How to use wildcards in Shopify API product filtering?

Hey everyone! I’m trying to figure out how to use the Shopify API to get specific products. I know we can use this to get a product with an exact handle:

GET /admin/products.json?handle=some-product

But what if I want to get all products whose handles start with a certain prefix? Like, I want to grab all products that have handles starting with ‘cool-’. Is there a way to use wildcards or something similar in the API call?

I’ve tried looking through the docs, but I’m not sure what kind of operators or syntax I can use for this kind of filtering. Any help would be super appreciated! Thanks in advance!

I’ve actually encountered this issue before when working on a client’s Shopify store. The solution that worked for me was using the ‘query’ parameter with a wildcard. Here’s what I found effective:

GET /admin/products.json?query=handle:cool-*

This approach allows you to fetch all products with handles starting with ‘cool-’. It’s pretty versatile and can be used for other fields too, not just handles.

One thing to keep in mind is that this method can be a bit slower if you have a large number of products, as it performs a search rather than a direct lookup. If performance becomes an issue, you might want to consider alternative approaches like using metafields or tags to group your products, which could be more efficient for bulk operations.

hey sofiap, i think what ur lookin for is the ‘starts_with’ operator. try somethin like this:

GET /admin/products.json?handle=cool-*

or maybe:

GET /admin/products.json?handle_starts_with=cool-

not 100% sure which one works but give those a shot! lemme kno if it helps