A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi, I am new to the Shopify REST API. We are trying to work with our client's API developer to update their inventory every hour. The store has only about 1,000 skus and likely won't need to update inventory for more than 20-40 skus each out, at most. We wrote the Shopify side of the API and had it make one call to get the product skus and quantities (which I believe is 4 calls for 1000 products because of the 250/call max). We didn't have access to the client's inventory so we tested with a txt file but when we tested changes to inventory skus they updated as expected, only updating skus where inventory had changed. The client's developer came back and said that he's having to make 2 calls to get the product skus and quantities, a separate call for the sku and a separate call for the quantities. I told him when we wrote it and tested it, it was a single call but he's adamant that he has to make two separate calls (so 8 calls total because of 1,000 products). He mentioned that he had to do this because when he tested it wasn't updating the inventory so he was using inventory quantity vs. available quantity. So my two questions are:
Not too long ago Shopify changed to multiple shop inventory. So that might explain the situation where per-shop inventory is coming into play.
If you look into the Shopify GraphQL API you can make more efficient API request calls --> https://shopify.dev/docs/admin-api/graphql/reference. You can grab any product, its variants, and its per-shop inventory levels all in a single call. Using bulk operations (https://shopify.dev/tutorials/perform-bulk-operations-with-admin-api) you can literally handle this for the entire shop in a single API call, polling to see if the bulk operation has completed. When completed you then pull the JSONL results file from the URL that the API response provides for you.
Thanks so much Greg, appreciate the response.
We used this endpoint:
Uri("https://" + shopifyUrl +
"/admin/api/2020-04/products.json?fields=id,title,variants")
where "shopifyurl" is the name of our shopify page
We used the REST api. As I mentioned, when we used that we got all the inventory levels with 1 call but the inventory side dev said he couldn't. So we're confused. But are you thinking that the REST API wouldn't work and we need to switch the the GraphQL API?
When I tried your example I do see underneath the variants the inventory_quantity field value. Which is the sum on-hands for that particular variant. If you don't care about per-site allocations then this one REST API query request is sufficient. If it isn't sufficient (due to requiring per-site allocation details) then if you are using the REST API you'd also need to query the inventory_level endpoint --> https://shopify.dev/docs/admin-api/rest/reference/inventory/inventorylevel. Otherwise you should be fine with what you have. Just taking into account the cursor-based pagination --> https://www.shopify.com/partners/blog/relative-pagination.
Greg, thank you again. This is very helpful.