A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello everyone,
I need your help guys. Basically, I am trying to create a product using the GraphQL with lots of variants but the GraphQL is restricted to adding inventory quantity which creates the product if I need to add the inventory to that product then inventoryAdjustQuantities mutation will be used, correct me if I am wrong. But on the inventoryAdjustQuantities mutation inventoryItemId is the required field.
How can I get the inventoryItemId while creating the product I am pasting the mutation and input that I am using.
Mutation
mutation createProductAsynchronous($productSet: ProductSetInput!, $synchronous: Boolean!) { productSet(synchronous: $synchronous, input: $productSet) { product { id handle productType variantsCount { count } variants(first: 100) { nodes { id } } } productSetOperation { id status userErrors { code field message } } userErrors { code field message } } }
Input:
{ "synchronous": true, "productSet": { "title": "Bezel Emerald Catalyst Bracelet", "descriptionHtml": "Voila! We caught your eyes staring! With a little bit of sparkle, and a whole lot of fun, the Bezel Emerald Catalyst Bracelet features a statement emerald cut diamond in the center along with an array of round cuts to seize every glance.", "handle": "bezel-emerald-catalyst-bracelet", "productType": "Apparel", "tags": ["Emerald", "Catalyst", "Bracelet"], "vendor": "Kynd Mark", "status": "ACTIVE", "productOptions": [ { "name": "Metal", "position": 1, "values": [ { "name": "14K White Gold" }, { "name": "14K Yellow Gold" }, { "name": "14K Rose Gold" } ] }, { "name": "Carat Weight", "position": 2, "values": [ { "name": "2.2" }, { "name": "4.2" } ] }, { "name": "Bracelet Size", "position": 3, "values": [ { "name": "5.5" }, { "name": "6" }, { "name": "6.5" }, { "name": "7" }, { "name": "7.5" }, { "name": "8" } ] } ], "variants": [ { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "5.5" } ], "sku": "LB70589", "price": 1000, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "6" } ], "sku": "LB70589", "price": 1100, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "6.5" } ], "sku": "LB70589", "price": 1200, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "7" } ], "sku": "LB70589", "price": 1300, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "7.5" } ], "sku": "LB70589", "price": 1400, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "8" } ], "sku": "LB70589", "price": 1500, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "5.5" } ], "sku": "LB70589", "price": 1500 }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "6" } ], "sku": "LB70589", "price": 1600, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "6.5" } ], "sku": "LB70589", "price": 1700, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "7" } ], "sku": "LB70589", "price": 1800, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "7.5" } ], "sku": "LB70589", "price": 1900, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K White Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "8" } ], "sku": "LB70589", "price": 2000, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "5.5" } ], "sku": "LB70589", "price": 1000 }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "6" } ], "sku": "LB70589", "price": 1100, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "6.5" } ], "sku": "LB70589", "price": 1200, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "7" } ], "sku": "LB70589", "price": 1300, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "7.5" } ], "sku": "LB70589", "price": 1400, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "8" } ], "sku": "LB70589", "price": 1500, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "5.5" } ], "sku": "LB70589", "price": 1500 }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "6" } ], "sku": "LB70589", "price": 1600, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "6.5" } ], "sku": "LB70589", "price": 1700, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "7" } ], "sku": "LB70589", "price": 1800, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "7.5" } ], "sku": "LB70589", "price": 1900, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Yellow Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "8" } ], "sku": "LB70589", "price": 2000, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "5.5" } ], "sku": "LB70589", "price": 1000 }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "6" } ], "sku": "LB70589", "price": 1100, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "6.5" } ], "sku": "LB70589", "price": 1200, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "7" } ], "sku": "LB70589", "price": 1300, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "7.5" } ], "sku": "LB70589", "price": 1400, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "2.2" }, { "optionName": "Bracelet Size", "name": "8" } ], "sku": "LB70589", "price": 1500, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "5.5" } ], "sku": "LB70589", "price": 1500 }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "6" } ], "sku": "LB70589", "price": 1600, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "6.5" } ], "sku": "LB70589", "price": 1700, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "7" } ], "sku": "LB70589", "price": 1800, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "7.5" } ], "sku": "LB70589", "price": 1900, "requiresComponents": false, "inventoryPolicy": "DENY" }, { "optionValues": [ { "optionName": "Metal", "name": "14K Rose Gold" }, { "optionName": "Carat Weight", "name": "4.2" }, { "optionName": "Bracelet Size", "name": "8" } ], "sku": "LB70589", "price": 2000, "requiresComponents": false, "inventoryPolicy": "DENY" } ] } }
Would it be easier to do this as two separate GraphQL mutations, eg use productCreate first and then use inventoryAdjustQuantities?
Liam | Developer Advocate @ 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
Thanks for confirming that's the only way to add inventory.
One more question: When using GraphQL to add products, is it possible to include images and videos via external URLs, just like with CSV uploads?
I noticed that while CSV uploads successfully downloaded both images and videos to my store files, videos weren't downloading when using external URLs. Does GraphQL behave the same way?
hi, there
in your response , you should include the variants fields in the response , and each variant will contain an inventory item object with ID.
you could refer to this below.
product {
id
variants(first: 1) {
nodes {
id
inventoryItem {
id
}
}
}
}