> ## Documentation Index
> Fetch the complete documentation index at: https://docs.frontic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch a Tree

Fetch a [Menu Tree](/api-builder/trees) — a hierarchical collection of records assembled from a [Data Storage](/data-integration/data-storages) using `parentKey` and `position` defaults, with each node rendered through a [Detail Block](/api-builder/blocks).

## Path Parameters

<ParamField path="project-token" type="string" required>
  Your project's Fetch token, embedded in the subdomain.
</ParamField>

<ParamField path="slug" type="string" required>
  The tree's slug, e.g. `<tree-slug>`. Per project — see your tree's detail view in the API Builder.
</ParamField>

## Query Parameters

<ParamField query="key" type="string">
  Optional starting node. When provided, `items` contains a single entry — the node with this key, plus its descendants. Without a key, `items` contains every root-level node (records with no parent).
</ParamField>

<ParamField query="depth" type="integer">
  Optional level limit. Controls how many levels of `$items` are included. Without it, all levels are returned (subject to the 1,000-node cap).
</ParamField>

## Headers

See [Headers](/reference/fetch-api#headers) on the overview for the full set. Trees honour `fs-context`, `fs-domain`, `fs-version`, and `fs-secret` (only when the project has fetch keys configured).

## Response

The response body wraps the tree in an `items` array. When called without a `key`, this array lists every root-level node (records with no parent); when called with one, it holds only the matching node — still wrapped in a list, for shape consistency with the unkeyed call. Each node's subtree is carried on its own `$items` field.

<ResponseField name="items" type="array" required>
  The tree's top-level nodes.

  <Expandable title="Node properties">
    <ParamField path="key" type="string" required>
      The node's identifier, taken from the storage record's primary field.
    </ParamField>

    <ParamField path="$items" type="array" required>
      Child nodes, same shape as the parent. Empty on leaves.
    </ParamField>

    <ParamField path="..." type="any">
      Other fields come from the tree's [Detail Block](/api-builder/blocks) — they vary per project. The example shown uses a block with `name` and a [Route field](/api-builder/blocks#route) called `link`.
    </ParamField>
  </Expandable>
</ResponseField>

A single response is capped at **1,000 nodes total**. When a level wouldn't fit within the budget, the entire level is omitted (partial levels are never returned) and a warning is included in the response header.

<RequestExample>
  ```bash curl theme={"theme":"css-variables"}
  curl 'https://fetch-<project-token>.frontic.com/tree/<tree-slug>?key=<starting-node>&depth=2' \
    -H 'fs-context: <context-key>'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 OK theme={"theme":"css-variables"}
  {
    "items": [
      {
        "key": "shop",
        "name": "Shop",
        "link": {
          "slug": "shop",
          "path": "/en/shop",
          "url": "<your-shop>/en/shop",
          "href": "https://<your-shop>/en/shop"
        },
        "$items": [
          {
            "key": "women",
            "name": "Women",
            "link": {
              "slug": "shop/women",
              "path": "/en/shop/women",
              "url": "<your-shop>/en/shop/women",
              "href": "https://<your-shop>/en/shop/women"
            },
            "$items": []
          }
        ]
      }
    ]
  }
  ```
</ResponseExample>

## Status codes

| Code  | When                                                                           |
| ----- | ------------------------------------------------------------------------------ |
| `200` | Tree (or subtree) returned                                                     |
| `401` | `fs-secret` missing or wrong (only when the project has fetch keys configured) |
| `403` | Project's plan limit for Fetch API requests exceeded                           |
| `404` | Tree slug doesn't exist, or `key` doesn't match a node                         |
