I’m looking for the simplest way to take an image hosted off of shopify (for example on S3), and set it to the image for a partiular product variant. I’ve fiddled with productVariantUpdate, productCreateMedia and productVariantAppendMedia but have not had great success. For instance, here is my best attempt so far:
mutation {
productCreateMedia(media: {
mediaContentType: IMAGE,
originalSource: "${src}"
},
productId: "${productId}"
) {
media {
id
}
}
}
Which gives me this response
"data": {
"productCreateMedia": {
"media": [
{
"id": "gid://shopify/MediaImage/123456789"
}
]
}
}
Then I try to use the MediaImage id in the following mutation with the intent of setting the variant image
mutation {
productVariantUpdate(input: {
id: "${variantId}",
mediaSrc: "${imageId}"
}) {
productVariant {
image {
src
}
}
}
}
Unfortunately this produces “image”:null in the response and the variant’s image is unchanged.
Like I said, I’ve tried several other approaches. Just looking for a simple way to upload an image to a product variant.
Am I doing something terribly wrong? Is there a much easier way to do this?