inventorySetOnHandQuantities all or nothing?

garyrgilbert
Shopify Partner
390 40 162

Hey there,

 

inventorySetOnHandQuantities is a great method allowing us to update 250 inventory items in one go.. great and thanks for that. The only problem is that the mutation is unfortunately an "all or nothing" mutation if for some reason a single inventoryitemid is not found the entire mutation block seems to fail e.g. nothing gets updated.  This should be reported in the usererrors query indicating which line failed but the reset of the mutation shouldn't really fail in my opinion.

 

Could we get some kind of flag added so that we don't have the entire thing fail because a single item was not found?

 

Cheers,

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Replies 8 (8)

Liam
Shopify Staff
2731 298 769

Hi Gary,

Thanks for your feedback. I understand how having a more flexible approach to updating inventory could improve your workflow. At the moment, as you pointed out, the inventorySetOnHandQuantities mutation is designed to be atomic - meaning it either fully succeeds or fails. This is intended to ensure data consistency.

 

I'll pass this feedback to our product team for consideration in future updates. We always appreciate hearing about ways we can improve our APIs to better suit your requirements.

 

In the meantime, you could implement some error checking on your end before sending the mutation request. For example, you could verify the existence of inventory item IDs before including them in the mutation.

 

Hope this helps,

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

garyrgilbert
Shopify Partner
390 40 162

Hi Liam,

 

thanks for the reply and sorry for not getting back sooner.. things are a bit crazy right now as we ramp up for the holiday season.

 

I agree that in some circumstances making a batch of db updates as an atomic transaction to prevent data inconsistency makes sense.. when the purpose is to prevent data inconsitency. But in this particular case there is no threat of data inconsistency since the items that are to be updated no longer exist, hence no consistency issue would be created.

 

Your interim solution would work for a small customer with a couple hundred products/variants to update but this particular merchant has just over 25k items currently, which will probably double within the year, selling on 3 channels with a B2B shop running on another system, and POS's and the requirement to keep the Shopify inventory synched with a maximum of 30 minute cycle.  So we all know in this situation that the the rest api is out, there is no way that I could make 25k rest api calls within a half hour even with a plus account without spawning multiple threads, so that leaves me with the graphql query.. and the need to ensure that the inventory_item_ids I have in our db all exist.. that means creating a job to check the items and adding a product/delete webhook.. (Would love a variant/delete webhook fyi).  This over complicates things a bit.

 

I'll have to think about how to handle this.

 

cheers and thanks for the reply

 

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution

Liam
Shopify Staff
2731 298 769

Hi again Gary,

 

Could you share a request id for a mutation that failed, so we can see what validation is causing the bulk mutation to fail?

 

Cheers,

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

garyrgilbert
Shopify Partner
390 40 162

Hey Liam,

 

Sure, I havent had a chance to clean the db yet so I will get that to you on Monday.

 

Cheers

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
garyrgilbert
Shopify Partner
390 40 162

Hi Liam,

 

I got that request id for you: 34d93c4d-4916-4604-baa3-7b9178c91a85

 

Cheers,

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
SIG_KAP
Shopify Partner
7 0 2

any update on this? 
@Garyrgilbert did you find a solution. 

I got a client with over 150K products, I would love to know how your working with a large inventory. 

garyrgilbert
Shopify Partner
390 40 162

Heya,

 

I ended up having to listen for products/update products/delete webhooks to ensure that my local products database stays in synch with shopifys so if the merchant removes a product or a variant I don't try to update the inventory of something that no longer exists. Its not 100% but pretty close.

 

then I batch update the 25k products in batches of 250, takes about 10 minutes, average about 8 updates per minute because I also have to update variant metafields at the same time, without having to update the metafields I was able to update all 25k products in under 3 minutes. 

 

Thats multiple orders of magnitude faster than the rest api!

 

Cheers,

Gary

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
SIG_KAP
Shopify Partner
7 0 2

Thanks for the Reply Gary. 

I'm finding that too - InventorySetOnHandQuantities is fast enough to go through a big inventory. 

 

The way I'm doing comparisons is a bit different. 
I just do a bulkoperation of product data, covert the jasonl to a csv and then run a copy to a postgres database - That takes about 10 mins.  

To compare Inventory to a supplier I do sql join and then update product inventory numbers that are different from the supplier numbers using  InventorySetOnHandQuantities