API to Search Products by SKU

Tourist
9 0 1

Pretty sure this is a very popular question being asked around the forum but it didn't get officially resolved. We have emailed Shopify Partner and it's being rejected and instead suggesting us to ask around the forum. We're using an app that heavily depends on retrieving product information and update them, but the only way to find a product by using SKU(because most app users don't specifically put product ID) is to paginate the API call to retrieve all products and search by SKU inside the loop.

We've tried the solutions as suggested in the topics, but none of them work for non-admin access with Private Apps credentials. This API only works on browser that user already logged in as admin.

https://examplestocksync.myshopify.com/admin/products/search.json?query=sku:XYZ0000

For other browsers without logged in as admin, the API will return a JSON error: 

{"errors":"Not Found"}

Is there any way or any other workaround for this to work?

1 Like
Shopify Expert
9807 92 1560

You can't search for a SKU via the API. You can however search for a SKU using the storefront search so perhaps that's of use.

You do want to be careful if you do that since Shopify does have bot protection in place. If this is for just your store just make sure you are not calling the page too often. If you do, your app will be blocked from accessing the front end.

Here's a very old post I wrote on that idea.
https://freakdesign.com.au/blogs/news/search-for-a-shopify-product-by-sku

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Tourist
3 0 3

I've read all of the responses / reasons why this feature doesn't exist. They all seem like excuses to me for something that is very standard accross other ecommerce  API platforms. We have over 15k products listed and will likely 30k by end of year. Downloading the entire inventory 30-50 times a day is not something Shopify wants me doing!


Here's our terrible work-around:
Download entire inventory once a day. Store the product ID in a database next to the Variant SKU, cross reference for things like quantity / pricing updates. I'm charging my customer a lot of dev time for a missing / standard feature.


At this point, the work is done. I don't care if shopify ever fixes this anymore. But, just a general feedback you are not serving your customers well in this area.

3 Likes
Shopify Partner
17 0 2

Hi!

If you need to update product price or quantity by SKU, there is an app that can help: https://apps.shopify.com/excel-export-import.

You just need to prepare the Excel document with Variant SKUs and data you want to update and import it into your Shopify store.

Here is the detailed tutorial on the update by SKU: https://excelify.io/2018/02/12/update-shopify-product-by-sku/. And you can find many more useful things you can do with the app.

Feel free to ask any question on that topic.

Best regards!

0 Likes
Tourist
5 0 3

Did you try the variants endpoint? So far as I know, the product endpoint does not contain product SKUs, thus the not found error.

https://examplestocksync.myshopify.com/admin/variants/search.json?query=sku:XYZ0000

 

1 Like
New Member
1 0 2

I wasn't able to find anything with a REST based solution as Shopify does not provide an API endpoint for this. I solved this by making a GraphQL request using the following body.

 

URL: https://example.myshopify.com/admin/api/<api-version>/graphql

-H 'X-Shopify-Access-Token: <ACCESS_TOKEN>' \
-H 'Content-Type: application/json' \

Body
{
  query: `query($filter: String!) {
    productVariants(first: 1, query: $filter) { 
      edges { 
          node { 
          id 
          sku 
          legacyResourceId 
          displayName 
          inventoryItem { 
            id 
            legacyResourceId 
          } 
        } 
      } 
    } 
  }`,
  variables: {
    filter: `sku:my-custom-sku`
  }
}
2 Likes
Tourist
9 0 1

Ah I've overlooked the graphQL query to find product based on SKU. Does it support multiple SKUs or only one SKU is allowed per API call?

0 Likes
Tourist
5 0 3

@Yoon 

Check out the search syntax: https://help.shopify.com/en/api/getting-started/search-syntax

You can use an OR connector to specify multiple SKU's, or other parameters.

 

Example:

"filter" => "sku:ABC123 OR sku:ABC456 OR sku:ABC789"
1 Like
Shopify Partner
50 0 7

Quick question on this...for SKU queries, it seems like this query only returns variant results if you enter the exact SKU. Prefix queries don't seem to return anything. This isn't a big deal, just wanted to confirm if that's the expected behaviour.

 

So, for example, let's say we have:

 

Product 1 has 3 SKUs: "SKU1", "SKU2", and "SKU3". 

query: "sku:SKU1 OR sku:SKU2 OR sku:SKU3"

...will return those variants.

 

But, 

query: "sku:SKU*"

(prefix query with *) returns nothing.

 

Is that the expected behaviour specifically with SKU searches?

 

Thanks!

Kris

0 Likes
Highlighted
Tourist
5 0 3

If I recall correctly, partial sku matches don't work.

 

If I may offer some advice:

I have spent a great deal of time implementing workarounds and band-aid solutions for searching products by SKU. I don't know what you're working on, but if you've landed here, then I highly recommend you use GraphQL.

https://help.shopify.com/en/api/graphql-admin-api

 

Shopify now has a handy GraphiQL App which lets you execute graph queries against your shop. I found this notably helpful in order to test and get the ball rolling.

 

With the GraphQL API, you can fetch only the data you are looking for, which makes your calls faster, while easily being able to filter by a particular SKU.

1 Like