# Create an entity

Operation ID: `createEntity`

Group: Accounting › Entities

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

`POST /base/entities`

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

Creates an entity. A new entity always starts with status 'created' and in no accounting book. To use it, assign it to at least one book on POST accounting/books/entity-assignments, complete each assignment, then activate it with PATCH base/entities/:id { status: 'active', startDate }.

Hierarchy: once any entity exists, every new legal entity needs parentEntityId, so the legal hierarchy has exactly one top-level entity. A non-legal reporting entity is always top-level: it is created without a parent, also while other entities exist, and parentEntityId sent with it fails with FIELD_NOT_ALLOWED. A legal entity may name a non-legal reporting entity as its parent. A child cannot start before its parent.

The response is the new entity's id. Read the stored record, including its system-assigned entityNumber, with GET base/entities/:id.

Optional text fields sent as an empty string are treated as omitted. Every call sends the Api-Version header: a missing or empty header, or an unknown version, answers 400; a route the requested version does not contain answers 404.

## 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`: createEntityInput.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `entityName` | string | yes | The name of the entity. At most 120 characters; must be unique within the tenant. Example: `"Acme GmbH"`. |
| `entityType` | string | no | Whether the entity is a legal entity or a non-legal reporting entity. Defaults to 'LegalEntity'. Cannot be changed later. A non-legal reporting entity is always a top-level entity: it has no parent, so send it without parentEntityId (also when other entities exist). It may be the parent of legal entities. One of: `"LegalEntity"`, `"NonLegalReportingEntity"`. |
| `parentEntityId` | string | no | The parent entity in the hierarchy. For a legal entity: required once any entity exists; omit it only for the first, top-level entity. Any existing entity may be the parent, including a non-legal reporting entity. For a non-legal reporting entity: not accepted (FIELD_NOT_ALLOWED), since it is always top-level. See id on GET base/entities/:id. Example: `"9f2c6a10-7d34-4c8e-9b21-5a0f3e6d81b7"`. |
| `currency` | string | no | The entity's functional currency. Format ISO 4217, for example 'USD'. A code outside the supported currencies fails with INVALID_FIELD_VALUE. Entity-only: it is not copied to any book assignment. Example: `"EUR"`. |
| `timeZone` | string | no | The time zone the entity operates in. Format IANA time-zone name, for example 'Europe/Berlin'. Defaults to 'Etc/UTC'. An unknown zone fails with INVALID_FIELD_VALUE. Example: `"Europe/Berlin"`. |
| `country` | string | no | The country the entity is registered in. Format ISO 3166-1 alpha-2, for example 'US'. An unknown code fails with INVALID_FIELD_VALUE. Example: `"DE"`. |
| `entityCode` | string | no | A short code for the entity, separate from its entityNumber. |
| `localeCode` | string | no | The locale for documents sent from this entity. Format BCP 47, for example 'en-US'. A locale the tenant does not offer fails with INVALID_FIELD_VALUE. |
| `startDate` | date | no | The date the entity becomes effective. Format YYYY-MM-DD. Cannot be before the parent's start date. Required later to activate the entity. |
| `registeredAddress` | object | no | The entity's registered address. Example: `{"line1":"Friedrichstrasse 68","city":"Berlin","country":"DE","zipCode":"10117"}`. |
| `registeredAddress.line1` | string | yes | The first address line: street number and name, or PO box. |
| `registeredAddress.line2` | string | no | The second address line: apartment, suite, unit, building, or floor. |
| `registeredAddress.city` | string | yes | The city or locality. |
| `registeredAddress.stateProvince` | string | no | The state, province, or region. |
| `registeredAddress.country` | string | yes | The country of the address. Format ISO 3166-1 alpha-2, for example 'US'. An unknown code fails with INVALID_FIELD_VALUE. |
| `registeredAddress.zipCode` | string | yes | The postal or ZIP code. |
| `externalIdentifiers` | array<object> | no | External identifiers owned by other systems. At most one entry per fieldName, and each fieldName must be configured. List the configured fieldNames on GET base/entity-external-identifier-fields; any other fails with UNKNOWN_EXTERNAL_IDENTIFIER. Example: `[{"fieldName":"netsuiteSubsidiaryId","value":"12"}]`. |
| `externalIdentifiers[].fieldName` | string | yes | The configured key of the external identifier, a camelCase slug such as 'netsuiteSubsidiaryId'. |
| `externalIdentifiers[].value` | string | yes | The identifier as the source system holds it. Cannot be empty. |
| `externalIdentifiers[].externalUrl` | string | no | An absolute http(s) link to the object in the source system. Anything else fails with INVALID_FIELD_VALUE. |

```json
{
  "entityName": "Acme GmbH"
}
```

## Response

`200` Success

Under `data` (createEntityOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes | The unique identifier of the created entity. Example: `"3b7d5e9c-1a24-4f80-9c6d-2e8f70b13a45"`. |

```json
{
  "data": {
    "id": "3b7d5e9c-1a24-4f80-9c6d-2e8f70b13a45"
  },
  "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 |
| --- | --- |
| `PARENT_ENTITY_NOT_FOUND` | 400 |
| `FIELD_REQUIRED` | 400 |
| `FIELD_NOT_ALLOWED` | 400 |
| `FIELD_TOO_LONG` | 400 |
| `INVALID_FIELD_VALUE` | 400 |
| `DUPLICATE_ENTITY_NAME` | 400 |
| `DATE_CONFLICT` | 400 |
| `UNKNOWN_EXTERNAL_IDENTIFIER` | 400 |
| `DUPLICATE_EXTERNAL_IDENTIFIER` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

- `400` — Invalid request or business failure. Codes: PARENT_ENTITY_NOT_FOUND, FIELD_REQUIRED, FIELD_NOT_ALLOWED, FIELD_TOO_LONG, INVALID_FIELD_VALUE, DUPLICATE_ENTITY_NAME, DATE_CONFLICT, UNKNOWN_EXTERNAL_IDENTIFIER, DUPLICATE_EXTERNAL_IDENTIFIER
- `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
