Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Storefront API Collection filtering by productType not working

Storefront API Collection filtering by productType not working

alamincse07
Shopify Partner
2 0 0

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?


Replies 2 (2)

alamincse07
Shopify Partner
2 0 0

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:

Delarocha
Visitor
2 0 0


Hello @alamincse07 , in which section did you say you activated this filter?