# The product hierarchy: the category tree, where each feature sits, and its latest grouping (/api/hierarchy/get_hierarchy)

`GET /v1/products/{productId}/hierarchy`

Operation name: `get_hierarchy`

Start here to see how a product is organised; to find a category, feature or topic by name, use `search` instead. A category holds either subcategories or features, never both (2 to 8 when the AI groups them). The read pages over one list: the categories depth-first (parents first; the top level by position, below it A to Z; `parentId` null at the top), then the features by category, A to Z, unplaced ones (`categoryId` null) last; follow `meta.nextCursor` until it is null. If the tree changes between pages, the next page answers 409 `conflict`: read again from the first page. `view: compact` answers ids, titles, places and each category's `featureCount` (features in it and below it). `view: full` (the default) adds descriptions, who set each value and positions (order added). Each feature carries its `source` documentation page. The full view also answers `build`: the latest grouping, after a knowledge base read or a rebuild: queued, completed or failed; it completes once its features are named in their categories, and `categoriesUnnamed` counts the categories whose features could not be named yet. `categoryId` reads only that category's branch: the category itself first, every category below it, and their features. `version` is a fingerprint of the tree, on every page: send it as `expectedVersion` with a change, so that a change planned from this read is refused if the tree changed since. To restructure, use `apply_hierarchy_changes`.

## Authentication

An OAuth access token for the person who allowed your tool: register a client, then the authorization code flow with PKCE (S256). Send it as `Authorization: Bearer <token>` on every route that needs a signed-in person. Calls with a token are limited per person, across all their apps, to 120 calls a minute and 10,000 a UTC day; calls that start AI runs or knowledge base reads (creating an organization, starting a knowledge base read, rebuilding categories, retrying topics or rechecking) also to 10 a minute and 200 a UTC day. Over a limit a call answers 429 `rate_limited` with `Retry-After` and `details.retryAfter` in seconds, and changes nothing.

Or: An API key, sent as `Authorization: Bearer ha_…` (keys made before the rename to Heuristic start `fsa_` and keep working). Keys are created only in the Heuristic web app and shown once. A personal key (Settings → Personal → My API keys) acts as its person in one of their organizations, with exactly their access there, checked on every call; its calls count toward the person's limits on calls through apps and agents, as described for OAuth tokens, and it can't change the person's account (their profile, organizations, invitations or connected apps). An organization key (Settings → Organization → API keys, created by Admins) acts for the organization, not a person: it can see and change every product and its feedback as an Admin can, but not people, product access, CRM connections or the organization's settings, and it can't delete a product; each organization key has its own limits, with the same numbers. Either kind is Full access or Read only (a change with a read-only key answers 403 `read_only_key`), reaches only its own organization (others answer 404), works on /v1 only, not on the MCP server, and can't create keys or manage the organization's API keys. Other refused calls answer 403 `api_key_not_allowed`. A wrong, expired or revoked key, or a disabled member's personal key, answers 401 `unauthorized`. A full-access key sends feedback: a personal key as its person, to the products they own; an organization key to any product of its organization; the record's `sentBy` names the key.

## Path parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `productId` | path | string | yes | A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`. |

## Query parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `view` | query | string | no | `compact`: ids, titles, places and feature counts. `full` (the default): every field. |
| `categoryId` | query | string | no | A Heuristic id: a uuid, in any case (it is read in lower case). Anything else answers 400 `validation_error`. |
| `limit` | query | integer | no | How many items a page holds, 1 to 1000 (50 in the full view, 300 in the compact view when left out). A larger page may be cut off by your client. |
| `cursor` | query | string | no | The previous page's `meta.nextCursor`, with the same `view` and `categoryId`; left out: the first page. |

## Responses

### 200

One page of the tree

```json
{
  "type": "object",
  "properties": {
    "data": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "categories": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "parentId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "title": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "origin": {
                    "type": "string",
                    "enum": [
                      "ai",
                      "user"
                    ]
                  },
                  "titleOrigin": {
                    "type": "string",
                    "enum": [
                      "ai",
                      "user"
                    ]
                  },
                  "descriptionOrigin": {
                    "type": "string",
                    "enum": [
                      "ai",
                      "user"
                    ]
                  },
                  "placementOrigin": {
                    "type": "string",
                    "enum": [
                      "ai",
                      "user"
                    ]
                  },
                  "position": {
                    "type": "integer"
                  }
                },
                "required": [
                  "id",
                  "parentId",
                  "title",
                  "description",
                  "origin",
                  "titleOrigin",
                  "descriptionOrigin",
                  "placementOrigin",
                  "position"
                ]
              }
            },
            "features": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "categoryId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "position": {
                    "type": "integer"
                  },
                  "source": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "properties": {
                      "pageId": {
                        "type": "string"
                      },
                      "url": {
                        "type": "string"
                      },
                      "title": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "removedAt": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    },
                    "required": [
                      "pageId",
                      "url",
                      "title",
                      "removedAt"
                    ]
                  },
                  "origin": {
                    "type": "string",
                    "enum": [
                      "ai",
                      "user"
                    ]
                  },
                  "titleOrigin": {
                    "type": "string",
                    "enum": [
                      "ai",
                      "user"
                    ]
                  },
                  "descriptionOrigin": {
                    "type": "string",
                    "enum": [
                      "ai",
                      "user"
                    ]
                  },
                  "categoryOrigin": {
                    "type": "string",
                    "enum": [
                      "ai",
                      "user"
                    ]
                  },
                  "addedByLatestRead": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "id",
                  "title",
                  "description",
                  "categoryId",
                  "position",
                  "source",
                  "origin",
                  "titleOrigin",
                  "descriptionOrigin",
                  "categoryOrigin",
                  "addedByLatestRead"
                ]
              }
            },
            "build": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "kind": {
                  "type": "string",
                  "enum": [
                    "run",
                    "rebuild"
                  ]
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "queued",
                    "completed",
                    "failed"
                  ]
                },
                "categoriesUnnamed": {
                  "type": "integer"
                },
                "failure": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "code",
                    "message"
                  ]
                },
                "createdAt": {
                  "type": "string"
                },
                "finishedAt": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "id",
                "kind",
                "status",
                "categoriesUnnamed",
                "failure",
                "createdAt",
                "finishedAt"
              ]
            },
            "edited": {
              "type": "boolean"
            },
            "rebuildAvailableAt": {
              "type": [
                "string",
                "null"
              ]
            },
            "version": {
              "type": "string"
            },
            "view": {
              "type": "string",
              "enum": [
                "full"
              ]
            }
          },
          "required": [
            "categories",
            "features",
            "build",
            "edited",
            "rebuildAvailableAt",
            "version",
            "view"
          ]
        },
        {
          "type": "object",
          "properties": {
            "view": {
              "type": "string",
              "enum": [
                "compact"
              ]
            },
            "categories": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "parentId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "title": {
                    "type": "string"
                  },
                  "featureCount": {
                    "type": "integer"
                  }
                },
                "required": [
                  "id",
                  "parentId",
                  "title",
                  "featureCount"
                ]
              }
            },
            "features": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "title": {
                    "type": "string"
                  },
                  "categoryId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "id",
                  "title",
                  "categoryId"
                ]
              }
            },
            "version": {
              "type": "string"
            }
          },
          "required": [
            "view",
            "categories",
            "features",
            "version"
          ]
        }
      ]
    },
    "meta": {
      "type": "object",
      "properties": {
        "nextCursor": {
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "nextCursor"
      ]
    }
  },
  "required": [
    "data",
    "meta"
  ]
}
```

### 400

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 401

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 404

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

### 409

Error

```json
{
  "type": "object",
  "properties": {
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {}
      },
      "required": [
        "code",
        "message"
      ]
    }
  },
  "required": [
    "error"
  ]
}
```

## Example request

```bash
curl "https://staging.heuristic.app/v1/products/{productId}/hierarchy" \
  -H "Authorization: Bearer <access token>"
```
