Catalog
The catalog group reads what a shop sells: products, categories, collections and brands. Use it to build product cards, product pages, category and collection pages, brand pages and search.
Every call takes an optional request context last ({ headers, signal, orgId }). Amounts in an answer are plain numbers in the currency: 24900 is 24.900 kr., 179.9 is 179,90 €. Format one with formatPrice from @eldrajs/sdk/format. Only the minPrice and maxPrice filters you send are in minor units.
A signed-in business customer can get their own prices from listProducts, getProduct and listCollectionProducts. See Customer prices.
catalog.listProducts
Lists the products a shop sells online, one page at a time. Use it for the shop page, category pages, filters and "new in" rows.
eldra.catalog.listProducts(options?, context?): Promise<EldraProductList>| Name | Type | Default | What it does |
|---|---|---|---|
page | number | — | Page number, starting at 1. |
pageSize | number | — | Products per page. limit is an alias. |
sort | string[] | — | Sort fields. Prefix with - for descending, as in ['-createdAt']. Accepted: createdAt, updatedAt, publishedAt, slug, category, totalVariants, translations.title, status, minPrice. |
locale | string | — | Language of titles and text, such as is-IS. |
categoryId | string[] | — | Products in any of these categories, or in any category beneath them. At most 50. |
collectionId | string[] | — | Products in any of these collections. At most 50. |
brandId | string[] | — | Products of any of these brands. At most 50. |
option | string[] | — | Option values as <optionKey>:<value>, such as colour:oat. Values of one key are OR'd; different keys are AND'd. At most 50. |
ext | string[] | — | Custom field values as <schemaApiId>.<fieldId>:<value>, such as care.fabric:wool. At most 10. |
minPrice | number | — | Lowest variant price to include, in minor units, inclusive. |
maxPrice | number | — | Highest variant price to include, in minor units, inclusive. |
onSale | boolean | — | Only products with a variant marked down below its compare-at price. |
availability | 'in_stock' | 'out_of_stock' | — | Only products a customer can buy now, or only those they cannot. |
facets | boolean | false | Adds a facets object with counts for building filters. |
filter | string[] | — | Filter tokens as field:op:value, such as slug:in:hekla,lopi-classic. |
The SDK sends each value of categoryId, collectionId, option, ext and filter as its own query parameter. Pass arrays; never join them with commas yourself.
Returns { data, meta, facets? }. data is a page of product cards, and can be null on an empty page.
| Field | What it is |
|---|---|
id, slug, title | Identify and name the product. Link to /products/<slug>. |
minPrice, maxPrice | Lowest and highest price a customer pays, after any automatic discount. Show minPrice as a "from" price when they differ. |
compareAtPrice | The merchant's compare-at price. Present only while it is above the regular price. |
priorPrice, discountLabel | Describe an automatic discount on the variant minPrice came from. |
thumbnail | { url, altText?, width?, height?, assetId }. See Images. |
brand | { id, name, slug, logo? }, when the product has one. |
totalVariants | How many variants the product has. |
options | Option swatches for the card, such as colours. |
meta | { page, pageSize, total, totalPages, rows, hasNext, hasPrev }. |
Errors worth handling
PRODUCT_FILTER_EXTENSION_INVALID(400): anexttoken is not<schemaApiId>.<fieldId>:<value>.PRODUCT_FILTER_EXTENSION_LIMIT(400): more than 10exttokens.
import { formatPrice } from '@eldrajs/sdk/format';
const { data: sweaters, meta } = await eldra.catalog.listProducts({
categoryId: [lopapeysurId],
option: ['colour:oat', 'colour:charcoal'],
maxPrice: 30000, // 30.000 kr.
sort: ['minPrice'],
pageSize: 24,
locale: 'is-IS',
});
for (const sweater of sweaters ?? []) {
console.log(sweater.title, formatPrice(sweater.minPrice, 'ISK', 'is-IS'));
}TIP
Prices in the answer are plain numbers in the currency, and minPrice already includes automatic discounts. Announce a reduction only against priorPrice.
catalog.getProduct
Reads one product with its variants, options and media. Use it for a product page.
eldra.catalog.getProduct(productIdOrSlug, options?, context?): Promise<EldraProductDetails>| Name | Type | Default | What it does |
|---|---|---|---|
productIdOrSlug | string | — | The product's id or its slug. |
locale | string | — | Language of titles and text. |
currency | string | store currency | Prices the variants in this selling currency, such as EUR. Needs gateway contract 6.19.0 or later. |
Returns the product. categoryIds, options, variants and mediaByOptionValue are always present. variants lists only variants a customer can buy.
| Field | What it is |
|---|---|
id, slug, title | Identify and name the product. |
options | Each option, such as size or colour: { id, key, kind, name, values }. |
variants | Each variant: { id, sku, price, compareAtPrice?, priorPrice?, optionValues, media? }. |
mediaLinks | The product's images. |
mediaByOptionValue | Images per option value, so picking a colour can switch the gallery. |
brand | { id, name, slug, logo? }, when the product has one. |
seo | { title?, description?, canonicalUrl?, noindex?, ogTitle?, ogDescription?, imageUrl? }. |
extensions | Custom fields, keyed by CMS schema, then field. Absent when there are none. |
requiresShipping, shipsAbroad | Whether the product is shipped, and whether it can leave Iceland. |
A product that is missing, not active or not sold online answers 404.
const sweater = await eldra.catalog.getProduct('lopapeysa-hekla', { locale: 'is-IS' });
const size = sweater.options?.find((option) => option.key === 'size');
const cheapest = sweater.variants?.reduce((a, b) => (a.price <= b.price ? a : b));
console.log(
sweater.title,
size?.values?.map((value) => value.name)
);
console.log(formatPrice(cheapest!.price, 'ISK', 'is-IS')); // "24.900 kr."Custom fields in extensions are typed once you generate types. See Generated types.
catalog.listCategories
Lists every active category in one flat list. Use it to build the category menu and breadcrumbs.
eldra.catalog.listCategories(options?, context?): Promise<EldraCategory[]>| Name | Type | Default | What it does |
|---|---|---|---|
locale | string | — | Language of titles and descriptions. |
Returns an array, never paged. It is [] when the shop has no categories.
| Field | What it is |
|---|---|
id, slug, title | Identify and name the category. |
parentId | Its nearest active parent. Absent for a top-level category. |
description, seo | Text for the category page. |
Every parentId names a category in the same list, so you can build the tree yourself.
const categories = await eldra.catalog.listCategories({ locale: 'is-IS' });
const topLevel = categories.filter((category) => !category.parentId);
const childrenOf = (id: string) => categories.filter((category) => category.parentId === id);TIP
Link a category as /categories/<path>, its slugs from the top down, such as /categories/peysur/lopapeysur. Eldra's emails link there.
catalog.listCollections
Lists the shop's active collections, one page at a time. Use it for a "shop by collection" page or a menu.
eldra.catalog.listCollections(options?, context?): Promise<EldraCollectionList>| Name | Type | Default | What it does |
|---|---|---|---|
page | number | — | Page number, starting at 1. |
pageSize | number | — | Collections per page. limit is an alias. |
sort | string[] | — | Sort fields. Prefix with - for descending. |
filter | string[] | — | Filter tokens as field:op:value. |
locale | string | — | Language of titles and descriptions. |
Returns { data, meta }. data can be null on an empty page.
| Field | What it is |
|---|---|
id, slug, title | Identify and name the collection. Link to /collections/<slug>. |
image | { url, altText?, width?, height?, assetId }, when set. |
productCount | How many products are in it. |
description, seo | Text for the collection page. |
const { data: collections } = await eldra.catalog.listCollections({ locale: 'is-IS' });catalog.getCollection
Reads one active collection by its slug. Use it for the header of a collection page.
eldra.catalog.getCollection(slug, options?, context?): Promise<EldraCollection>| Name | Type | Default | What it does |
|---|---|---|---|
slug | string | — | The collection's slug. |
locale | string | — | Language of the title and description. |
Returns one collection, with the same fields as in listCollections, plus sortMode: how the merchant ordered its products.
const collection = await eldra.catalog.getCollection('vetrarlinan', { locale: 'is-IS' });catalog.listCollectionProducts
Lists the products in one collection, one page at a time. Use it for the product grid on a collection page.
eldra.catalog.listCollectionProducts(slug, options?, context?): Promise<EldraProductList>It takes the same options as listProducts, except collectionId. Two differ:
| Name | Type | Default | What it does |
|---|---|---|---|
slug | string | — | The collection's slug. |
sort | string[] | the collection's own order | Accepted: position, title, minPrice, createdAt. Prefix with - for descending. |
Returns the same { data, meta, facets? } as listProducts. Only products a customer can see and buy are listed.
Errors worth handling: the same PRODUCT_FILTER_EXTENSION_INVALID and PRODUCT_FILTER_EXTENSION_LIMIT as listProducts.
const [collection, products] = await Promise.all([
eldra.catalog.getCollection('vetrarlinan', { locale: 'is-IS' }),
eldra.catalog.listCollectionProducts('vetrarlinan', {
availability: 'in_stock',
facets: true,
pageSize: 24,
locale: 'is-IS',
}),
]);catalog.listBrands
Lists the shop's active brands, ordered by name. Use it for a brand index or a brand filter.
eldra.catalog.listBrands(options?, context?): Promise<EldraBrand[]>| Name | Type | Default | What it does |
|---|---|---|---|
locale | string | — | Language of descriptions. |
Returns an array, never paged. It is [] when the shop has no brands.
| Field | What it is |
|---|---|
id, slug, name | Identify and name the brand. |
logo | { url, altText?, width?, height?, assetId }, when set. |
description | In the requested locale, else the default one, else absent. |
seo | Text for a brand page. |
const brands = await eldra.catalog.listBrands({ locale: 'is-IS' });catalog.getBrand
Reads one active brand by its slug. Use it for a brand page, with listProducts({ brandId }) for its products.
eldra.catalog.getBrand(slug, options?, context?): Promise<EldraBrand>| Name | Type | Default | What it does |
|---|---|---|---|
slug | string | — | The brand's slug. |
locale | string | — | Language of the description. |
Returns one brand, with the same fields as in listBrands.
Errors worth handling
CATALOG_BRAND_NOT_FOUND(404): the brand is missing or not active. Show your not-found page.
import { isEldraError } from '@eldrajs/sdk';
try {
const brand = await eldra.catalog.getBrand('istex', { locale: 'is-IS' });
const { data: products } = await eldra.catalog.listProducts({ brandId: [brand.id] });
} catch (error) {
if (isEldraError(error, 'CATALOG_BRAND_NOT_FOUND')) return notFound();
throw error;
}catalog.search
Searches the shop's public content: products, CMS entries and categories. Use it for a search box or a search results page.
eldra.catalog.search(query, options?, context?): Promise<EldraSearchResponse>| Name | Type | Default | What it does |
|---|---|---|---|
query | string | — | What the shopper typed. |
types | ('PRODUCT' | 'CMS_ENTRY' | 'CATEGORY')[] | all | Which kinds of result to return. |
limit | number | — | Most results to return. |
locale | string | — | Language to search in. |
Returns { results, total }. results can be null when nothing matched.
| Field | What it is |
|---|---|
kind | PRODUCT, CMS_ENTRY, CMS_SCHEMA or CATEGORY. |
title, summary, snippet | Text to show for the result. |
targetUrl | Where the result links to, when known. |
sourceId | The id of the product, entry or category found. |
breadcrumb | Where the result sits, for display. |
score | How well it matched. |
const { results, total } = await eldra.catalog.search('lopapeysa', {
types: ['PRODUCT'],
limit: 8,
locale: 'is-IS',
});WARNING
Search results always carry list prices, never a business customer's prices. Read prices for a signed-in customer from listProducts or getProduct.