Is there a way to fetch custom filters for a particular category in Magento 2 using Rest api?

Is there a way to fetch custom filters for a particular category in Magento 2 using Rest api?

September 11, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Is there a way to fetch custom filters for a particular category in Magento 2 using Rest api?

Fetching Custom Filters for Specific Categories in Magento 2 using REST API

As a senior developer, I understand your requirement of fetching category-specific filters using Magento 2’s REST API. This is indeed possible by leveraging the built-in filter functionality provided by the platform.

Understanding Magento’s Attribute System

Magento allows you to create attributes and assign them to specific product types or categories. When you add an attribute to a category, it becomes available for filtering within that category only. This is what enables the dynamic display of relevant filters based on the selected category.

For example, if you have a clothing store with different size options (S, M, L), you can create a “Size” attribute and assign it to your clothing categories. The system will then automatically make this filter available when browsing the clothing category but not for other product types like electronics or accessories.

Retrieving Category-Specific Filters via API

To fetch these category-specific filters using the REST API, you’ll need to use the searchCriteria parameters in combination with the filterGroups field. However, directly filtering by category ID as you’ve done won’t work for fetching filter attributes since the system doesn’t expose this data at the product level.

Instead, we can query the attribute options directly and then associate them with categories through a separate API endpoint. Here’s how to do it:

  1. Fetch All Attribute Options

You can use the following API endpoint to retrieve all available attribute options across your entire store:

GET /rest/default/V1/attributes?searchCriteria[filterGroups][0][filters][0][field]=attribute_set_id&searchCriteria[filterGroups][0][filters][0][value]=2&searchCriteria[filterGroups][0][filters][0][condition_type]=eq

This endpoint returns a list of all attributes assigned to the specified attribute set (in this case, ID 2). You can adjust the attribute_set_id value based on your store configuration.

  1. Map Attributes to Categories

Each attribute is assigned to one or more categories through an attribute set. To find out which category(ies) an attribute belongs to:

GET /rest/default/V1/attributes/{attributeId}

Replace {attributeId} with the actual ID of the attribute you want to fetch.

The response will contain a category_ids field that lists the IDs of all categories assigned to this particular attribute. This information tells us which filters should be displayed for each category.

  1. Create Filter Attribute Options

To make these attributes visible as filter options in the frontend, they must have associated option values:

GET /rest/default/V1/attributes/{attributeId}/options

Again, replace {attributeId} with your attribute’s ID to fetch its option values. These are the actual choices that will appear as filters.

Putting It All Together

To summarize, here’s how you can build a data flow to support category-specific filtering:

  • Fetch all attributes using the endpoint mentioned in step 1.
  • For each attribute, use step 2 to determine which categories it should apply to.
  • Use step 3 to retrieve the option values for each attribute.

Now, you have everything needed to construct a dynamic filter system that displays only the relevant options based on the currently selected category.

Remember, this approach assumes that your filters are configured at the attribute level and assigned correctly to their respective categories within Magento’s backend. The REST API merely provides access to this pre-configured data.

Conclusion

Fetching category-specific filters in Magento 2 using the REST API requires a combination of querying attributes, mapping them to categories, and retrieving their option values. While it involves multiple API calls, the process is straightforward once you understand how Magento structures its attribute system.

By following these steps, you can build a robust filtering system that enhances your users’ browsing experience by showing only the most relevant options for each product category.

For more detailed information on Magento’s REST API endpoints and their parameters, I recommend checking out the official documentation at https://laravelcompany.com/magento-2-rest-api-documentation/.

Magento 2 Catalog Database API

Our network