---
title: "Get the knowledge document tree"
method: GET
path: "/api/knowledge/tree"
tags: ["Knowledge"]
---

# Get the knowledge document tree

`GET /api/knowledge/tree`

## Request

- Base URL: `https://core-api.getaptly.com`
- URL: `https://core-api.getaptly.com/api/knowledge/tree`
- Auth: one of:
  - API key in header `x-token`
  - API key in header `Authorization`
  - HTTP bearer
- TypeScript: <https://skmtc.dev/getaptly/apis/aptly-api/docs/api/knowledge/tree/get.ts> (a function with typed inputs; its response is checked against the schema)

Returns a lazy, depth-bounded tree of knowledge documents starting at `parentId`
(root documents when omitted). Each node reports `hasChildren` so you can decide
whether to fetch further levels via `GET /api/knowledge/{id}/children`.

Accepts the same filter parameters as `GET /api/knowledge/list` (everything below
except `limit`/`skip` — `parentId` here keeps its tree-specific meaning, the root
to start from, not a filter). With no filter active, the response is the plain
tree with no `matched` field on any node. With a filter active, the tree (already
built and depth-bounded as usual) is pruned to documents that match the filter,
plus their ancestors (so a match stays reachable from the root) and their
descendants (so a matched folder's contents stay visible) — every kept node
within the tree, matching or not, gets a `matched` boolean. A document that would
only appear more than `depth` levels below the root is never fetched, so it can't
match either — increase `depth` to search deeper.

## Query parameters

- `parentId` string
- `depth` integer
- `aptletUuid` string
- `aptletInstanceId` string
- `streamId` string
- `search` string
- `archived` boolean
- `ownerId` string
- `updatedById` string
- `createdFrom` string, date-time
- `createdTo` string, date-time
- `updatedFrom` string, date-time
- `updatedTo` string, date-time
- `unlinked` boolean

## Response `200`

Tree of knowledge document nodes.

- object
  - `nodes` KnowledgeTreeNode[]
    - `_id` string: Document ID.
    - `name` string: Document title.
    - `emoji` string, nullable
    - `iconUrl` string, nullable
    - `accessType` 'public' | 'publicReadonly' | 'private'
    - `parentId` string, nullable: Parent document ID, or null for a root document.
    - `rank` integer, nullable: Sort order among siblings. May be null.
    - `archived` boolean
    - `hasChildren` boolean: Whether this document has at least one child, whether or not it was expanded.
    - `matched` boolean: Only present when at least one of the tree endpoint's filter parameters (aptletUuid, aptletInstanceId, streamId, search, archived, ownerId, updatedById, createdFrom, createdTo, updatedFrom, updatedTo, unlinked) is active. `true` for a document that directly matched the filters; `false` for a node kept only as ancestor/descendant context around a match.
    - `children` KnowledgeTreeNode[]: Nested nodes, present up to the requested `depth`. When a filter is active, this is pruned to matches plus their ancestors/descendants within the tree rather than every child.

## Other responses

- `400`: Invalid input — an unparseable date, `to` not after `from`, or `unlinked=true` combined with `aptletUuid`/`aptletInstanceId`/`streamId`.
- `401`: Invalid or missing API key.

---

[API](https://skmtc.dev/getaptly/apis/aptly-api.md) - [All operations](https://skmtc.dev/getaptly/apis/aptly-api/llms.txt) - [OpenAPI document](https://skmtc.dev/getaptly/apis/aptly-api/revisions/75c367e0b8e5?raw)
