Retrieve a Category in Storefront

In this guide, you'll learn how to retrieve a product category and its details in the storefront.

How to Retrieve a Product Category in Storefront?#

There are two ways to retrieve a product category:


Retrieve a Product Category by ID#

To retrieve a product category by its ID, send a request to the Get a Product Category API route:

Tip: Learn how to install and configure the JS SDK in the JS SDK documentation.

In this example, you send a request to the Get a Product Category API route with the category's ID.

The response has a product_category field, which is a product category object.


Retrieve a Product Category by Handle#

To retrieve a product by its handle, send a request to the List Product Categories API route passing it the handle query parameter:

In this example, you filter the product categories by their handle and retrieve the first product category that matches the handle. Since handles are unique, you can be sure that the product category you retrieve is the one you're looking for.

If no product category matches the handle, the product category doesn't exist, so you can show a 404 error or a custom message to the customer.

The product category in the response is a product category object.

Was this page helpful?
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