# Assign a legal entity to an accounting book

Operation ID: `createBookEntityAssignment`

Group: Accounting › Books

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

`POST /accounting/books/entity-assignments`

Retry-safe: A write that accepts Idempotency-Key: repeating a request with the same key replays the stored answer instead of executing twice.

Assigns a legal entity to an accounting book, with the chart of accounts, fiscal calendar and currency the entity uses in that book. An entity is assigned to a book at most once. An active entity needs all three properties, in this book and in every other book it is assigned to. Non-legal reporting entities cannot be assigned through this API.

Assigning a fiscal calendar creates the entity's accounting period statuses in the book. While multi-book is off, the currency also becomes the legal entity's currency.

An adjustment book holds only entities of its base book, with the same properties: send bookId and entityId only, and the three properties are copied from the entity's assignment to the base book. An entity that has posted to a full book cannot join another full book. In a consolidating book (an adjustment book copies consolidation from its base book), assign an entity's subsidiaries before the entity, and use a chart of accounts compatible with its parent's.

## 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`. |
| `Idempotency-Key` | header | string | no | An opaque caller-chosen string (1-255 characters) that makes this request safe to retry. Repeating the same key with an identical request body replays the original response instead of re-executing - but only once that original request succeeded; a failed attempt re-executes on retry. Repeating the key with a different body is answered with 422. A key still in flight is answered with 409 - as is a key whose original request was interrupted before it finished, for a few minutes afterwards, until that attempt is presumed dead. A completed response stays replayable for 24 hours. The key is scoped to the caller, not to the action: reusing it for a different action is answered with 409 or 422 rather than treated independently. On read actions this header is ignored. On write actions that cannot offer the guarantee it is answered with `400 IDEMPOTENCY_NOT_SUPPORTED` rather than silently ignored. |

## Request body

Required, `application/json`: createBookEntityAssignmentInput.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `bookId` | string | yes | The accounting book to assign the legal entity to. See id on GET accounting/books/:id. Example: `"3f2a9c14-6d0b-4b8e-9f1a-2c7d5e8b9a10"`. |
| `entityId` | string | yes | The legal entity to assign. Must be a legal entity: non-legal reporting entities are refused. See id on GET base/entities. Example: `"6f9a2b1c-1d2e-4f3a-8b9c-0d1e2f3a4b5c"`. |
| `chartOfAccountsId` | string | no | The chart of accounts the entity uses in this book. Required when the entity is active. Rejected for an adjustment book, which copies it from the base book. See id on GET accounting/chart-of-accounts/:id. Example: `"a1c4d7e0-2b3c-4d5e-8f9a-1b2c3d4e5f60"`. |
| `fiscalCalendarId` | string | no | The fiscal calendar the entity uses in this book. Required when the entity is active. Rejected for an adjustment book, which copies it from the base book. See id on GET accounting/fiscal-calendars/:id. Example: `"c0ffee00-1234-4abc-9def-0123456789ab"`. |
| `currency` | string | no | The currency the entity uses in this book. Format ISO 4217, for example 'USD'. Required when the entity is active. Rejected for an adjustment book, which copies it from the base book. Example: `"EUR"`. |

```json
{
  "bookId": "3f2a9c14-6d0b-4b8e-9f1a-2c7d5e8b9a10",
  "entityId": "6f9a2b1c-1d2e-4f3a-8b9c-0d1e2f3a4b5c"
}
```

## Response

`200` Success

Under `data` (createBookEntityAssignmentOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes | The unique identifier for the created entity assignment. Example: `"9b8a7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d"`. |

```json
{
  "data": {
    "id": "9b8a7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d"
  },
  "diagnostics": [
    {
      "code": "<code>",
      "message": "<message>",
      "severity": "error",
      "path": [
        "<path>"
      ],
      "details": "<details>"
    }
  ]
}
```

## Response headers

- `Idempotency-Replayed` — Present and `true` only when this response replays a previously stored one for the same Idempotency-Key, rather than reflecting a live execution. Absent on a live response - never sent as `false`.

## Errors

| Code | Status |
| --- | --- |
| `REFERENCE_NOT_FOUND` | 400 |
| `INVALID_FIELD_VALUE` | 400 |
| `FIELD_REQUIRED` | 400 |
| `FIELD_NOT_ALLOWED` | 400 |
| `DUPLICATE_ASSIGNMENT` | 400 |
| `ENTITY_HAS_TRANSACTIONS` | 400 |
| `ENTITY_HIERARCHY_INCOMPLETE` | 400 |
| `ASSIGNMENT_INCOMPLETE` | 400 |
| `CHART_OF_ACCOUNTS_INCOMPATIBLE` | 400 |
| `ENTITY_NOT_IN_BASE_BOOK` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

- `400` — Invalid request or business failure. Codes: REFERENCE_NOT_FOUND, INVALID_FIELD_VALUE, FIELD_REQUIRED, FIELD_NOT_ALLOWED, DUPLICATE_ASSIGNMENT, ENTITY_HAS_TRANSACTIONS, ENTITY_HIERARCHY_INCOMPLETE, ASSIGNMENT_INCOMPLETE, CHART_OF_ACCOUNTS_INCOMPATIBLE, ENTITY_NOT_IN_BASE_BOOK
- `401` — The request carries no valid access token.
- `403` — Not authorized
- `404` — Not found
- `409` — The Idempotency-Key is still being processed by another request.
- `422` — The Idempotency-Key was already used with a different request payload.
- `429` — Too many requests from this client address. The response has no body and no `Retry-After` header.
- `500` — Internal server error
