Retrieve Nested Categories in Storefront

A product category has parent and child categories.

To retrieve the child or nested categories of a category in your storefront, pass to the Get a Category API Route the following query parameters:

  • include_descendants_tree=true to retrieve each category's nested categories at all levels.
  • Add category_children to fields, which is the field that will hold a category's nested categories. You can either pass *category_children to retrieve all fields of a child category, or specify the fields specifically to avoid a large response size. For example, field=category_children.id,category_children.name.
  • parent_category_id=null to retrieve only the categories that don't have a parent. This avoids retrieving the child categories multiple times in the response since child categories are now set in their parent's object.

For example:

The product_category field in the response has a category_children field. It's an array of product category objects.

Was this page helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break