[GraphQL] New Mutation for bulk inventory adjustment at a single location

Ryan
Shopify Staff
492 42 113

Hey Devs,

 

To allow apps to sync inventory changes faster, we have just released a new inventoryBulkAdjustQuantityAtLocation GraphQL mutation.

This mutation has a cost of 10, and allows to adjust the inventory of up to 100 inventory items at a specific location. With the GraphQL bucket refill of 50 this allows adjusting inventory of up to 500 inventory items per second.

mutation {
  inventoryBulkAdjustQuantityAtLocation(
    locationId: "gid://shopify/Location/1",
    inventoryItemAdjustments: [
      {inventoryItemId: "gid://shopify/InventoryItem/1", availableDelta: 1},
      {inventoryItemId: "gid://shopify/InventoryItem/2", availableDelta: 10}
      ]) {

    inventoryLevels {
      available
    }
  }
}

Here's an example using Insomnia on my store:

With a sync bandwidth of 1.8M adjustments per hour, this should remove the need for Fulfillment Services to be the inventory manager; i.e. using the hourly fetch_stock sync. We recommend this mutation as the prefered way for Fulfillment Services to sync inventory changes with Shopify.

If you need help with GraphQL, you can join us in the #graphql channel of the Shopify Partners Slack!  Also check out our Getting Started Guide and Blog post on using GraphQL with Locations.  Our newest guides (fulfillment, inventory) also include GraphQL examples.

 

Happy Coding!

Ryan | 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 the Shopify Help Center or the Shopify Blog

Replies 7 (7)
David_Petti
Tourist
10 0 5

But this still requires us to call the stock level within Shopify first.... slow. We need you to allow us to SET the stock and ignore any adjusting like in the REST interface.

 

Dave

Ryan
Shopify Staff
492 42 113

Hi Dave,

There are no plans to include a set endpoint for the new inventory APIs.  You can keep track of any inventorylevel changes using webhooks and perform an adjust to the intended level.  Inventory sets were too racy when multiple actors are adjusting inventory and often resulted in incorrect inventory counts.

Ryan

Ryan | 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 the Shopify Help Center or the Shopify Blog

Poul_Poulsen
Shopify Partner
22 2 15

How do i get in on the Partner Slack Channel?

 

If you need help with GraphQL, you can join us in the #graphql channel of the Shopify Partners Slack!  Also check out our Getting Started Guide and Blog post on using GraphQL with Locations.  Our newest guides (fulfillmentinventory) also include GraphQL examples.

Metafields is a myth...
james148
Shopify Partner
13 0 14

I'm going to chip in and say it would be great if we had a 'set'.

I certainly understand the race conditions, but I would imagine that a lot of your customers don't have stores where race conditions are a massive concern; assuming the inventory update are performed at slow times.

Ryan
Shopify Staff
492 42 113

https://help.shopify.com/en/partners/getting-started/walkthrough#step-3-join-the-community

 

Link to join slack is on this page.

Ryan | 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 the Shopify Help Center or the Shopify Blog

Poul_Poulsen
Shopify Partner
22 2 15

Thanks Ryan

Metafields is a myth...
Kevin_Harwood
New Member
1 0 30

I wanted to chime in and again stress how great the ability to set would be here. I certainly understand race conditions can come up, but we have an enterprise level ERP system that is the master of iventory data across all our systems, and we periodiaclly run full syncs to keep things up to date.

 

Without the set, we have to query the current shopify number, and then go and set it. "inventoryBulkAdjustQuantityAtLocation" is great and is only about 10% of the overall sync time, but we are spending 90% of the sync time just querying the current shopify number so we can calculate a delta (this is actually leads to _more_ race condtions).

It would be an INCREDIBLE help to have the ability to set the inventory number, and we could get our full ERP sync down to less than half a minute.