GraphQL mutation inventoryBulkAdjustQuantityAtLocation

Highlighted
Shopify Partner
29 4 10

Scenario:

with my Nodejs app I connect to a courier FTP server to download a stock balance file two times a day. This file contains up to 30 thousands lines of text, each line is a product variant with unique SKU and available quantity. While downloading I use stream to convert data to a JavaScript object which result a list of arrays into array [["SKU",0]].

For your better understand this explanation, I will call this data: "source".

 

As you see we do not have inventoryItemId yet. So the idea is to:

 

1. queryGetInventoryItems(); 

create a query to get all inventoryItems id, sku and tracked status with something like this https://pastebin.com/KQzHcuiy and maybe repeat this until "hasNextPage": false, so to get all inventoryItems from the shopify store into our memory and then return all id, sku and tracked status into a shopifyInventoryItems.JSON file. Is this the right way to get all inventory items?

 

 

2. mutationInventoryItemUpdateToTracked();

sometime inventoryItem does result "tracked": false, to solve should parse shopifyInventoryItems.JSON so for each "tracked": false, we perform see here https://pastebin.com/BR6CFqAm

 

 

3. matchSkuToGetInventoryItemId();

Because only 60% of the source SKU correspond to an actual inventoryItemId, in the try catch we still have shopifyInventoryItems.JSON in memory so we compare source.JSON to match sku and write this two cases into source.json:

  • "no_match", push array like this ["sku",10,"title","","no_match"]
  • "tracked", push array like this ["sku",10,"title","inventoryItemId","tracked"]

 

 

4. mutationInventoryBulkAdjustQuantityAtLocation();

finally we have source quantity and shopify InventoryItemId into source.json so pass the list of the "tracked": true on file to this,

 

mutation {
  inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: {inventoryItemId: "", availableDelta: 0}, locationId: "")
}

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1555 81 282

Point 1: As far as GraphQL goes, this is the correct way to paginate until you run out of inventory items provided to goal is to get all inventory items.

 

Sorry, is there more of a question you're looking for an answer to? Everything you're mentioning seems ok but feel free to clarify any additional intent behind your post.

 

Cheers.

0 Likes
Highlighted
Excursionist
40 1 6

This is great and helped me.  Of course, the bit issue is that there is no bulk update api, just an adjust which just make the whole thing more complicated

0 Likes