A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi guys I am trying to work out if it is possible to use the mutations ProductCreate and /or ProductUpdate to create product media if I parse it the URL of the media?
Is it possible to do it all in one go? Or do I have to do a ProductUpdate and THEN a ProductUpdateMedia
Obviously it would be beneficial to do it all in one go with the ProductCreate or ProductUpdate mutations...
Solved! Go to the solution
This is an accepted solution.
The productCreate mutation takes a CreateMediaInput that can be used to add media at the same time as creating the product. Is that what you are looking for? The syntax is confusing to me because I still don't really understand graphql but it looks like this:
This is an accepted solution.
The productCreate mutation takes a CreateMediaInput that can be used to add media at the same time as creating the product. Is that what you are looking for? The syntax is confusing to me because I still don't really understand graphql but it looks like this:
product_media_query = """mutation productCreate($input: ProductInput!, $media: [CreateMediaInput!]) { productCreate(input: $input, media: $media) { product { id } shop { id } userErrors { field message } } } """
Syntax highlighting seems to only work sometimes here. The media variable is a list of images, specified here:
https://shopify.dev/api/admin-graphql/2021-10/input-objects/CreateMediaInput
You also should link the product variant to the media url via imageSrc(or maybe mediaSrc):
Thank you very much for your help. 😎