How to get a product by SKU via StoreFront API?

How to get a product by SKU via StoreFront API?

mmarienko
Shopify Partner
23 0 14

I need to get a product by SKU via StoreFront API, but that is impossible for me. I didn't find any information about that on the Shopify dev doc. I found only GraphQL filter by SKU, but it is not available for StoreFront, only for Admin API. 
Is there another way?

Regards, Max Marienko - Shopify Expert
Reply 1 (1)

adrocodes
Shopify Partner
1 0 0

Hey Marienko,

 

You can access the SKU through the storefront API, they are just tied to a Product Variant. Even if you don't add a variant to a product, there will always be at least one with the SKU that has been entered. (In the returned data, the title is usually "Default Title", if you haven't added a product variant)

 

If your products do have variants, then the SKU will change based on the selected SKU.

 

Hopefully that helps. Here is an example GraphQL Query:

{
  products(first:10){
    edges{
      node{
        id
        variants(first:100) {
          edges {
            node {
              sku
              title
            }
          }
        }
      }
    }
  }
}