# Delete Value Object

Operation ID: `deleteValueObject`

Group: Value Accounting › Value Objects

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

`DELETE /value-accounting/value-objects/{id}`

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

Delete one value object with its mappings, DEACTIVATE it when it is still in use, or SKIP it when it is a custom value object's shadow — and report which happened. WRITES. An unused value object is hard-deleted with its mappings — DESTRUCTIVE, no undo. A value object the system created as a side effect — for a record that had none, when it was tagged or recorded as a business driver member — is deleted the same way: `isSystemManaged: true` locks its name and mappings against edits, not against this delete. One in use — allocation lines point at it, one of its records is referenced as a tag, or related to other master data, or a relationship is anchored on or points at the value object itself (a cluster included) — is kept and end-dated to today (or to its own startDate, when that is later) with every mapping still open (a mapping that would only start after that day is deleted); one that already ended keeps its own end date and is reported 'deactivated' again, and its mappings still open end on that same day. A custom value object's shadow is left untouched and named by its owner: delete it through deleteCustomValueObject (DELETE value-accounting/custom-value-objects/:id). All three are a success with HTTP 200: read outcome ('deleted', 'deactivated' or 'skipped'), reason, and for a skipped shadow customValueObjectId. Re-open a deactivated value object with reactivateValueObjects (POST value-accounting/value-objects/reactivate). It cannot be re-opened while another value object holds an open one-to-one link to the record it stood for (ONE_TO_ONE_EXISTS): end that link first. An unknown id is rejected with NOT_FOUND and nothing is written. For several value objects in one call use bulkDeleteValueObjects (POST value-accounting/value-objects/bulk-delete).

Deletes one value object with its mappings — or, when it is still in use, DEACTIVATES it instead — and reports which of the two happened.

A value object that is not in use is hard-deleted together with its mappings; there is no undo. A value object the system created as a side effect — for a record that had none, when it was tagged or recorded as a business driver member — is deleted the same way: `isSystemManaged: true` locks its name and mappings against edits, not against this delete. A value object that IS in use is kept: it and every one of its mappings still open are end-dated to today (or to its own startDate, when that is later), which retires it once that day has passed — a mapping that would only start after that day is deleted instead and listed in deletedMappingIds — while every posting made against it keeps resolving. A value object that already ended keeps its own end date and is reported deactivated again; its mappings still open end on that same day, so reactivating re-opens them with it. In use means any of: allocation lines point at it, one of its records is referenced as a tag (business driver combinations included), or one of its records is related to other master data through the associations resource, or a relationship is stored against the value object itself — anchored on it or pointing at it — whatever record it stands for today (a cluster included). Both outcomes are a success (HTTP 200); read `outcome`, and `reason` for why a value object was kept.

A custom value object's SHADOW — the value object a custom value object carries for allocations — is not this resource's to delete: the value, its shadow and their mapping are deleted or retired together through deleteCustomValueObject (DELETE value-accounting/custom-value-objects/:id). It comes back as outcome `skipped` with the owning `customValueObjectId`, and nothing is written.

A deactivated value object can be re-opened with reactivateValueObjects (POST value-accounting/value-objects/reactivate). It cannot be re-opened while another value object holds an open one-to-one link to the record it stood for (ONE_TO_ONE_EXISTS): end that link first. One kept only by relationships becomes deletable once they are removed with removeRelationship (POST value-accounting/associations/remove). An unknown id fails with `NOT_FOUND` and nothing is written.

## 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. |
| `id` | path | string | yes | Id (a UUID) of the value object to delete; bound from the :id path segment. An id that matches no value object is rejected with NOT_FOUND rather than treated as an already-completed delete. Ids are matched case-insensitively and returned in canonical lowercase. |

## Response

`200` Success

Under `data` (deleteValueObjectOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `outcome` | string | yes | What happened: 'deleted' — it was not in use and is gone with its mappings, so its id no longer resolves; 'deactivated' — it is in use, so it and every mapping still open were end-dated to today, or to its own startDate when that is later (a mapping that had already ended keeps its date, so reactivating re-opens exactly these; one that would only start after that day was deleted — deletedMappingIds) and its id still resolves (the end date is inclusive, so it reads status 'active' for the rest of that day and 'inactive' from the next); one that already ended keeps its own end date and is reported 'deactivated' again, and its mappings still open end on that same day; 'skipped' — it is a custom value object's shadow, so nothing was written; address customValueObjectId instead. One of: `"deleted"`, `"deactivated"`, `"skipped"`. |
| `reason` | string | no | Why the value object was kept, as a sentence. For 'deactivated' the first that applies: allocation lines point at it, one of its records is referenced as a tag (business drivers), or it is part of master-data relationships (the only one a caller can clear: remove them with removeRelationship (POST value-accounting/associations/remove), then delete again; the sentence names the application-API action for the same removal). For 'skipped', which custom value object owns the shadow and the route that deletes it. Absent for 'deleted'. |
| `deletedMappingIds` | array<string> | no | Present only on 'deactivated' when the deactivation DELETED mappings: ids (UUIDs) of the value object's mappings that would only have started after the day it ends on (today, its own start when it has not started yet, or the end it already had). Such a mapping is never in effect inside the value object's life, so it is deleted rather than ended before its own start; none is left canceled. These ids no longer resolve. The reason sentence only counts them (it names no id); this field is the contract. |
| `customValueObjectId` | string | no | Id (a UUID) of the custom value object that owns this shadow — the record to send to deleteCustomValueObject (DELETE value-accounting/custom-value-objects/:id). Present exactly when outcome is 'skipped'. |

```json
{
  "data": {
    "outcome": "deleted",
    "reason": "<reason>",
    "deletedMappingIds": [
      "<deletedMappingIds>"
    ],
    "customValueObjectId": "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 |
| --- | --- |
| `NOT_FOUND` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

- `400` — Invalid request or business failure. Codes: NOT_FOUND
- `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
