FROM CACHE - en_header

Find Product by SKU, 2.0

Stacey7
New Member
7 0 0

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:

https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/find-product-variant-by-sku-value-1532...

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?

Replies 3 (3)
Massaad
Shopify Staff
Shopify Staff
349 0 38

Hello Kristin,

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?

Massaad | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Rob_Curry
Shopify Partner
53 0 10

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.

Stacey7
New Member
7 0 0

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.