A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello,
I have a functionality in restapi to update my stock. Works well but very slow.
I want to transition to use GraphQL to update my inventory.
Using inventorybulkadjustquantityatlocation (https://shopify.dev/api/admin-graphql/2021-10/mutations/inventorybulkadjustquantityatlocation) I can set individually very well.
But I cannot get the formatting correct to send multiple updates in one query.
Here is my $postdata variable that I send via Curl:
{"query":"mutation inventoryBulkAdjustQuantityAtLocation($inventoryItemAdjustments: [InventoryAdjustItemInput!]!, $locationId: ID!)
{ inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $inventoryItemAdjustments, locationId: $locationId)
{userErrors { field message} }}",
"variables":{"inventoryItemAdjustments":[{"availableDelta":16,"inventoryItemId":"gid://shopify/InventoryItem/43028674117838"},{"availableDelta":3,"inventoryItemId":"gid://shopify/InventoryItem/43028674150606"},{"availableDelta":2,"inventoryItemId":"gid://shopify/InventoryItem/43028674183374"},{"availableDelta":10,"inventoryItemId":"gid://shopify/InventoryItem/43028676018382"}],"locationId":"gid://shopify/Location/62241177806"}}
I must be missing something simple here and maybe hand over the array of values incorrect in the json.
What is the correct way to send the variables?
Please advice.
Solved! Go to the solution
This is an accepted solution.
I haven't tried passing locationId in with the variables, so my first example has it hard coded; I use something like this.
Guy, please have a look into this. I have been researching on and off and people only post a graphql to update one single product inventory at a time.
It would be needed to do it like in the example properly with 40-100 at a time.
What is the correct formatting. I'd be glad to have a json example please.
This is an accepted solution.
I haven't tried passing locationId in with the variables, so my first example has it hard coded; I use something like this.
Thank you for taking the effort and giving a great answer.
It is very helpful that you showed versions with the location global or for each row. 🙂
I have troubles to check if this works with the graphql app.
See this screenshot: https://ibb.co/d2vy6V8
I used this header:
mutation inventoryBulkAdjustQuantityAtLocation($inventoryItemAdjustments: [InventoryAdjustItemInput!]!, $locationId: ID!) {
inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $inventoryItemAdjustments, locationId: $locationId) {
userErrors {
field
message
}
}
}
I used these variables:
{
"variables":{
"invItemAdjustments":[
{
"inventoryItemId":"gid://shopify/InventoryItem/43028674117838",
"availableDelta":16
},
{
"inventoryItemId":"gid://shopify/InventoryItem/43028674150606",
"availableDelta":3
},
{
"inventoryItemId":"gid://shopify/InventoryItem/43028674183374",
"availableDelta":2
},
{
"inventoryItemId":"gid://shopify/InventoryItem/43028676018382",
"availableDelta":10
}
],
"locationId":"gid://shopify/Location/62241177806"
}
}
In the graphiql app, you have to go remove the outer layer; putting data in the variable pane wraps the text { variable }. So when testing there, you'd want something like this:
{
"invItemAdjustments":[
{
"inventoryItemId":"gid://shopify/InventoryItem/43028674117838",
"availableDelta":16
},
{
"inventoryItemId":"gid://shopify/InventoryItem/43028674150606",
"availableDelta":3
},
{
"inventoryItemId":"gid://shopify/InventoryItem/43028674183374",
"availableDelta":2
},
{
"inventoryItemId":"gid://shopify/InventoryItem/43028676018382",
"availableDelta":10
}
],
"locationId":"gid://shopify/Location/62241177806"
}
This works well now. I came down from 10min to 1.5min for 10.000 lines. Thanks.
Would be good to hand over more than 200 at a time. But it is what it is.