Reads the site's visible product categories, as a tree or one at a time. Accessible via lynkow.productCategories.

Requires a publishable key: pass publishableKey to createClient(), or every call throws LynkowError UNAUTHORIZED. With cache: true, responses are cached for 5 minutes.

Access via: lynkow.productCategories

Methods

2 methods

getBySlug

TypeScript
getBySlug(slug: string, options?: BaseRequestOptions & { market?: string }): Promise<ProductCategory>

Fetches one visible product category by its slug, with its structuredData (render it with renderJsonLdGraph()) and without children. Takes the slug only, never a pcat_... id. With a locale, the slug can be the one of that locale, and an untranslated category is served in the closest available locale with isFallback: true. Throws LynkowError NOT_FOUND (apiCode PRODUCT_CATEGORY_NOT_FOUND) for an unknown slug, an inactive or internal category or one under such a parent, an untranslated category with fallback: false, and when categories are off for the site.

Parameter

Type

Description

slug

string

The category's URL slug (e.g. 'kitchen').

options

BaseRequestOptions & { market?: string }

locale, fallback, market and fetchOptions.

Returns: Promise<ProductCategory>

TypeScript
import { renderJsonLdGraph } from 'lynkow'

const category = await lynkow.productCategories.getBySlug('kitchen', { locale: 'fr' })
// <div dangerouslySetInnerHTML={{ __html: renderJsonLdGraph(category.structuredData?.graph) }} />

tree

TypeScript
tree(options?: BaseRequestOptions): Promise<ProductCategoryTreeNode[]>

Fetches the tree of visible categories: each node nests its sub-categories in children, ordered by position. An inactive or internal category is left out with its whole branch. With a locale, an untranslated node is served in the closest available locale with isFallback: true, and fallback: false leaves it out with its branch. Throws LynkowError NOT_FOUND (apiCode PRODUCT_CATEGORY_NOT_FOUND) when categories are off for the site.

Parameter

Type

Description

options

BaseRequestOptions

locale, fallback and fetchOptions.

Returns: Promise<ProductCategoryTreeNode[]>

TypeScript
const roots = await lynkow.productCategories.tree({ locale: 'fr' })
for (const root of roots) {
  console.log(root.name, root.path, root.children.map((child) => child.name))
}