Retrieve a Collection in the Storefront
Retrieve a collection by ID or handle.
On this page
In this guide, you'll learn how to retrieve a product collection and its details in the storefront.
How to Retrieve a Product Collection in Storefront?
There are two ways to retrieve a product collection:
- Retrieve a collection by its ID. This method is straightforward and useful if you only have the collection's ID.
- Retrieve a collection by its
handlefield. This is useful if you're creating human-readable URLs in your storefront.
Retrieve a Product Collection by ID
To retrieve a product collection by its ID, send a request to the Get a Collection API route:
Tip: Learn how to install and configure the JS SDK in the Getting started guide.
React
tsx
JS SDK
ts
In this example, you retrieve the product collection by sending a request to the Get a Collection API route.
The response has a collection field, which is a product collection object.
Retrieve a Product Collection by Handle
To retrieve a product by its handle, send a request to the List Product Collections API route passing it the handle query parameter:
React
tsx
JS SDK
ts
In this example, you retrieve the product collection by sending a request to the List Product Collections API route passing it the handle query parameter.
Since handles are unique, you can be sure that the product collection you retrieve is the one you're looking for. If no product collection matches the handle, you can show a 404 error or a custom message to the customer.
The product collection in the response is a product collection object.