Filter products by SKU starting with certain prefix

Topic summary

Goal: Retrieve product variants whose SKU begins with a given prefix via Shopify’s GraphQL API.

  • Attempted approach: productVariants query using query: “sku:ABC_DEF-*” returned no results. Using an exact SKU (e.g., ABC_DEF-1234) does return the correct variant, confirming data exists with that prefix.
  • Ask: How to filter variants by SKU prefix (i.e., starts-with) using GraphQL.

Follow-ups and context:

  • The author asked whether a suggested solution is available in the official Shopify Python API library.
  • They clarified their use case is an external app that updates inventory levels, not Liquid templates, so Liquid-based solutions are not applicable.

Status:

  • No confirmed solution provided in the discussion text.
  • Key open question: Whether Shopify’s GraphQL search supports prefix queries on SKU (and if so, how), or if an alternative API/library method is required.
Summarized with AI on December 27. AI used: gpt-5.

Hi, I’m trying to use the GraphQL productvariants api to search for products where the SKU starts with a certain string, let’s say ABC_DEF-. My query is like this :

{
productVariants(first: 10, query: “sku:ABC_DEF-*”) {
edges{
node{
id
sku
}
}
}
}

This doesn’t return any result. If I put a valid SKU like ABC_DEF-1234, instead of ABC_DEF-*, it does return the correct product, so there are products with my SKU prefix.

How can I get all products with a certain sku prefix ?

Thanks in advance

1 Like

Thanks for your reply. Is this integrated in the official python’s library ?

Thanks, but that doesn’t help in my case. I’m have an external app that update products’ inventory levels. It’s not used inside liquid code.