I am having hard time fetch products for a specific product category using storefront graphql api

So we’re building a buy-now-pay-later store module in our web-app that will be integrated into Shopify (via Shopify’s Storefront APIs).

We are using storefront Shopify API to fetch products to view on our custom react page. We need to categorise the products listing on page. For this, we need to fetch products for a specific product category. I explored the both admin and storefront endpoints I found the endpoints to filter by productType and collection but couldn’t find a one to filter the products for specific category.

As per my knowledge we can filter the products for a collection. But we need to filter by product category.

Thanks in advance.

Unfortunately, Shopify’s Storefront API does not have a direct endpoint for filtering products by category. However, you can filter products by collection, which is a group of products that share a common theme or characteristics, and then within the collection, you can categorize the products by adding tags to each product.

Here’s a sample GraphQL query that fetches products from a specific collection and then filters them by tags:

javascriptCopy code
query { collection(handle: "collection-handle") { title products(first: 20) { edges { node { title tags ... on Product { category: tags(first: 1) { edges { node { name } } } } } } } } }

In this example, replace collection-handle with the handle of the collection you want to fetch products from. The tags field returns an array of all the tags assigned to a product, and category is a custom field that uses the tags field to only return the first tag assigned to the product, which would be used as the product’s category.

Unfortunately, Shopify’s Storefront API does not have a direct endpoint for filtering products by category. However, you can filter products by collection, which is a group of products that share a common theme or characteristics, and then within the collection, you can categorize the products by adding tags to each product.

Here’s a sample GraphQL query that fetches products from a specific collection and then filters them by tags:

javascriptCopy code
query { collection(handle: "collection-handle") { title products(first: 20) { edges { node { title tags ... on Product { category: tags(first: 1) { edges { node { name } } } } } } } } }

In this example, replace collection-handle with the handle of the collection you want to fetch products from. The tags field returns an array of all the tags assigned to a product, and category is a custom field that uses the tags field to only return the first tag assigned to the product, which would be used as the product’s category.

Unfortunately, Shopify’s Storefront API does not have a direct endpoint for filtering products by category. However, you can filter products by collection, which is a group of products that share a common theme or characteristics, and then within the collection, you can categorize the products by adding tags to each product.

Here’s a sample GraphQL query that fetches products from a specific collection and then filters them by tags:

javascriptCopy code
query { collection(handle: "collection-handle") { title products(first: 20) { edges { node { title tags ... on Product { category: tags(first: 1) { edges { node { name } } } } } } } } }

In this example, replace collection-handle with the handle of the collection you want to fetch products from. The tags field returns an array of all the tags assigned to a product, and category is a custom field that uses the tags field to only return the first tag assigned to the product, which would be used as the product’s category.