This seems to work well when the variant doesn’t already have media attached. However, when trying to replace existing media against a variant it doesn’t seem to associate the new media with it; it’s simply created against the product. Is this intentional?
Topic summary
Main issue: How to update product variant images via GraphQL (GQL), including bulk operations, given ProductVariantUpdate’s input lacks an image field.
Key update (2024-04 API/new product model):
- Use productVariantsBulkUpdate. It can upload an image from a URL and associate it to a variant in a single request (via mediaSrc and media fields, with allowPartialUpdates). Shopify provided a working example and migration resources for the new product model.
Outcomes:
- Reporter confirmed this approach works for adding/associating images to variants at scale.
- Earlier complex workaround (manually fetching media IDs and updating) is no longer necessary for this use case.
Caveat/edge case:
- When a variant already has media, productVariantsBulkUpdate appears to add the new image to the product but does not replace/associate it with the variant. Two users report this; it’s unclear if it’s intended or a bug.
- Suggested workaround: explicitly delete/unlink existing variant media, then run the bulk update to attach the new media.
Status:
- Partially resolved. Bulk add/attach works; replacement behavior is unresolved pending clarification from Shopify.
- Bulk mutation reduces the need for throttling compared to per-item updates, but no specific rate-limit guidance was provided.
1 Like