POS ProdutSearchAPI searchProducts only returning 1 variant per product

I’m using the ProductSearchAPI and I need to return the products and their variants based on a search term:

const results = await api.productSearch.searchProducts({ queryString })

However, the above api call only returns the first variant for each product. As an example, I’ll search for the term HMG. I have a product call HMG Basecoat that has 4 variants, as shown below:

When using the queryString hmg in the searchProducts endpoint, the following is returned:

Notice how only 1 variant is returned in the variants array, even though numVariants is correct with 4. This is happening with multiple products. How do I fix this to return all variants associated with a product?

Hey @21O - thanks for mentioning this. I’ll do a little digging on my end here and loop back with you once I can confirm expected behaviour :slight_smile:

Thanks @Alan_G, I look forward to hearing back from you. I’m really hoping it’s a bug and the expected behaviour isn’t to only return 1 variant… that would seem a little pointless.

Thanks,
Joe

Hi @Alan_G - did you get a chance to investigate this issue?

Cheers,
Joe

Can anyone provide an update on this? Surely it’s a bug and not how it’s expected to work?

Hey @21O - thank you for following up and apologies for the long wait. We’ve been working on this internally, but can’t seem to replicate the issue.

Would you be able to share a code snippet for your extension’s function so we can try to test on our end a bit further? I can set up a DM with you if that’s easier - just ping me here. We’ll get this looked it for sure.

Hi @Alan_G, thanks for getting back to me. This is the code I’m using to make the call:

<SearchBar
    placeholder='Search all products'
    onTextChange={searchAllProducts}
    onSearch={searchAllProducts}
/>

const searchAllProducts = async (queryString: string): Promise<void> => {
    const results = await api.productSearch.searchProducts({ queryString })
    console.log('queryString', queryString)
    console.log('results', results)
    ...
}

And the results:

So as I said in my original post, the ‘HMG’ prodcuct has 4 variants, which matches the numVariants property. However there is only 1 variants returned in the variants array. I need to return all of the variants for a product. Is this possible with this endpoint, or will I have to use a server side api call and return the data to the POS app?

Cheers

Thanks again @21O - we’ll do some more digging on our end here to confirm expected behaviour and I’ll loop back with you once I have more to share :slight_smile:

@21O sorry just catching up here. You are correct that the product search itself only returns 1 variant because it’s actually only searching for products, not the variants themselves. You can use the product Id to look up all the variants in a subsequent query.

For context this API is designed to work with a search field, and is the same that we use internally. In our case, we list the products, then when a merchant selects that product we can navigate to the variant list (firing that second query I sent you). We didn’t design this for the purpose of listing a massive list of variants within a massive list of products as this would have obvious performance implications. Not only would we be having to paginate on the product level, but paginating the variants within each product (due to the large max num of variants allowed now) would be a large technical complexity. So we designed so that you can search for the product, find the one you want, and then find the variants.

@210 I will also add that we’ll be shipping Direct API in 2025-07, which means you’ll be able to fire a GraphQL query directly from your extension. Since GQL already supports pagination on those endpoints, you should be able to achieve what you want to do in 1 query

Thanks for the reply @JS_Goupil. That makes a lot of sense, I’ll refactor my code and introduce the second endpoint. Thank you both for your help!

1 Like