Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Create prodcut medie from ProductCreate / ProductUpdate possible?

Solved

Create prodcut medie from ProductCreate / ProductUpdate possible?

mattayres
Shopify Partner
11 0 8

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...

Accepted Solution (1)

dogowner
Shopify Partner
59 5 8

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:

 

 

View solution in original post

Replies 4 (4)

dogowner
Shopify Partner
59 5 8

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:

 

 

dogowner
Shopify Partner
59 5 8

product_media_query = """mutation productCreate($input: ProductInput!, $media: [CreateMediaInput!]) { productCreate(input: $input, media: $media) { product { id } shop { id } userErrors { field message } } } """

dogowner
Shopify Partner
59 5 8

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):

 

https://shopify.dev/api/admin-graphql/2021-10/input-objects/ProductVariantInput#field-productvariant...

 

 

mattayres
Shopify Partner
11 0 8

Thank you very much for your help. 😎