Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
We are facing some issues to get the expected results from the Shopify API. Here is an example query to get products for collection AG and productType = Tee, but the graphql query we are using is not returning us the expected result.
Here is the API reference that we followed, API_VERSION = '2022-04'
https://shopify.dev/api/examples/filter-products#query-products-by-type
Below is the GraphQL query:
query MyQuery {
collection(handle: "ag") {
products(filters: {productType: "Tee"}, first: 2) {
edges {
node {
id
productType
}
}
}
}
}
Query result returned:
{
"collection": {
"products": {
"edges": [
{
"node": {
"id": "gid://shopify/Product/767547",
"productType": "Denim"
}
},
{
"node": {
"id": "gid://shopify/Product/7267",
"productType": "Short"
}
}
]
}
}
}
See the returned products type is not "Tee". But we have the products with this type in the store inventory.
Can someone please help with this? What is wrong with the query?
OK this turned out to be a configuration issue. To allow filtering by product type, it needs to be turned on in the admin for your store. If you navigate to: Online Store > Navigation
... and scroll to the bottom, you will see where you can add allowed filters: