I am trying to update a Variant's inventory using the SKU we have provided to reconcile the id.
Some time ago this question was asked:
However, the answer does not appear to work anymore against the new API. As far as I can tell the only way to get the SKU would be to query for all the products in the Shopify database, iterate through all the variants, so that I can find the SKU. This would be wildly inefficient from our perspective and for any Shopify servers.
Is there a way to query for a Product Variant based on the SKU alone? If not, when can we expect this feature to be available?
It is more related to the nubmer of records that are returned by the search. Since SKU is non-unique it would not necesarily provide the relationship you require. For example, if the API returns 5 results (due to 5 sizes sharing a SKU) the client getting this data still needs to iterate through. It is better to find the ID and get the data returned directly. But the results you need can be found with the existing API.
You are correct in your statement. It would be a massive server hog to iterate all variants each time you want to match the SKU. LIkely the app would hit the API limit rapidly.
In fact any request to the internet would be many magnitudes slower compared to a local lookup. The recomended way for an app to do this would be to pull the information down to your own database. This architecture provides the swiftest response for your customers.
This app could then create the SKU to ID relationship you require allowing your app to find the variant by SKU lookup utomatically.
Does this make sense?
I agree, doing the search in realtime would be a massive overhead. I think the best option would be to set a scheduled task which on every execution (daily, hourly whatever) downloads all products and stores in a local database. I do this for a number of private apps and seems to work well.
Another option, which i haven't actually tried, is to access the admin product search using GET /admin/products?query=[SKU]
If in your system, the SKUs are unique, then i think it would only return 1 result. As i say, i haven't tried this from the API wrapper, but i dont see why it wouldnt work.
Thanks for the replies everyone. I feel like it's a bizarre notion to have non-unique SKUs, since a SKU by definition (being a stock keeping unit), should be unique. This is particularly true in the context of inventory updates.
Have you created a collection on your online store and experienced an issue with adding yo...By Ollie Aug 24, 2022
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...By Ollie Jul 28, 2022