Get all categories with custom attributes in Magento 2 REST Api

Get all categories with custom attributes in Magento 2 REST Api

August 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Get all categories with custom attributes in Magento 2 REST Api

Get All Categories with Custom Attributes in Magento 2 REST API

If you’re using the Magento 2 REST API for listing all the categories, the default endpoint {{production_url}}/index.php/rest/V1/categories will return basic information about each category, including ID, parent ID, name, and other fundamental attributes. However, if you need custom attributes for each category in the result set, you currently have to call the endpoint for each individual category.

Here’s an example of the default response format:

{
    "id": 2,
    "parent_id": 1,
    "name": "Default Category",
    "is_active": true,
    "position": 1,
    "level": 1,
    "product_count": 0,
    "children_data": [{
        "id": 3,
        "parent_id": 2,
        "name": "T-shirts",
        "is_active": true,
        "position": 1,
        "level": 2,
        "product_count": 8
    }, {
        ...
    }],
    ...
}

To retrieve custom attributes, you need to call the category ID-specific endpoint:

{{production_url}}/index.php/rest/V1/categories/3

This query will return a more detailed response including the requested custom attributes:

{
  "id": 3,
  "parent_id": 2,
  "name": "T-shirts",
  ...
  "custom_attributes": [
    {
      "attribute_code": "description",
      "value": "<p>retest</p>"
    },
    {
      "attribute_code": "image",
      "value": "Screen_Shot_2017-06-16_at_4.06.35_PM.png"
    },
    ...
  ]
}

However, if you have a large number of categories (n categories), you would need to make n separate API calls to retrieve all the custom attributes.

Single API for All Custom Attributes

As of Magento 2’s current REST API implementation, there isn’t a single endpoint that returns custom attributes for all categories at once. The official documentation doesn’t provide such an option.

This limitation is due to the way Magento handles category data. Each category has its own set of custom attributes stored in separate tables (e.g., catalog_category_entity_varchar, catalog_category_entity_text, etc.). Retrieving these in a single query would require complex database joins, which could impact performance for large datasets.

Workaround and Best Practices

  1. Batch Processing: If you need to process a large number of categories, consider using batch processing techniques on the client side or server side (with your own backend service). You can break down the category list into smaller chunks and make multiple API calls in parallel.

  2. Caching Strategies: Implement caching for the custom attribute data after retrieval. This way, you only need to fetch the attributes once per session or time period, reducing the number of API calls required.

  3. Expand the REST API (Advanced): If you have extensive customization needs and technical expertise in extending Magento’s core functionality, you could consider creating a custom REST API module that provides an endpoint for retrieving all categories with their respective custom attributes in one request. This would require deep knowledge of Magento’s data model and API architecture.

  4. Use GraphQL: Magento 2 also supports GraphQL, which allows you to define complex queries for retrieving multiple types of data (including custom attributes) in a single request. You can create a GraphQL schema that includes the category information along with the necessary custom attributes. This approach could be more efficient than the current REST API.

Conclusion

While Magento 2’s default REST API doesn’t currently provide a single endpoint for retrieving all categories with their respective custom attributes, there are several workarounds and best practices you can employ to optimize your data retrieval process.

Remember to consider performance implications when dealing with large datasets. Implementing caching strategies and using efficient batch processing techniques can significantly reduce the number of required API calls.

If you find that the current limitations in Magento’s REST API don’t meet your specific use case, you might want to explore more advanced customization options or leverage GraphQL for a more flexible data retrieval experience.

For more information on Magento 2’s REST and GraphQL APIs, I recommend checking out the official Magento 2 documentation.

Further Reading

To learn more about working with Magento 2’s REST API, consider reading our in-depth guide: Mastering Magento 2 REST API for Headless Commerce Development on Laravel Company.

Magento 2 Catalog Database API

Our network