# Create Value Object

Operation ID: `createValueObject`

Group: Value Accounting › Value Objects

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

`POST /value-accounting/value-objects`

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

Create the value object that stands for one or more master-data records, with its mappings, or resolve the one that exists. WRITES, in ONE transaction. mappings is required and names each record as {dimensionCode, id}; at least one (MAPPING_REQUIRED), the same record twice with the same dates counts once (with different dates it is DUPLICATE_MAPPING_ROW). ONE record: when it already has its own value object, that id is RETURNED — re-opened first if it was retired, but only while the record is ACTIVE and the reactivate screens pass, otherwise refused with VALUE_OBJECT_RETIRED; kept active (its end date cleared) when it ends TODAY — a custom value object's shadow ending today is kept as it stands while the custom value object ends today too — refused with ONE_TO_ONE_EXISTS when that clear would duplicate another value object's open one-to-one link — and name, objectNumber, categoryId and the mapping dates are IGNORED, so the call is safe to repeat and never duplicates or renames; otherwise — also when the value object the record's link moved away from now stands for another record, which is left untouched — a new 1:1 value object is created, ending with the record it stands for: on the record's end date when it has one of today or later (its mapping with it); a record that has already ENDED is refused with RECORD_INACTIVE, and a startDate after the record's end with END_BEFORE_START. SEVERAL records: a new CLUSTER value object is always created, numbered VO-n. A record has at most one open one-to-one value object: a NEW value object that stands for one record alone on some day from today on — one record sent, or several of which only one is open that day (the others start later or already ended, judged on the mappings' startDate/endDate) — is refused with ONE_TO_ONE_EXISTS when another value object holds that record's open one-to-one link on that day; several records open on the same days claim nothing. Returns only the id; read the stored form with getValueObject (GET value-accounting/value-objects/:id). Refusals, all before the first write: NAME_REQUIRED (blank name), UNSUPPORTED_DIMENSION_CODE / RECORD_NOT_FOUND (a record that does not resolve), CATEGORY_NOT_FOUND, OBJECT_NUMBER_TAKEN (the objectNumber SENT for a new 1:1 value object is already used — an omitted number never is: the record's own business number gives way to a generated VO-n when another value object holds it, so the new value object's number can differ from the record's; also answered, the call rolled back, when a concurrent create takes the number between the check and the write), VALUE_OBJECT_RETIRED (the record's own value object is retired and this call does not re-open it), RECORD_INACTIVE / END_BEFORE_START (a new 1:1 value object for a record that has ended, or starting after its end), ONE_TO_ONE_EXISTS (checked last; also re-judged after the write, rolling the call back). Making a master-data record known to value accounting this way makes it count as in use, so the record can afterwards be deactivated but no longer hard-deleted.

Creates the value object that stands for one or more master-data records, with its mappings, and returns only its `id`.

A value object always represents master data, so `mappings` is required and must name at least one record (`MAPPING_REQUIRED` otherwise); each record is the pair {dimensionCode, id} the associations resource speaks, and the same record sent twice with the same dates counts once — sent twice with different dates it is refused with `DUPLICATE_MAPPING_ROW` (one entry per record; a second link period is a later PATCH).

RESOLVE-OR-CREATE for ONE record. When the record already has its own (non-cluster) value object, that value object's id is RETURNED and nothing is duplicated — re-opened first when it or its mapping was retired, but only while the record is ACTIVE and the reactivate screens pass — re-opened up to the record's own end date when the record ends today or later (it never outlives the record), with no end date when the record has none; a record whose end date is BEFORE today has ended and is not active; a retired value object this call will not re-open is refused with `VALUE_OBJECT_RETIRED` (details.reason says why) and nothing is written — re-open it on purpose with reactivateValueObjects (POST value-accounting/value-objects/reactivate). One whose end date is TODAY (still active) is KEPT ACTIVE: its end date is cleared — or moved to the record's own end date when the record ends later, and left as it is when the record ends today too, and for a custom value object's shadow ending today while its custom value object ends today too (the value is the record: its end of today is kept, a create never undoes a deactivation; a shadow behind a custom value object ending LATER is brought up to that end, one whose custom value object has no end is cleared) — the mappings ending with it following — refused with `ONE_TO_ONE_EXISTS` when that clear would duplicate another value object's open one-to-one link; a FUTURE end date is kept. The `name`, `objectNumber`, `categoryId` and mapping dates of the request are then IGNORED: this call never renames or re-files an existing value object (updateValueObject (PATCH value-accounting/value-objects/:id) does). This is what makes the call safe to repeat. A value object the record's link moved away from, which now stands for another record, is not its own: a new 1:1 value object is created and that one is left untouched.

A CLUSTER for more than one record: a new value object is always created and its number is always a generated `VO-n` — calling twice with the same set creates two clusters.

A record has at most one OPEN one-to-one value object. A NEW value object — for one record, or for several of which only one is open on some day from today on (the others start later or have already ended, judged on the mappings' own startDate and endDate) — stands for that record alone on those days, and is refused with `ONE_TO_ONE_EXISTS` when another value object already holds the record's open one-to-one link on one of them; details name that value object, its mapping and the shared days. Several records open on the same days claim nothing. End the other link first, or date the mappings so that more than one record is open on every day. The claim is re-judged after the write, in the same transaction: a link another request wrote in between fails the call with the same code and rolls it back.

The number of a new 1:1 value object is `objectNumber` when sent, the record's own business number (a department's code, a customer's number) when omitted and the record has one, and a generated `VO-n` when omitted without one or sent as null. Every check runs before the first write.

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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | yes | Display name — normally the record's own name, or a descriptive name for a cluster. Required and must not be empty or whitespace only (NAME_REQUIRED), judged even when an existing value object is returned and the name is then ignored. Stored exactly as sent, untrimmed. Names are NOT unique. A 1:1 value object named exactly as the system names the record's mirror is recognised as that mirror (isSystemManaged) and its name, dates, category and mappings then follow the record. Example: `"Sales"`. |
| `startDate` | date | yes | First day the value object is valid, inclusive. Format YYYY-MM-DD. Required. Ignored when an existing value object is returned. Example: `"2026-01-01"`. |
| `objectNumber` | string \| null | no | Business number of a NEW 1:1 value object, unique tenant-wide (OBJECT_NUMBER_TAKEN otherwise). Omit it to take the record's own business number (a department's code, a customer's number) when the record has one and no value object holds it yet, and a generated VO-n otherwise — when the record has none, or another value object already holds it (business numbers are unique only within their dimension; the value object that the record's link moved away from, for one) — so the new value object's number can differ from the record's; send null, or an empty string, to always generate VO-n. A number you send is written as sent, never replaced. Ignored for a cluster, which is always numbered VO-n, and when an existing value object is returned. A generated number is one above the highest numeric VO- number (VO-<digits>; other VO- numbers are ignored) that no value object holds — not gap-free. |
| `categoryId` | string | no | Id (a UUID) of the category to file a NEW value object under, as listed by the categories data-set (GET value-accounting/categories). Omit to leave it uncategorised. An id that names no category is rejected with CATEGORY_NOT_FOUND and nothing is written — also when an existing value object would be returned, which then keeps its own category. Matched case-insensitively. |
| `mappings` | array<object> | yes | The master-data records the value object stands for — a plain array of full mappings (the update edits them with createMappings / updateMappings / deleteMappings). At least one (MAPPING_REQUIRED). Entries naming the same record with the same dates are collapsed, the first kept; the same record with different dates is refused with DUPLICATE_MAPPING_ROW. ONE distinct record = a 1:1 value object with resolve-or-create semantics; MORE than one = a new cluster — which still stands for a record ALONE on the days only that record's mapping is open, and is then refused with ONE_TO_ONE_EXISTS when another value object holds that record's open one-to-one link. Example: `[{"record":{"dimensionCode":"department","id":"0f1e4b9a-6a71-4a2c-8a0d-2f9c5d3b7e10"}}]`. |
| `mappings[].record` | object | yes | The master-data record, as the pair ensureRelationship (POST value-accounting/associations) takes. Both halves are required, because a UUID is unique within its dimension but not across dimensions. |
| `mappings[].record.dimensionCode` | string | yes | Dimension the record belongs to. One of 'department', 'businessUnit', 'team', 'location', 'region', 'employee', 'vendor', 'customer', 'valueCenter', 'custom' ('custom' being a custom value object, which already has its own value object — the call then returns it). An unknown code raises UNSUPPORTED_DIMENSION_CODE. |
| `mappings[].record.id` | string | yes | Id (a UUID) of the master-data record — the same value resolveReportingTags (POST base/reporting-tags/resolve) returns as modelUuid. An id that resolves to no record of that dimension raises RECORD_NOT_FOUND; a record is never created implicitly. Inactive records resolve. Matched case-insensitively. |
| `mappings[].startDate` | date | no | First day the mapping is valid, inclusive. Format YYYY-MM-DD. Defaults to TODAY, or to the value object's startDate when that is later; send the day the relationship really began when it began earlier — never before the value object's startDate (MAPPING_STARTS_BEFORE_OWNER, judged also when an existing value object is returned). Otherwise ignored when an existing value object is returned. |
| `mappings[].endDate` | date | no | Last day the mapping is valid, inclusive. Format YYYY-MM-DD. Omit for an open-ended mapping, the normal case. Ignored when an existing value object is returned. |

```json
{
  "name": "Sales",
  "startDate": "2026-01-01",
  "mappings": [
    {
      "record": {
        "dimensionCode": "department",
        "id": "0f1e4b9a-6a71-4a2c-8a0d-2f9c5d3b7e10"
      }
    }
  ]
}
```

## Response

`200` Success

Under `data` (createValueObjectOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | yes | Id (a UUID) of the value object that now stands for the records — newly created, or the existing 1:1 value object that was returned (re-opened when it had been retired; a retired one this call does not re-open is VALUE_OBJECT_RETIRED instead). This is the whole of the response; it is what getValueObject, updateValueObject and deleteValueObject (GET, PATCH and DELETE value-accounting/value-objects/:id) are keyed by. |

```json
{
  "data": {
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
  },
  "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 |
| --- | --- |
| `MAPPING_REQUIRED` | 400 |
| `NAME_REQUIRED` | 400 |
| `UNSUPPORTED_DIMENSION_CODE` | 400 |
| `RECORD_NOT_FOUND` | 400 |
| `DUPLICATE_MAPPING_ROW` | 400 |
| `INVALID_DATE_RANGE` | 400 |
| `MAPPING_STARTS_BEFORE_OWNER` | 400 |
| `CATEGORY_NOT_FOUND` | 400 |
| `OBJECT_NUMBER_TAKEN` | 400 |
| `VALUE_OBJECT_RETIRED` | 400 |
| `RECORD_INACTIVE` | 400 |
| `END_BEFORE_START` | 400 |
| `ONE_TO_ONE_EXISTS` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

- `400` — Invalid request or business failure. Codes: MAPPING_REQUIRED, NAME_REQUIRED, UNSUPPORTED_DIMENSION_CODE, RECORD_NOT_FOUND, DUPLICATE_MAPPING_ROW, INVALID_DATE_RANGE, MAPPING_STARTS_BEFORE_OWNER, CATEGORY_NOT_FOUND, OBJECT_NUMBER_TAKEN, VALUE_OBJECT_RETIRED, RECORD_INACTIVE, END_BEFORE_START, ONE_TO_ONE_EXISTS
- `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
