> ## 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](https://docs.frontic.com/api-builder/trees.md) - a hierarchical collection of records assembled from a [Data Storage](https://docs.frontic.com/data-integration/data-storages.md) using `parentKey` and `position` defaults, with each node rendered through a [Detail Block](https://docs.frontic.com/api-builder/blocks.md).

## Path Parameters

**project-token** `string` *required*

Your project's Fetch token, embedded in the subdomain.

**slug** `string` *required*

The tree's slug, e.g. `<tree-slug>`. Per project - see your tree's detail view in the API Builder.

## Query Parameters

**key** `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).

**depth** `integer`

Optional level limit. Controls how many levels of `$items` are included. Without it, all levels are returned (subject to the 1,250-node cap).

## Headers

See [Headers](https://docs.frontic.com/reference/fetch-api.md#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.

**items** `array` *required*

The tree's top-level nodes.

**Node properties**

**key** `string` *required*

The node's identifier, taken from the storage record's primary field.

**\$items** `array` *required*

Child nodes, same shape as the parent. Empty on leaves.

**...** `any`

Other fields come from the tree's [Detail Block](https://docs.frontic.com/api-builder/blocks.md) - they vary per project. The example shown uses a block with `name` and a [Route field](https://docs.frontic.com/api-builder/blocks.md#route) called `link`.

A single response is capped at **1,250 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.

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

```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": []
        }
      ]
    }
  ]
}
```

## Status codes

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.