Uploading and associating an outside image to a product variant

1 0 0

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 {

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 {

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?

Reply 1 (1)

Shopify Staff
1357 225 475

Hey @mrtamborineman,


You may be running into file format types for images (PNG, JPG, IMG) and I would suggest going through our developer documents on Managing Media for Products and more specifically on how to Manage media for product variants to help clarify the process. 


Hope that helps! 

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