A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I am using the `productVariantAppendMedia` mutation in the Shopify graphQL api to try and associate multiple product images to a product variant.
I am using the correct format for my call, as found in the docs:
"productId": "",
"variantMedia": {
"mediaIds": [
""
],
"variantId": ""
}
Where mediaIds, I have an array of a couple media IDs.
When I run my request I am getting the following back in the userErrors:
message: ‘'Variant was specified in more than one media input.'’
This message is kind of vague - is this saying that a variant can only have one media attached to it? That seems a little preposterous to me, and is also counterintuitive since mediaIds is plural and is an array.
Any help here is appreciated!
Hey @laurenatlovd,
Are you able to share an x-request-id and date header from an example request where the error was returned? Other helpful info would be a link to the documentation for the version you are using, as well as a fully formatted graphql request body and variables?
I would be happy to take a closer look and pass back any insights!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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
Absolutely --
Here is the documentation that I am using: https://shopify.dev/api/admin-graphql/2022-10/mutations/productVariantAppendMedia
The mutation that I'm running and variables:
mutation productVariantAppendMedia($productId: ID!, $variantMedia: [ProductVariantAppendMediaInput!]!) {
productVariantAppendMedia(productId: $productId, variantMedia: $variantMedia) {
product {
id
}
productVariants {
media(first: 100) {
nodes {
... on MediaImage {
id
image {
id
url
}
}
... on Video {
id
}
}
}
}
userErrors {
field
message
}
}
}
variables: {
productId: "gid://shopify/Product/7550035394730",
variantMedia: [{mediaIds: [ 'gid://shopify/MediaImage/27295576752298' ],variantId: 'gid://shopify/ProductVariant/43545776062634'}, {mediaIds: [ 'gid://shopify/MediaImage/27295576785066' ],variantId: 'gid://shopify/ProductVariant/43545776062634'},{mediaIds: [ 'gid://shopify/MediaImage/27295576817834' ], variantId: 'gid://shopify/ProductVariant/43545776062634'}]
}
From a request:
'x-request-id': [ 'edd6d6f4-6121-459d-a2a0-77dae6774417' ],
date: [ 'Sun, 11 Dec 2022 15:21:13 GMT' ],
I hope that helps, let me know if you need anything else from me
Hey @laurenatlovd, thanks for all of the details and your patience here!
We were able to find logs with the request id and noticed that there were multiple cases of the same variant_id passed across multiple pairs - the error being PRODUCT_VARIANT_SPECIFIED_MULTIPLE_TIMES: Variant specified in more than one pair as seen in our MediaUserErrorCode doc here. Our documentation here confirms that there can only be one image per product variant, and we replicated in a development environment by passing multiple iterations of the same variant_id in different media pairs.
Based on testing and findings this error would be expected, and hope this offers some clarity - Cheers!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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
Will you provide the ability to add more than 1 image per product variant in the future, is that the reason why you can specify an array as input?
Hey @tnbnovicell ! That's an interesting observation regarding the array. I'm not aware of any increases to the number of images available to be added to a product. Definitely keep an eye on our developers changelog for if that does change in the future!
You may find this recent post interesting, related to changes to product media https://shopify.dev/changelog/deprecation-of-image-related-fields-in-product-and-product-variants-mu...
Hope this helps!
-Kyle G.
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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