Hello!
SKU will be your bane. While SKU is said to be a unique string code, and it typically is in inventory management systems, it isn’t within Shopify. And fair enough so, if inventory systems A had an item to sync with Shopify with SKU-123 and inventory system B had another item (not same items) to sync with Shopify by SKU-123, then which item in Shopify’s inventory is SKU-123?
So because of that, any kind of inventory item querying by SKU is not possible (BUT it is as I’ll explain). REST Admin will allow you to get up to 100 inventory items by ID. GraphQL API will let you query the inventoryItems object by sku but query will limit you to fetching 1 SKU at a time. Or? Well remember that in Shopify SKU does not have to be unique so it is up to you to ensure they are unique. If you can and have, then you can simply do multiple queries in one request.
query {
item_1: inventoryItems(first: 1, query: "sku:SKU-123") {
edges {
node {
id
inventoryLevels(first: 10) {
edges {
node {
available
location {
id
}
}
}
}
}
}
}
item_2: inventoryItems(first: 1, query: "sku:SKU-124") {
edges {
node {
id
inventoryLevels(first: 10) {
edges {
node {
available
location {
id
}
}
}
}
}
}
}
}
And so on and so forth until your bucket is full - you’d need to experiment how many you can “batch up” like that.
The benefit of above queries is you now not only retrieved your inventory item ID, but you also have the location ID and inventory stock level for that location which comes in handy if you want to do inventoryBulkAdjustQuantityAtLocation as that gem only likes deltas rather than absolute levels. TIP If you ever need to batch get all your levels you can simply pass delta 0 and it will return the current inventory level in the response BUT at constant cost - beats the pants off doing multiple calls or even multiple queries per request.
Well now you calculate your deltas for each inventory item at location and then you call inventoryBulkAdjustQuantityAtLocation.
So in theory, 1 object to query, 1 mutation. How many requests will depend how many of those inventoryItems queries you can squeeze in to 1 request - and I am too lazy to do the math. I wouldn’t worry about the bulk adjustment then, that one is a monster and should plough your through quite comfortably.
Now if you read all that thinking, yeah, but our SKUs are NOT unique, well then…
Okay, I do mean that sort of seriously. Though if you’d still need to do it via SKU, then I’d keep a synced lookup table or index of SKU < > Inventory Item in your app where you can go crazy and do your SKU rules whichever way you want, then query a SKU to get your Shopify Inventory Item ID so you can batch update levels without doing 1000’s of requests to aggregate all the IDs you’d need.
Hope this helps!