Focusing on managing products, variants, and collections through the API.
I want to add an image for each variable.
I added an image URL to imageSrc, but I can't actually add an image. What should I do?
mutation productVariantsBulkCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkCreate(productId: $productId, variants: $variants) { product { id } productVariants { id image{ url } metafields(first: 250) { edges { node { namespace key value } } } } userErrors { field message } } } { "productId": "gid://shopify/Product/8730477592876", "variants": [ { "options": [ "Fashionable6" ], "sku": "SKU001", "price": 114.99, "inventoryPolicy": "DENY", "inventoryQuantities": { "availableQuantity": 25, "locationId": "gid://shopify/Location/91036582188" }, "imageSrc" : "https://sellpick-bucket.s3.ap-northeast-2.amazonaws.com/weap0n77/SSGCOM/GDS002054/894833a74460ed37e5e32b5826a92397/7a664f1435b2137b86fb833e6142a881.jpg" }, { "options": [ "Rugged6" ], "sku": "SKU002", "price": 114.99, "inventoryPolicy": "DENY", "inventoryQuantities": { "availableQuantity": 25, "locationId": "gid://shopify/Location/91036582188" }, "imageSrc" : "https://sellpick-bucket.s3.ap-northeast-2.amazonaws.com/weap0n77/SSGCOM/GDS002054/894833a74460ed37e5e32b5826a92397/7a664f1435b2137b86fb833e6142a881.jpg" } ] }
Hi Weap0n7,
I've digged into this and it looks like from our GraphQL API documentation, the imageSrc
field is deprecated as of the 2023-07 release. This field can no longer be used to associate an image with a product variant through mutations. Instead, you should use the mediaSrc
field. Can you try again using mediaSrc?
Hope this helps!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
mutation productVariantsBulkUpdate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {
productVariantsBulkUpdate(productId: $productId, variants: $variants) {
product {
id
}
productVariants {
id
}
userErrors {
field
message
}
}
}
{
"productId": "gid://shopify/Product/8730477592876",
"variants": [
{
"id": "gid://shopify/ProductVariant/46999766991148",
"options": [
"Rugged7"
],
"sku": "SKU002",
"price": 50.99,
"inventoryPolicy": "DENY",
"mediaSrc":"https://sellpick-bucket.s3.ap-northeast-2.amazonaws.com/stg/upload/file/BACD0500/weap0n77/191655/20221208165355/GDS030451/16619050790AC4D009861B10CA46ECC2_img_760.JPEG"
}
]
}
Hi @Liam ,
I can confirm with @weap0n7 . We are seeing the same thing. It doesn't matter if we use mediaSrc: "https://xxxx" or mediaSrc: ["https://xxxx"]. It also doesn't work with `productVariantsBulkCreate`
With productVariantsBulkCreate, you need
1. Add all images in media input first
2. In each variant payload input, add the image in the above list.
It will work.
For productVariantsBulkUpdate:
Hope you can find the new way out.
For me, I got all the media from product for getting the media Id, and then add the corresponding mediaId for each variant image.
The variant image will be updated smoothly.