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 ?
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).
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.
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....
Nicolas, why wouldn't you use the existing ability to import products and images from CSV?
Just asking.
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.
User | Count |
---|---|
13 | |
12 | |
7 | |
4 | |
4 |