I am trying to filter products within a collection using the Storefront GraphQL API: -
query ($handle: String!, $filters: [ProductFilter!]) {
collection(handle: $handle){
products(first: 250, filters: $filters) {
edges {
node {
id
handle
title
descriptionHtml
productType
tags
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
Vars:
{
"handle": "******",
"filters": [{"tag": "*****"}]
}
I’ve redacted the specifics for privacy reasons.
There are two problems with this: -
-
The number of products returned is minimal. Pinging the “products” endpoint gives 40 products for a query using the above criteria, the above returns 12. It is a similar story for other collections and filters.
-
If I add more filter criteria, the system returns unexpected results. For example, stipulating two product tags returns products as if the tags are considered an “OR” query. I’ve just checked the documentation and this does seem to be expected behaviour…
In this case, how would I filter by two “tags”?
–
If anybody could provide insight into why only a certain number of products are returned, that would be greatly appreciated. The latter issue I can work with.
Hi @Richard_Peck ,
Thanks for your post. When testing just now in a test store with the Storefront API v2023-04 using the query that you specified all expected products are being returned with different combinations of a collection handle and a tag.
If you’re still having trouble with products consistently missing from the query please submit a support request through the Partner dashboard and use the API Support topic and Email path. Important details include a specific example from a store that you have staff or collaborator access to with details of both queries used (the product one as well as the collection one), which App is making the queries, which API version is being used, and a specific product that keeps getting excluded from the results even though it matches the filter.
For the part about tag filtering, if you’re looking for an ‘AND’ type filter on multiple tags setting up the variables this way works:
{
“handle”: “test-1”,
“filters”: [
{
“tag”: “skis”,
“tag”: “Large”
}
]
}
Hope you have a great day,
Jon551
Many thanks for the comprehensive response!
Let me send a support request in the partner dashboard. I’ll also check your suggestion regarding the tag filters. I am quite sure I did test that but will look again.
I’ll provide an update having done so.
Nope, filters not respecting “AND” functionality at all. Will detail it further in partner dashboard support ticket. Thank you for your help.
@Richard_Peck did you find a solution to this you could share? We’re hitting the same issue and looking for a non-hack solution.
@Richard_Peck Actually, I found this suggestion to work! Maybe an update since this post, but it works on 2023-10 at least.
After a lot of back-and-forth with technical support, it turns out they don’t support filtering collections with a large number of products inside. Since the collection I wanted to filter had 7k products, this was causing the problem. Smaller collections should work fine.