> For the complete Lynkow documentation index in agent-friendly format, see [llms.txt](/llms.txt).

# CategoriesService

**Published**: 2026-11-30
**Category**: Services

Reads blog categories as a flat list, a nested tree or a single category with its articles,
available as `lynkow.categories`. With `cache: true`, responses are cached for 5 minutes.

Access via: `lynkow.categories`

## Methods

**4** methods

### `clearCache`

```typescript
clearCache(): void
```

Clears every cached category response held by the client. Call it when a `category.*` webhook arrives
so the next read fetches fresh data.

Returns: `void`

```typescript
// On category restructuring:
lynkow.categories.clearCache()
```

---

### `getBySlug`

```typescript
getBySlug(slug: string, options?: CategoryOptions & BaseRequestOptions): Promise<CategoryDetailResponse>
```

Fetches one category by slug with a page of its published articles. The articles default to 500 per
page, at most 500. With a locale, the category is served from the fallback locale when it has no
translation, and `fallback: false` turns that into a 404. With `cache: true`, cached for 5 minutes.
Throws `LynkowError` `NOT_FOUND` for an unknown slug, and for an empty, `'.'` or `'..'` slug, which is refused without a request.

| Parameter | Type | Description |
| --- | --- | --- |
| `slug` | `string` | The category slug, such as `'tech'`. |
| `options` | `CategoryOptions & BaseRequestOptions` | `page` and `limit` for the articles, plus request options (`locale`, `fallback`). |


Returns: `Promise<CategoryDetailResponse>`

```typescript
const { category, contents } = await lynkow.categories.getBySlug('tech', {
  page: 1,
  limit: 10
})
console.log(category.name)             // "Tech"
console.log(contents.data.length)      // Number of articles on this page
console.log(contents.meta.currentPage < contents.meta.lastPage) // Whether more pages exist
```

---

### `list`

```typescript
list(options?: BaseRequestOptions): Promise<CategoriesListResponse>
```

Fetches every category as a flat list with its published article count, for menus and filters.
Without a locale, a multi-language site lists its default-locale categories. With one, each
translation group appears once and a missing translation is served from the fallback locale
(`fallback: false` drops those). With `cache: true`, cached for 5 minutes.

| Parameter | Type | Description |
| --- | --- | --- |
| `options` | `BaseRequestOptions` | Request options. `locale` selects the language, `fallback: false` refuses a fallback. |


Returns: `Promise<CategoriesListResponse>`

```typescript
const { categories, blogUrlMode } = await lynkow.categories.list()
categories.forEach(cat => {
  console.log(`${cat.name} (${cat.contentCount} articles)`)
})
```

---

### `tree`

```typescript
tree(options?: BaseRequestOptions): Promise<CategoryTreeResponse>
```

Fetches the category hierarchy as a nested tree: root categories at the top, each with a `children`
array. Locale and fallback behave as in CategoriesService.list. With `cache: true`, cached for 5 minutes.

| Parameter | Type | Description |
| --- | --- | --- |
| `options` | `BaseRequestOptions` | Request options. `locale` selects the language, `fallback: false` refuses a fallback. |


Returns: `Promise<CategoryTreeResponse>`

```typescript
const { tree } = await lynkow.categories.tree()
// Iterate root categories and their children
tree.forEach(root => {
  console.log(root.name)
  root.children.forEach(child => {
    console.log(`  - ${child.name}`)
  })
})
```