GraphQL BulkOperation to Update Inventory Quantities

luke-csg
Tourist
4 0 4

Hi,

 

Shopify is not our primary inventory and stock management system. I am trying to setup a GraphQL BulkOperationMutation to update stock available on our Shopify Shops for various locations.

 

Previously we were using the REST API and pagination to do this synchronously but with so many products and multiple locations this is failing a lot due to throttling and timeout issues.

 

I thought I had it sorted with a BulkOperation ProductVariantsBulkInput but inventoryQuantities only seem to be supported on Create and not Updates.

 

I have found I can update Inventory Stock levels via the GraphQL inventorySetOnHandQuantities but this doesn't appear to be supported for bulk operations.

 

Can anyone tell me if it is possible to bulk update stock inventory quantities?

 

Thanks,

 

Luke

Replies 6 (6)
ShopifyDevSup
Shopify Staff
Shopify Staff
1202 190 419

Hey @luke-csg - thanks for getting in touch. You are correct that the inventorySetOnHandQuantities mutation isn't supported with Bulk Operations (list of all supported mutations here). 

I was also able to do some testing on our end here and can confirm that inventory quantities can't be updated using the Product Variants as you mentioned, however you should be able to update the quantities for multiple inventory items using the inventoryItemAdjustQuantities mutation. 
 

For example:

mutation AdjustMultipleInventoryQuantities($input: InventoryAdjustQuantitiesInput!) {
 inventoryAdjustQuantities(input: $input) {
   userErrors {
     field
     message
   }
   inventoryAdjustmentGroup {
     createdAt
     reason
     referenceDocumentUri
     changes {
       name
       delta
     }
   }
 }
}
 

and the variable inputs:

{
 "input": {
   "reason": "correction",
   "name": "available",
   "referenceDocumentUri": "logistics://my.warehouse/take/2023-01/13",
   "changes": [
     {
       "delta": -4,
       "inventoryItemId": "gid://shopify/InventoryItem/12345678",
       "locationId": "gid://shopify/Location/12345678"
     },
     {
       "delta": 5,
       "inventoryItemId": "gid://shopify/InventoryItem/12345678",
       "locationId": "gid://shopify/Location/12345678"
     }
   ]
 }
}

Hope this helps - let us know if we can clarify anything further on our end here. 

 

Al | Shopify Developer Support 
 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

luke-csg
Tourist
4 0 4

Thanks for the feedback.

 

This issue with using a delta for me is that we aren't keeping track on the Shopify stock quantities. Stock management is controlled through our own platform. I would need to query the Shopify API to establish what the current stock available level is for each product variant and compare to our stock system to calculate the delta to apply. 

 

Whilst that is possible it complicates and slows down the process when the ability to simply set the quantity would do the job.

 

Plus with asynchronous Bulk Operations having a longer run time its possible an order could be placed and change the available quantity between querying the available quantity and the delta mutation to amend the quantity.

 

Actually I can't see inventoryAdjustQuantities listed as supported for Bulk Operations? Can you confirm it is supported?

ShopifyDevSup
Shopify Staff
Shopify Staff
1202 190 419

Hey @luke-csg,

 

I can confirm that inventoryAdjustQuantities is not a supported Bulk Operation and the suggested work around is just a method to make multiple inventory adjustments using the mutation.

 

Hope that helps! 

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

luke-csg
Tourist
4 0 4

Ok. Certainly the GraphQL inventoryAdjustQuantities mutation is an improvement on the REST Admin API as this allows up to 250 inputs per query.

 

I hit an issue where some InventoryItems not being activated for some locations. I am activating these using the inventoryBulkToggleActivation mutation. However, whilst I can activate multiple locations per InventoryItem, I only seem be able to activate one InventoryItem per query. Are there any mutations that support activating multiple InventoryItems with locations per query?

 

It's slow going 1 at a time for 1000's of inventory items.

ShopifyDevSup
Shopify Staff
Shopify Staff
1202 190 419

Hey @luke-csg - at the moment there isn't a mutation that would support activating multiple InventoryItems, the current workaround you mentioned is the best way to do this right now our recommendation would be to call inventoryBulkToggleActivation in a loop for each inventory item. I definitely understand it's not the most ideal workaround though. I'm going to put through a report on my end here so that we can forward on this thread to our developers for future consideration in terms of implementing a feature like the one we're discussing here. 

I can't guarantee anything going forward (including a response) - but I can confirm we'll get product team eyes on this. As always - hope this helps!

 

Al | Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

luke-csg
Tourist
4 0 4

Thanks for the feedback.

 

I now have everything working and it's much more robust that the previous REST API based solution we were using.

 

I do think it would be useful to have Bulk Operation for Inventory Quantity updates.