Find Product/Variant by SKU value.

Ian_Morgan1
Shopify Partner
3 0 0

I currently store references to SKUs in my own db so I can track my inventory across multiple sales channels, Shopify included.

When I want to update inventory via the Shopify JSON API, I have to pass in a Shopify product ID (rather than my SKU value).

Consequently, I can't seem to find a way to search for a product by its variants' SKU value, and update the stock accordingly. This is supported everywhere else in eBay/ Magento/ Amazon and so forth; Is this functionality supported in the Shopify API (bearing in mind I can search from the product screen by SKU), and what does the API call look like?

Thanks, Ian.

 

Replies 6 (6)
Chris_Saunders
Shopify Staff
Shopify Staff
591 0 52

In Shopify skus aren't forced to be unique so searching for a single product based on sku wouldn't work in the same way it would at the other providers.

That being said, it appears that the search API that is used by the admin is open and you can leverage that to find the products you are looking for:

curl -H "Content-Type: application/json" \
https://user:pass@yourshop.myshopify.com/admin/products/search.json?query=sku:abracadabra

 

Chris | 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

NamsteTech
New Member
1 0 0

I tried as below but it gives 404.

Is there any mistake? The same URL works on the browser after logged in site.

 

curl -H "Content-Type: application/json" https://apikey:password@mysite.myshopify.com/admin/api/2020-07/variants/search.json?query=sku:XYZ

 

Ian_Morgan1
Shopify Partner
3 0 0

Appreciate the response Chris, will check it out. I think it's a bit strange that this isn't inherently supported in the API as it would make sense for a lot of sellers, and returning a list of matched variants would be fine. I think it's down to the seller to make a good choice in SKU naming rather than the marketplace, so not enforcing 'uniqueness' makes sense to me anyway.

Ian_Morgan1
Shopify Partner
3 0 0

That works nicely, thanks. Also tried it with the OAuth token which also works fine.

Thanks for your help!

gchoney
New Member
2 0 0

This is not working against the PUT request. It shows error "{'errors': {'id': 'expected String to be a id'}}". Could you help me with this.

olivert
Explorer
51 12 20

Hi there was a question like this the other day.

You can do this with graphql.

Example below:

https://community.shopify.com/c/Shopify-APIs-SDKs/sku-search-return-not-found/m-p/793300#M52069