# Implement Category pages

Nosto provides functionality to retrieve all products for a specific category. This is useful when you want to implement category merchandising using the same API as for Search.

## API Requests <a href="#autocomplete" id="autocomplete"></a>

### Using category ID and category path

{% hint style="info" %}
Using the category ID is only fully supported for Shopify merchants. Others should use the category path instead to benefit from full functionality.
{% endhint %}

Provide the [categoryId](https://search.nosto.com/v1/graphql?ref=InputSearchProducts) API parameter to fetch all products associated with that category. Additionally [categoryPath](https://search.nosto.com/v1/graphql?ref=InputSearchProducts) should be provided for better analytics data.

#### Query

```graphql
query {
  search(
    accountId: "YOUR_ACCOUNT_ID"
    products: {
      categoryId: "123456789",
      categoryPath: "Pants"
    }
  ) {
    products {
      hits {
        productId
        name
        url
        imageUrl
        price
      }
      total
      size
    }
  }
}
```

{% hint style="info" %}
Product fields that can be requested in the `hits` object are documented [here](https://search.nosto.com/v1/graphql?ref=SearchProduct). All indexed fields are accessible via the API.
{% endhint %}

### Using only category path

Provide the [categoryPath](https://search.nosto.com/v1/graphql?ref=InputSearchProducts) API parameter to fetch all products associated with that category. This parameter is the same as the `categories` product field.

#### Query

```graphql
query {
  search(
    accountId: "YOUR_ACCOUNT_ID"
    products: {
      categoryPath: "Pants"
    }
  ) {
    products {
      hits {
        productId
        name
        url
        imageUrl
        price
      }
      total
      size
    }
  }
}
```

{% hint style="info" %}
Product fields that can be requested in the `hits` object are documented [here](https://search.nosto.com/v1/graphql?ref=SearchProduct). All indexed fields are accessible via the API.
{% endhint %}

#### Child category handling

Depending on your configuration, fetching a parent category will also include products from the child categories. For example, fetching products for the category `Pants` would also include products from the categories `Pants -> Shorts` and `Pants -> Khakis`.

This is an admin-only setting. Please contact your Nosto representative to adjust this setting.

### Using custom filters

In some rare cases [categoryId](https://search.nosto.com/v1/graphql?ref=InputSearchProducts) or [categoryPath](https://search.nosto.com/v1/graphql?ref=InputSearchProducts) is not enough. In these cases [custom filters](https://search.nosto.com/v1/graphql?ref=InputSearchFilter) can be used to build any query for category & landing pages.

#### Query

```graphql
query {
  search(
    accountId: "YOUR_ACCOUNT_ID"
    products: {
      preFilter: [
        {
          field: "productId",
          value: [
            "2276",
            "2274"
          ]
        }
      ],
    }
  ) {
    products {
      hits {
        productId
        name
      }
      total
      size
    }
  }
}
```

### Other features & implementation

The category page shares a lot of similarities with the search page, so please refer to the search page documentation:

{% content-ref url="/pages/gw8yjgpxCgqq1YI6Cz7N" %}
[Implement Search results page](/techdocs/implementing-nosto/implement-search/implement-search-using-api/implementing-search-page.md)
{% endcontent-ref %}

## Analytics

### Nosto Analytics

To analyze user behavior you need to implement tracking. This can be achieved in two different ways, depending on the integration environment:

* [JavaScript library](/techdocs/implementing-nosto/implement-search/search.md#search-1) (recommended - more convenient, but requires a JavaScript environment).
* [GraphQL API](/techdocs/implementing-nosto/implement-search/implement-search-using-api/analytics-ab-testing.md) (works anywhere).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nosto.com/techdocs/implementing-nosto/implement-search/implement-search-using-api/implementing-category-pages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
