Associate images with products: productCreateMedia vs. productUpdateMedia vs. productCreateMedia

Topic summary

Issue: A developer using Shopify API version 2024-01 struggled to associate existing media/images with products. They were confused about which mutation to use since productAppendImages is deprecated, and the available options—productCreateMedia and productUpdateMedia—seemed designed for creating or updating media rather than simply linking existing media to products.

Key Challenge:

  • Media already existed in the system and didn’t need creation or modification
  • Initial attempts showed “Media associated successfully” messages, but images weren’t appearing in product listings
  • Uncertainty about the correct GraphQL mutation for this use case

Resolution:

  • The solution involved using the full media URL instead of just the media GID when calling productCreateMedia
  • Developer created a helper function get_media_url() to fetch the complete URL from the media ID
  • Modified associate_media_with_product() to pass the full URL as originalSource in the mutation
  • After this change, product images displayed correctly in product listings

Code approach: Query the media node to retrieve the full image URL, then use productCreateMedia mutation with originalSource parameter containing that URL.

Summarized with AI on November 8. AI used: claude-sonnet-4-5-20250929.

Hi Hinton - glad you figured it out and posted your solution.

If the image is displaying on the product page, it should be associated with the product. Why are you thinking the image is not yet fully associated with the product?