Retrieve a Product in the Storefront
Retrieve a product by ID or handle.
On this page
In this guide, you'll learn how to retrieve a product and its details in the storefront.
On Next.js, retrieve from src/lib/data/products.ts with "use server". Pass storeCode first and region_id (resolved from [countryCode]) when you need calculated prices. See Show Products and Build a Next.js Storefront.
ts
How to Retrieve a Product in Storefront?
There are two ways to retrieve a product:
- Retrieve a product by its ID. This method is straightforward and useful when you only have access to the product's ID.
- Retrieve a product by its
handlefield. This is useful if you're creating human-readable URLs in your storefront.
Retrieve a Product by ID
To retrieve a product by its ID, send a request to the Retrieve Product API route:
Tip: Learn how to install and configure the JS SDK in the Getting started guide.
React
tsx
JS SDK
ts
The response has a product field, which is a product object.
Tip: Refer to the Features in Product Details Page section to learn about other features you can add to a product details page.
Retrieve a Product by Handle
To retrieve a product by its handle, send a request to the List Products API route passing the handle query parameter:
React
tsx
JS SDK
ts
Retrieve Translated Product
Prerequisites
- Translation Module Configured
By default, Aiminaabee returns the product's original content (such as title and description).
If you support localization in your storefront, you can set the locale to retrieve product information based on the customer's preferred language.
You can set the locale using one of the following methods:
- Use the JS SDK's
setLocalemethod. The JS SDK will automatically include the locale in subsequent requests. - Pass the
localequery parameter to the List Products API route. - Set the
x-aiminaabee-localeheader in the API request to the List Products API route.
For example:
Using JS SDK
ts
Using Query Parameter
bash
Using Header
bash
The returned product will have the same structure as described in the products schema, but fields such as title and description will be in the specified locale:
json
If translations aren't available for the selected locale, or no locale is selected, the product's original content is returned.
Retrieve in Server-Side Environments
For server-side environments (such as server components or server actions in Next.js), you can set the locale using cookies to persist the selected locale across requests.
Learn more in the Storefront Localization guide.
Features in Product Details Page
On a product details page, you typically want to allow customers to choose a variant, see its price, and add it to the cart.
The following guides will help you add these features to your storefront: