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: productSet and media?

Solved

productSet and media?

ronald_g
Explorer
80 2 16

Previously, we can use productCreate with `media` as a parameter. How do we attach media when using productSet? `productSet` has a parameter for `mediaId`, but how do we get the `mediaId`? productCreateMedia requires `productId` to create media, which creates a cyclical loop. 

Accepted Solution (1)

AsafGitai
Shopify Staff
109 16 45

This is an accepted solution.

HI folks,

Wanted to let you know we have added ability to create files when calling productSet
https://shopify.dev/docs/api/admin-graphql/2024-10/input-objects/ProductSetInput#field-files

View solution in original post

Replies 9 (9)

Ashish_Shah
Shopify Staff
22 7 11

Hey @ronald_g 

Below is a recommended approach.  Let me know if this presents any challenges. 

  1. Use fileCreate mutation to create files/media and get mediaIDs
  2. Use productSet to create the product and variants and associate them with the mediaIDs created in 1)

ALIAS | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ronald_g
Explorer
80 2 16

Thank you @Ashish_Shah. I have a few follow up questions:

 

1. The File.id returned by `fileCreate` is the same as the mediaId?

2. Is fileCreate synchronous? Do we get the id immediately or need to wait like `productSet` to get the product.id?

3. Even if using `productSet`, it seems to that we still need to use `productVariantsBulkCreate` to set inventory, is that correct?

4. Since `productVariantsBulkCreate` already has `media` as an input argument, would that replace the need for `fileCreate`?

 

Thanks

 

ronald_g
Explorer
80 2 16

Just to add @Ashish_Shah ,

We started testing with fileCreate, however, is there documentation on how duplicateResolutionMode = REPLACE is supposed to work? In our tests new files keep getting created.

Richard_Monette
Shopify Staff
19 2 7

We started testing with fileCreate, however, is there documentation on how duplicateResolutionMode = REPLACE is supposed to work? In our tests new files keep getting created.

 

Are you using the same filename? The duplicateResolutionMode mode is taken into consideration if you are trying to specify the same filename. Without REPLACE a UUID is appended to the filename to deduplicate, with REPLACE it is treated effectively as an update.

To learn more visit the Shopify Help Center or the Community Blog.

Richard_Monette
Shopify Staff
19 2 7

1. The File.id returned by `fileCreate` is the same as the mediaId?

 

Yes

 

2. Is fileCreate synchronous? Do we get the id immediately or need to wait like `productSet` to get the product.id?

 

The file processing is asynchronous, you can use the status of the file to know when it is ready

To learn more visit the Shopify Help Center or the Community Blog.

syedusama0786
Shopify Partner
47 2 13

Hey @ronald_g Hope you are doing great!
I just want to ask you how do you manage this scenario ? Actually i wanted to add shopify products using productSet bulk mutation with product media, variants and options. How do you manage this ?
can you please help me about it?
Thanks for your favour in advance

AsafGitai
Shopify Staff
109 16 45

This is an accepted solution.

HI folks,

Wanted to let you know we have added ability to create files when calling productSet
https://shopify.dev/docs/api/admin-graphql/2024-10/input-objects/ProductSetInput#field-files

syedusama0786
Shopify Partner
47 2 13

@AsafGitai Thanks for this update. I'm glad to see that. one more concern i have about the productSet API is how we can update quantity of the product using productSet during creation of the product in bulk mutation.?
Because if we use productSet for creation of the product it would not update the quantity.
We need one API for the product creation which include everything Like product variants, options, Images, quantity and inventory, cost, tags, collections, sales channel, category, product type, vendor and meta tags. It will be useful in sync up 2 or more store with master store. we transfer product from one store to another only by using just one query.
can you guide me about it ?
Thanks

tedtate
Shopify Staff
19 2 4

👋 Hi @syedusama0786 ,

 

You should now be able to update inventory quantities with ProductSet if you update to using the 2024-10 release candidate:

https://shopify.dev/docs/api/admin-graphql/2024-10/input-objects/ProductSetInventoryInput