All things Shopify and commerce
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hello!
I am using GraphQL productVariantAppendMedia path to associate product image to one of its variants. Below is the mutation:
mutation {
productVariantAppendMedia(productId: "gid://shopify/Product/7723406459105", variantMedia: {mediaIds: ["gid://shopify/ProductImage/36771612623073"], variantId: "gid://shopify/ProductVariant/42940636594401"}) {
product {
id
}
productVariants {
id
}
userErrors {
field
message
}
}
}
When I execute the above mutation on GraphiQL then I receive below (vague) response:
{
"data": {
"productVariantAppendMedia": null
},
"errors": [
{
"message": "invalid id",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"productVariantAppendMedia"
]
}
],
"extensions": {
"cost": {
"requestedQueryCost": 10,
"actualQueryCost": 1,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 999,
"restoreRate": 50
}
}
}
Which id of which field is invalid? I don't get it.
Can I even use this path for this purpose?
I will really appreciate quick responses.
Solved! Go to the solution
This is an accepted solution.
I have actually resolved the issue on my own. I was actually providing the wrong id as MediaId. What I actually did - get the Media Object of the product and from that object extract the MediaId and then pass it into the mutation- It worked perfectly fine.
This is an accepted solution.
I have actually resolved the issue on my own. I was actually providing the wrong id as MediaId. What I actually did - get the Media Object of the product and from that object extract the MediaId and then pass it into the mutation- It worked perfectly fine.
It wasn't clear to me how to get the correct MediaId's. This worked:
{
product(id: "gid://shopify/Product/123"){
media (first: 250){
edges{
node{
alt
__typename
... on MediaImage{
id # <- this one
image{
altText
url
__typename
}
}
}
}
}
}
}