# Get Value Center Hierarchy

Operation ID: `getValueCenterHierarchy`

Group: Value Accounting › Value Centers

[Open in the interactive reference](https://lensing.ai/api-docs/lensing/v1/endpoints/getValueCenterHierarchy)

`GET /value-accounting/value-centers/{id}/hierarchy`

Read-only: Reads and returns; changes nothing.

Walk the value center tree from one value center: direction=descendants returns every value center BELOW it down to the leaves, direction=ancestors every value center ABOVE it up to the root. Read-only. Each row is {id, name, parentId, depth}, depth 1 being a direct child or the direct parent; the value center in the path is not part of the answer, so a leaf's descendants and a root's ancestors are an empty items array. Every id is a value center id. Unfiltered and unpaged — a filter would narrow the tree walk itself rather than its rows, and silently drop rows that are there. For one level only, getValueCenter (GET value-accounting/value-centers/:id) carries the direct children and the parent. An id that matches nothing is rejected with NOT_FOUND, a direction that is neither of the two with INVALID_DIRECTION.

Walks the value center tree from the value center in the path, in the direction the `direction` query parameter names, and returns every value center on the way.

`direction=descendants` returns everything BELOW the value center — its children, their children, and so on to the leaves. `direction=ancestors` returns everything ABOVE it — its parent, the parent's parent, and so on up to the root. The value center named in the path is never part of the answer: the caller already has it, and a leaf (descendants) or a root (ancestors) answers with an empty `items` array.

Each row names a value center by its id and name, its own parent's id and its `depth` — the number of levels between it and the value center in the path, 1 being a direct child (or the direct parent). Every id is a value center id, the one getValueCenter (GET value-accounting/value-centers/:id) is keyed by.

The walk takes no filter. It is a walk over the tree's own edges, and a filter applied to a subtree walk narrows the traversal rather than the rows it returns — a row demonstrably in the subtree would come back missing — so none is offered; filter the rows you receive, or narrow with searchValueCenters (POST value-accounting/value-centers/search). The whole tree is returned in one response, unpaged.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Api-Version` | header | string · v1 | yes | The API version this request targets, named by its public identifier. Required on every request; omitting it, or naming a version this company does not have, is answered with 400. This document describes version `v1`. |
| `id` | path | string | yes | Id (a UUID) of the value center to walk from; bound from the :id path segment. An id that matches no value center is rejected with NOT_FOUND. Ids are matched case-insensitively and returned in canonical lowercase. Example: `"6d2c8f31-b4a7-4e19-9f2b-77c0a1d4e5b2"`. |
| `direction` | query | string | yes | Which way to walk, as the direction query parameter: 'descendants' for everything below the value center (its subtree), 'ancestors' for everything above it (its chain of parents up to the root). Required, matched exactly (lowercase); any other value is rejected with INVALID_DIRECTION. Example: `"descendants"`. |

## Response

`200` Success

Under `data` (getValueCenterHierarchyOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `items` | array<object> | yes | The value centers on the walk, the value center in the path excluded. For descendants: level by level, nearest first, each level by name. For ancestors: the direct parent first, the root last. Empty for a leaf (descendants) or a root (ancestors). |
| `items[].id` | string | yes | Id (a UUID) of the value center — the id getValueCenter (GET value-accounting/value-centers/:id) is keyed by. |
| `items[].name` | string | yes | Display name of the value center. |
| `items[].parentId` | string | no | Id (a UUID) of this row's own direct parent. On a descendants walk it is always present — the value center in the path or another row. On an ancestors walk it is absent — not null — on the root, the last row. |
| `items[].depth` | number | yes | How many levels this value center is away from the value center in the path: 1 for a direct child (descendants) or the direct parent (ancestors), 2 for a grandchild or grandparent, and so on. |

```json
{
  "data": {
    "items": [
      {
        "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "name": "<name>",
        "parentId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
        "depth": 0
      }
    ]
  },
  "diagnostics": [
    {
      "code": "<code>",
      "message": "<message>",
      "severity": "error",
      "path": [
        "<path>"
      ],
      "details": "<details>"
    }
  ]
}
```

## Errors

| Code | Status |
| --- | --- |
| `INVALID_DIRECTION` | 400 |
| `NOT_FOUND` | 400 |

## Statuses

- `400` — Invalid request or business failure. Codes: INVALID_DIRECTION, NOT_FOUND
- `401` — The request carries no valid access token.
- `403` — Not authorized
- `404` — Not found
- `429` — Too many requests from this client address. The response has no body and no `Retry-After` header.
- `500` — Internal server error
