API : Create product with Variant and add image to variant

Wedooit
Shopify Partner
4 0 0

Hello,

I'm trying to add products with the API (json)

Is it possible to add directly a new image for a variant and not a reference to an existing image ?

I mean to add a variant i use this:

"variants":[
    {
        "option1" : "Red",
        "price" : "11.00",
        "sku": "AB01"
    },
    {
        "option1" : "Blue",
        "price" : "12.00",
        "sku":"AB02"
    }

But I would to have something like :

"variants":[
    {
        "option1" : "Red",
        "price" : "11.00",
        "sku": "A01",    
     "images": [
          {
            "src": "http://www.mysite.com/myimg1.jpg"
          }     
          ]

    },
    {
        "option1" : "Blue",
        "price" : "12.00",
        "sku":"AL01",
     "images": [
          {
            "src": "http://www.mysite.com/myimg2.jpg"
          }     
          ]

    }

Possible ?

 

Replies 11 (11)
Zameer
Shopify Staff
Shopify Staff
297 31 88

Hey there,

Zameer here from the Shopify Developer Experience team.

Unfortuantely, that's not currently possible. As our API docs suggest, you must first create a product image for the product, and then associate it to the appropriate variant(s).

Wedooit
Shopify Partner
4 0 0

Ok thanks Zameer.

Do you have plan in a futur update to include this feature ?

Nicolas

 

Zameer
Shopify Staff
Shopify Staff
297 31 88

Hey Nicolas,

As the functionality is still available through a combination of API calls, I don't see this being something that gets adjusted in the future.

Breaking down various aspects of a product into it's components such as the image, variants, etc. allows for clearner implementations and more overall versatility. 

I would recommend instead making adjustments to your application to account for this model.

Wedooit
Shopify Partner
4 0 0

I've a request to develop a tool that can import hundred of products into a shopify shop.

The idea is to upload a CSV in an admin site that should be converted into a JSON and then imported (API CALL) into a Shopify shop.

All products and variants are in the same JSON, that's why if it was possible to add directly an image for a variant that would have been perfect for me...1 call per product with variants...and not 1 call for products (and get the image ID) then X calls for the variants and provide the Image ID for each variant....

KarlOffenberger
Shopify Partner
1873 184 863

Nicolas, why wouldn't you use the existing ability to import products and images from CSV?

Just asking.

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
Wedooit
Shopify Partner
4 0 0

That's a good question, the requester will only work with XLS and FTP....

I need to make a service waiting for the XLS on the server and then call the API to insert all products into his shopify....

 

mashkovtsev
Shopify Partner
31 1 16

Hi Zameer.

I have to disagree with this solution. There are several reasons:

1.  Imagine the situation we have to upload a new product and its' variants, every variant will have a separate image. It's not the best solution, but the easiest to do is to create a product creation requests, fill all variants without images and add all these images to the product. As a result, Shopify will return a set of image ids, we will use these ids to send a new request and add them to our variants. But we're living in not-ideal world, so Shopify API may change images order in response, or decline some images and we will not know about it. So we can't use this solution.

2. The second option is to create a new product with variants without images and add all images one image per request (to handle errors). After that we have to do a separate request to link all images to our variants. Just imagine a situations if we have a lot of products to import...
Example: At this moment we need to import 47000 variants (5400 products in total, so we have an average of 9 variants per product).
To import these products we need `(1 + 9 + 1) * 5400 = 59400 requests`. Shopify allows us to do 2 requests per second, one request takes an average of one second for me.
We will ignore this 0.1s of delay to be sure that all requests will be in limit and will send requests with 0.5s delay. 
So to perform all these requests, we will need `59400 * 1.5 / 60 / 60 = 24.75` hours of continuous script execution. It's not a good performance and it may be improved (we can execute this script just in 2 hours) just by adding this "image_src" field to every variant.

Hope this makes sense. Thank you.

All the best.
Alex, Team Lead at Infinite Solutions Shopify Agency
https://inso.codes/
HMM100
Tourist
6 0 0

So every time you add a product and its variant, do you need to call the API to associate the variant with the image ID?

But each request can only associate one picture and one variant. Is there any other way to associate all variants and images at one time

mashkovtsev
Shopify Partner
31 1 16

I'm really impressed how Shopify dev team ignores requests like these (it's not the first one for me).

All the best.
Alex, Team Lead at Infinite Solutions Shopify Agency
https://inso.codes/
Dominik_Giroux
Shopify Partner
15 0 5

Kinda funny because I literally just reach that point on my product sync service I'm working on right now and we have 4900 products with many variants, so yep, 24 hours sync... Hooray.

garyrgilbert
Shopify Partner
82 8 22

They will either ignore or suggest you work with the Graphql bulk import.. but as soon as you try you will realize that it probably won't work how you think it should anyway... Yep we are all playing in their sandbox and they make the rules...

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution