GRAPHQL API. Search products variant with part of SKU

Shopify Partner
38 0 4

Hi, I want to make a simply call to check product variant with a SKU,

 

This works:

{productVariants(first: 250, query: "sku:DISP01") {
          edges {
            cursor
            node {
              id
              sku
            }
          }
        }
    }

It shows the DISP01 product variant.

 

But if I put this:

{productVariants(first: 250, query: "sku:DISP") {
          edges {
            cursor
            node {
              id
              sku
            }
            
          }
        }
    }

Nothing.

 

I have also tried:

"sku:DISP*"
"sku:DISP?"
"sku:DISP%"

How could I make this kind of search? 

 

Thanks

0 Likes
Highlighted
Shopify Staff
Shopify Staff
426 57 65

Hey @juan3211 ,

 

The Shopify documentation on query/search syntax should be able to help you here: https://shopify.dev/concepts/about-apis/search-syntax

 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Shopify Partner
38 0 4

Thanks Hassian, I have already read it, but I can't get it working. Could you please help me with the example ? Thanks

0 Likes
Highlighted
Shopify Partner
38 0 4

Hi @hassain  could you try to test my example ? thanks

0 Likes
Highlighted
Shopify Staff
Shopify Staff
426 57 65

Hi @juan3211 ,

 

As per your suggestion, I tried your example and investigated into this use case further. From what I found, it turns out that while Shopify does allow for wildcard matching on most queries, for SKU we expect an exact match to occur (so no wildcards can be used). I will let you know if this changes in the future.

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Shopify Partner
38 0 4

Hi, it is a very strange thing. Could you please open an official request and give me the number ?

 

Thanks

0 Likes
Highlighted
Shopify Partner
38 0 4

Hi ?

0 Likes
Highlighted
Shopify Partner
38 0 4

Hi?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
426 57 65

Hey @juan3211 ,

 

Thank you so much for your patience here.

 

Wanted to let you know that with the GraphQL Admin API, you should be able to query for product variants based on a partial match (e.g. wildcard search) for their SKU through the "products" query root. An example of how to do this is as follows:

 

query {
	products(first:10, query:"sku:1*") {
    edges {
      node {
        id
        title
        variants(first:10) {
          edges {
            node {
              sku
              id
              title
            }
          }
        }
      }
    }
  }
}

The reason why this was added to the "products" query root was so that this partial SKU query could also be supported in the search bar of the Shopify Admin web page. 

 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes
Highlighted
Shopify Partner
38 0 4

Thanks @hassain a lot. That works.

 

The way that you have told us is very risky. As we have to ask for "FIRST" elements two times, we could "lost" some of the results as we have to ask for very few products and a big number for variants not to to a lot of little queries in a row.

 

I want to mantain the official request opened. Could you please give me the number ?

 

Hope your answer, thanks

0 Likes