# Remove Relationship

Operation ID: `removeRelationship`

Group: Value Accounting › Master Data Associations

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

`POST /value-accounting/associations/remove`

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

Remove the relationship between two master-data records. WRITES and is DESTRUCTIVE — BOTH directed edges are deleted, whichever record created the relationship, and an association anchor left with no edges is cleaned up too. Symmetric: the argument order does not matter, and removing from one side also removes the other record's view of the relationship. Returns an empty body on success. Two records that are not related are rejected with NOT_FOUND rather than reported as a completed removal, so a caller can tell the two apart. It runs in one transaction: both edges are removed or neither is, and a rejected call writes nothing. Irreversible — re-create with ensureRelationship (POST value-accounting/associations), though which side was explicit is not remembered. A value object the tagging created for a record that had none is NOT removed with the relationship; to undo it too, delete it afterwards with deleteValueObject (DELETE value-accounting/value-objects/:id) — once nothing else uses it, it is hard-deleted, and `isSystemManaged: true` does not block the delete. This is also how a blocked master-data delete is unblocked: deleting a department, team, location or employee is refused while it still has a relationship a user made or took over, and a value object, value center or custom value object that still has any relationship is deactivated rather than deleted. POST rather than DELETE because a relationship has no id of its own — the pair of references identifying it travels in a request body, which a DELETE does not dependably deliver.

Removes the relationship between two master-data records ENTIRELY. Both directed edges are deleted — whichever record created the relationship — and an association anchor left holding no edges is cleaned up with them.

Symmetric: the argument order does not matter, and removing from one record's side also removes the other record's view of the relationship. That is the point of the two-edge model, not a side effect, but it does mean this call changes what a record the caller did not name reports.

Two records that are not related raise `NOT_FOUND`. It runs in one transaction: both edges are removed or neither is, and a rejected call writes nothing. Irreversible: re-create with ensureRelationship (POST value-accounting/associations), though which side was explicit is not remembered.

This is also how a delete is unblocked: deleting a department, team, location or employee is refused while a relationship a user made or took over remains, and this package's deletes DEACTIVATE a value object, value center or custom value object that still has any relationship instead of deleting it.

A value object the tagging created for a record that had none is NOT removed with the relationship. To undo it too, delete it afterwards with deleteValueObject (DELETE value-accounting/value-objects/:id): once nothing else uses it, it is hard-deleted — `isSystemManaged: true` locks its name and mappings against edits, not against the delete.

POST rather than DELETE: a relationship has no id of its own, so the pair of references that identifies it has to travel in a body, and a DELETE body is not dependably delivered.

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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `record` | object | yes | One end of the relationship, as the (dimensionCode, id) pair. Either order works — the relationship is removed whichever side created it. Example: `{"dimensionCode":"department","id":"9a5e1c77-3b2d-4f10-8c6e-1d40a7b93c58"}`. |
| `record.dimensionCode` | string | yes | Dimension the record belongs to. One of 'department', 'businessUnit', 'team', 'location', 'region', 'employee', 'vendor', 'customer', 'valueCenter', 'custom'. An unknown code raises UNSUPPORTED_DIMENSION_CODE. |
| `record.id` | string | yes | Id (a UUID) of the master-data record — the same value resolveReportingTags (POST base/reporting-tags/resolve) returns as modelUuid. Ids are matched case-insensitively and returned in canonical lowercase. |
| `relatedRecord` | object | yes | The other end of the relationship, as the same (dimensionCode, id) pair. Example: `{"dimensionCode":"valueCenter","id":"f91ecda5-2912-4624-b8b2-b6d28e1d64e1"}`. |
| `relatedRecord.dimensionCode` | string | yes | Dimension the related record belongs to. Same ten codes as `record.dimensionCode`. |
| `relatedRecord.id` | string | yes | Id (a UUID) of the related master-data record. Ids are matched case-insensitively and returned in canonical lowercase. |

```json
{
  "record": {
    "dimensionCode": "department",
    "id": "9a5e1c77-3b2d-4f10-8c6e-1d40a7b93c58"
  },
  "relatedRecord": {
    "dimensionCode": "valueCenter",
    "id": "f91ecda5-2912-4624-b8b2-b6d28e1d64e1"
  }
}
```

## Response

`200` Success

```json
{
  "data": {},
  "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 |
| --- | --- |
| `UNSUPPORTED_DIMENSION_CODE` | 400 |
| `RECORD_NOT_FOUND` | 400 |
| `NOT_FOUND` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

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