FROM CACHE - en_header

How do I search for a product based on the SKU?

Shopify Partner
61 0 14

I want to search for products based on the SKU's.

I've tried:


ShopifyAPI::Product.find(sku: 'wi196217')

# => ActiveResource::ResourceNotFound: Failed.  Response code = 404.  Response message = Not Found.
from /Users/narzero/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activeresource-4.0.0/lib/active_resource/connection.rb:144:in `handle_response'


p = Curl.get('https://<REDACTED>:<REDACTED>';) do |http|
  http.headers['Content-Type'] = 'text/plain'
  http.headers['Accept'] = '*/*'

puts p.body

# => "{\"errors\":\"[API] That action is not currently supported.\"}"

Method 2 works when using the Advanced Rest Client.

What should I try next?

Replies 5 (5)
Shopify Staff
Shopify Staff
208 9 47

Hi Narek. Since the SKU is actually on a specific variant of a product, you'll have better luck with something like this : 

ShopifyAPI::Variant.where(sku: 'wi196217').first


Shayne | Developer Advocate @ 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 or the Shopify Web Design and Development Blog

Shopify Partner
61 0 14

Hi Shayne,

That doesn't work. It returns a bunch of variants, sometimes the correct variant (the one that contains the matching sku) is in there and sometimes it just isn't.

Is there no other way to retrieve a product id based on the sku?


Shopify Partner
8 0 0

Shayne, is there a way to do a not search? For example, I'd like all products with a sku that is not wi196217.

Shopify Partner
24 0 0

It doesn't look like that's possible through the API. The only way you could do it would be to loop through the Products and Variants until you found a match, or store a local database with the Variant id, sku and product_id.

Shopify Partner
24 0 0

This would be cool:

ShopifyAPI::Variant.find(:all, params: { :sku => 'SKU123' } )