Assign multiple images to single variant

The docs at productVariantAppendMedia - GraphQL Admin suggest that a single product variant can accept multiple mediaIds (the input is an array), but this fails with error ““Only one mediaId is allowed per media input.”. Is there any intention to be able to attach multiple variant images to a given variant?

1 Like

Hi @Paul_Holmes,

This is correct that you can currently only attach a single product image to a variant at this time. The variantMedia input argument on the productVariantAppendMedia mutation is an array in order to accept multiple image/variant pairs in a single mutation.

For example, say I have a product id: 123, and I have two variants on that product, with variant ids; 456, and 789. I can attach media to both of these variants with a single call like so:

{
  "productId": "gid://shopify/Product/123",
  "variantMedia": [
    {
      "mediaIds": [
        "gid://shopify/MediaImage/111"
      ],
      "variantId": "gid://shopify/ProductVariant/456"
    },
    {
      "mediaIds": [
        "gid://shopify/MediaImage/222"
      ],
      "variantId": "gid://shopify/ProductVariant/789"
    }
  ]
}

I will definitely be submitting some feedback internally on your behalf that you’d like to see the ability to attach multiple media files to individual variants, and I would recommend that you submit some feedback on this as well. You can do so by scrolling to the bottom of the page in the Shopify.dev documentation and selecting Was this section helpful?: No, and enter your custom feedback.