# Create an account

Operation ID: `createAccount`

Group: Accounting › Accounts

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

`POST /accounting/accounts`

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

Creates one account in a chart of accounts and returns its id. Read the stored account with GET accounting/accounts/:id: the server derives the account number under hierarchical numbering, the exchange-rate type, and the stored revaluation mode.

A bank or credit-card account needs entityId and currency, and a new cash account is created for it. A grouping account takes no sub-type, entity, currency or revaluation mode. Fields that do not apply are rejected with FIELD_NOT_ALLOWED.

An account that breaks an accounting rule the server enforces, for example a bank account for a legal entity whose book has no currency, fails with VALIDATION_FAILED, with the rule's message in reason and, where known, the rule's name in rule. Every request must carry the Api-Version header: a missing or empty header, or one naming no API version, is answered 400; a route that exists but not in the requested version is answered 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`: createAccountInput.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `accountNumber` | string | no | The account number, unique within its chart of accounts. Required when the chart of accounts uses manual numbering. Not allowed when it uses hierarchical numbering, where the number is derived from the parent account. |
| `accountName` | string | yes | The display name of the account. Example: `"Operating Bank USD"`. |
| `accountType` | string | yes | The top-level classification of the account. Accepted values: 'asset', 'liability', 'equity', 'income', 'costOfGoodsSold', 'expense', 'otherIncome', 'otherExpense'. Example: `"asset"`. |
| `accountSubType` | string | no | A finer classification within accountType, for posting accounts only. Accepted values per accountType: 'bank', 'accountsReceivable', 'fixedAsset', 'cip', 'prepaidExpenses', 'deferredExpenses', 'otherCurrentAsset', 'otherAsset', 'unbilledReceivable', 'longTermAsset' (asset); 'accountsPayable', 'creditCard', 'deferredRevenue', 'otherCurrentLiability', 'longTermLiability' (liability); 'equity', 'otherComprehensiveIncome' (equity); and the sub-type named like the type for 'income', 'costOfGoodsSold', 'expense', 'otherIncome' and 'otherExpense'. Required for posting accounts. 'bank' and 'creditCard' require entityId and currency. Example: `"bank"`. |
| `description` | string | no | A free-form description of the account. |
| `chartOfAccountsId` | string | yes | The chart of accounts the account belongs to. See id on GET accounting/chart-of-accounts/:id. Example: `"5c1f0e2a-7b3d-4e8a-9f61-2d4b8c0a7e13"`. |
| `parentAccountId` | string | no | The grouping account this account rolls up to. It must already exist and be a grouping account in the same chart of accounts with the same accountType. Required for a posting account when the chart of accounts uses hierarchical numbering. Omit for a top-level account. See id on GET accounting/accounts/:id. Example: `"a8e2c4d1-3f5b-4a7c-8e9d-1b2c3d4e5f60"`. |
| `groupingAccount` | boolean | no | Whether this is a grouping (rollup) account. Defaults to false. A grouping account takes no accountSubType, entityId, currency or revaluationMode. Cannot be changed later. Example: `false`. |
| `entityId` | string | no | The legal entity a bank or credit-card account is denominated for. Required for, and only allowed on, 'bank' and 'creditCard' accounts. The entity must be assigned to the chart of accounts. See id on GET base/entities. Example: `"0f9e8d7c-6b5a-4c3d-9e2f-1a0b9c8d7e6f"`. |
| `currency` | string | no | The account's currency. Format ISO 4217, for example 'USD'. Required for, and only allowed on, 'bank' and 'creditCard' accounts. Example: `"USD"`. |
| `payOnBehalf` | boolean | no | Whether this account takes part in pay-on-behalf accounting. Defaults to false. true is only allowed on 'bank' and 'creditCard' accounts of a legal entity that has subsidiaries or a parent entity. |
| `elimination` | boolean | no | Whether this account is eliminated during consolidation. Defaults to false. true is not allowed on grouping, 'bank' or 'creditCard' accounts. |
| `revaluationMode` | string | no | Which revaluation results this account recognizes. Accepted values: 'recognizeAll' (both unrealized gains and unrealized losses), 'recognizeAllButUnrealizedGains' (only unrealized losses), 'none' (the account is not revalued). Posting accounts only. Omit to take the default the server derives. Which modes an account can take depends on its sub-type, on a bank or credit-card account's currency against its book's currency, and on the accounting standard of the chart's book; a mode the account cannot take is rejected with INVALID_FIELD_VALUE, whose allowedValues lists the modes it can take, never replaced. Example: `"recognizeAll"`. |
| `accountStatus` | string | no | The account's status, posting accounts only. Accepted values: 'enabled', 'disabled'. Defaults to 'enabled'. A grouping account accepts only 'enabled', the status it reads back with. |
| `externalIdentifiers` | array<object> | no | External identifiers owned by other systems, at most one per fieldName. Each fieldName must match an active account external-identifier configuration. GET accounting/account-external-identifier-fields lists them. Example: `[{"fieldName":"netsuiteAccountId","value":"1010","externalUrl":"https://example.app.netsuite.com/app/accounting/account/account.nl?id=1010"}]`. |
| `externalIdentifiers[].fieldName` | string | yes | The configured key of the external identifier, a camelCase slug such as 'netsuiteAccountId'. GET accounting/account-external-identifier-fields lists the accepted keys. |
| `externalIdentifiers[].value` | string | yes | The identifier as the source system holds it. |
| `externalIdentifiers[].externalUrl` | string | no | An absolute http(s) link to the object in the source system. Anything else is rejected with INVALID_FIELD_VALUE. |

```json
{
  "accountName": "Operating Bank USD",
  "accountType": "asset",
  "chartOfAccountsId": "5c1f0e2a-7b3d-4e8a-9f61-2d4b8c0a7e13"
}
```

## Response

`200` Success

Under `data` (createAccountOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes | The identifier of the created account. Example: `"7d3c2b1a-9e8f-4d6c-b5a4-3e2f1d0c9b8a"`. |

```json
{
  "data": {
    "id": "7d3c2b1a-9e8f-4d6c-b5a4-3e2f1d0c9b8a"
  },
  "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_ACCOUNT_NUMBER` | 400 |
| `INVALID_PARENT_ACCOUNT` | 400 |
| `TOP_LEVEL_ACCOUNT_TYPE_IN_USE` | 400 |
| `ENTITY_NOT_IN_CHART_OF_ACCOUNTS` | 400 |
| `UNKNOWN_EXTERNAL_IDENTIFIER` | 400 |
| `DUPLICATE_EXTERNAL_IDENTIFIER` | 400 |
| `VALIDATION_FAILED` | 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_ACCOUNT_NUMBER, INVALID_PARENT_ACCOUNT, TOP_LEVEL_ACCOUNT_TYPE_IN_USE, ENTITY_NOT_IN_CHART_OF_ACCOUNTS, UNKNOWN_EXTERNAL_IDENTIFIER, DUPLICATE_EXTERNAL_IDENTIFIER, VALIDATION_FAILED
- `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
