> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.lucanto.eu/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.lucanto.eu/_mcp/server.

# Undo a settlement

POST https://app.lucanto.eu/api/v1/workspaces/{workspace_id}/transactions/{id}/unpair
Content-Type: application/json

Removes the link and re-derives the affected record's payment status.
Without `allocation_id` every allocation on the transaction is removed.
The transaction itself is kept — use DELETE to remove it.

Also undoes a [`pair_with_transaction`](#operation/pairTransactionWithTransaction)
refund link when the transaction has no allocations: if it is linked
to another transaction via `paired_transaction_id`, that link is
undone instead (clearing `paired_transaction_id` on whichever side(s)
carried it).

This only covers a genuine refund pair. `paired_transaction_id` is
also how the ATM and internal-transfer auto-pairers link a real
transaction to a counterpart leg the app invented for it — unpairing
that from here would destroy the invented leg outright, so if either
side of the link is such an invented row, this is refused with 422
instead; undo it from the web.


Reference: https://docs.lucanto.eu/api-reference/api-reference/transactions/unpair-transaction

## Authentication

- `Authorization` header (bearer token, required) — JWT issued via POST /api/v1/auth/sign_in. Used by mobile and SPA clients. Revoked tokens are rejected.
- `Authorization` header (bearer token, required) — Lucanto API key. Two prefixes: * `lct_pat_<random><checksum>` — personal access token (owner: User) * `lct_live_<random><checksum>` — workspace token, live data Issue keys at `/settings/api_keys` (personal) or `/:workspace_id/settings/api_keys` (workspace). Plaintext token is shown once and never again.

## Request

### Path parameters

- `workspace_id` (long, required) — Workspace ID. The numeric ID shown in your URLs.
- `id` (ResourceId, required) — Transaction ID. Either the numeric `id` or the `public_id` (`txn_…`).

### Headers

- `Idempotency-Key` (string, optional) — Client-supplied unique key (recommended: UUID v4) for safe retries. Within 24 hours, repeating the same key with the same request (method, path, query, body) replays the original response instead of re-executing the action — once the action has run, a 5xx included; a request stopped before it ran is not stored. Reusing a key with a different request returns `422 idempotency_key_conflict` (IETF draft §2.7).

### Body (application/json)

This endpoint expects an object.

- `allocation_id` (long, optional) — Remove only this allocation. Omit to remove all of them.

## Response

### 200

Unpaired. Returns the updated transaction.

- `id` (long, required)
- `public_id` (string, required) — Stable public identifier of this record. Never changes once assigned. Its prefix names the entity: `doc_` document (invoice, proforma, credit note, quote, sales order), `exp_` expense, `cnt_` contact, `prj_` project, `ba_` bank account or cash register, `txn_` transaction, `lon_` loan, `bst_` bank statement. Accepted in place of the numeric `id` in this resource's path parameters and in request fields that reference it (`customer_id`, `bank_account_id`, …).
- `amount` (string, required) — Signed amount as a precision-preserving decimal string. Positive = credit (money in), negative = debit (money out).
- `direction` (enum, required) — Derived from the sign of `amount`. Zero is treated as `credit`.
  - Allowed values: `credit`, `debit`
- `matching_status` (string, required) — Matching / classification status. `unmatched`, `matched`, `manually_matched`, `no_match_found`, or an auto-classified bucket (`bank_fee`, `tax_fee`, `loan_principal`, `salary`, `internal_transfer`, `atm_withdrawal`, …).
- `synced_from_bank` (boolean, required) — `true` when imported from the bank via PSD2 sync; `false` for manually recorded transactions.
- `bank_account_id` (long, required) — ID of the owning bank account / cash register.
- `created_at` (datetime, required)
- `updated_at` (datetime, required)
- `currency` (string, optional, nullable) — ISO-4217 currency code (uppercased).
- `description` (string, optional, nullable) — Free-text description / narrative for the movement.
- `display_name` (string, optional, nullable) — Ready-to-render label for the other side of the movement: the counterparty name (payer on money in, payee on money out), falling back to the bank's trading-party identification and then to its additional info. Prefer this over `creditor_name`/`debtor_name` for display — on a card payment both of those are empty and the merchant is only in the trading-party identification. Best effort, not a guaranteed name: the last fallback is the bank's free-text narrative, so a row the bank named nobody on can render as e.g. `GP NÁKUP POS`. Null only when the bank sent none of the three.
- `variable_symbol` (string, optional, nullable) — SK/CZ payment matching symbol (variabilný symbol).
- `constant_symbol` (string, optional, nullable) — SK/CZ constant symbol (konštantný symbol).
- `specific_symbol` (string, optional, nullable) — SK/CZ specific symbol (špecifický symbol).
- `payment_reference` (string, optional, nullable) — End-to-end / structured payment reference.
- `remittance_info` (string, optional, nullable) — Unstructured remittance information from the bank.
- `creditor_name` (string, optional, nullable) — Name of the credited party (payee).
- `creditor_iban` (string, optional, nullable) — IBAN of the credited party.
- `debtor_name` (string, optional, nullable) — Name of the debited party (payer).
- `debtor_iban` (string, optional, nullable) — IBAN of the debited party.
- `booking_date` (date, optional, nullable) — Date the bank booked the transaction.
- `value_date` (date, optional, nullable) — Value date (when funds are effective).
- `paid_on` (date, optional, nullable) — Payment date — primary date for manually recorded (cash) transactions.
- `classification_subtype` (string, optional, nullable) — Finer-grained auto-classification bucket, when classified.
- `classification_detail` (string, optional, nullable) — Additional detail for the classification (e.g. a specific fee/tax label).
- `statement_imported` (boolean, optional) — `true` when the row was imported from an uploaded bank statement (PDF/CSV): bank data, but without a bank transaction id. Such rows may be corrected when the statement was misread; rows the bank delivered itself are locked.
- `correctable` (boolean, optional) — A property of the row: whether it is the kind of transaction a correction (`lucanto_correct_transaction`) applies to. Identical to `statement_imported` today. The caller's role still applies — correcting needs `transactions:manage`.
- `corrections` (list of TransactionCorrectionsItems, optional) — Correction history, oldest first — present on `GET /transactions/{id}` and `lucanto_get_transaction` only; the list and the pairing responses (pair, unpair, pair\_with\_transaction) omit it. Each entry records who corrected the row, when, why, through which surface and what changed.
- `payment_method` (string, optional, nullable) — Payment method (e.g. `cash`, `transfer`, `card`), when known.
- `pairable` (TransactionPairable, optional, nullable) — What this transaction settles, when it is paired. `matching_status` tells you a transaction is matched but not to what — this says which record, so you can tell whether a row is load-bearing for a document's payment state before acting on it. Null when unpaired.
- `bank_account` (TransactionBankAccount, optional, nullable) — Slim embed of the owning payment account (routing/identity fields only — no balances).

## Errors

### 401 Unauthorized Error

Missing or invalid authentication credentials.

- `error` (string, required) — Machine-readable error code. Stable across releases — clients should branch on this rather than the human-readable message.
- `message` (string, required) — Human-readable error description, localized to `Accept-Language`. Subject to wording changes between releases.
- `request_id` (string, required) — Server-side request identifier. Same value as the `X-Request-Id` response header. Quote this in support tickets so we can pull the matching server log line.
- `docs_url` (string, required) — URL of the per-error-code documentation page. Useful for SDK error subclasses to deep-link from a stack trace to the docs explaining the cause + remediation.

### 403 Forbidden Error

Authenticated, but the token's scope or the user's role does not permit this action. Both the token scope and the user's role must allow the action. Also returned when a workspace token is sent to an endpoint that acts for a user (`/user`, `/user/workspaces`, devices, notification preferences, diagnostics): a workspace token has no user behind it, so use a personal access token or a JWT there.

- `error` (string, required) — Machine-readable error code. Stable across releases — clients should branch on this rather than the human-readable message.
- `message` (string, required) — Human-readable error description, localized to `Accept-Language`. Subject to wording changes between releases.
- `request_id` (string, required) — Server-side request identifier. Same value as the `X-Request-Id` response header. Quote this in support tickets so we can pull the matching server log line.
- `docs_url` (string, required) — URL of the per-error-code documentation page. Useful for SDK error subclasses to deep-link from a stack trace to the docs explaining the cause + remediation.

### 404 Not Found Error

No such allocation on this transaction.

- `error` (string, required) — Machine-readable error code. Stable across releases — clients should branch on this rather than the human-readable message.
- `message` (string, required) — Human-readable error description, localized to `Accept-Language`. Subject to wording changes between releases.
- `request_id` (string, required) — Server-side request identifier. Same value as the `X-Request-Id` response header. Quote this in support tickets so we can pull the matching server log line.
- `docs_url` (string, required) — URL of the per-error-code documentation page. Useful for SDK error subclasses to deep-link from a stack trace to the docs explaining the cause + remediation.

### 409 Conflict Error

A request with this `Idempotency-Key` is still being processed. Retry shortly with the same key. Status per IETF draft-ietf-httpapi-idempotency-key-header §2.7.

- `error` (string, required) — Machine-readable error code. Stable across releases — clients should branch on this rather than the human-readable message.
- `message` (string, required) — Human-readable error description, localized to `Accept-Language`. Subject to wording changes between releases.
- `request_id` (string, required) — Server-side request identifier. Same value as the `X-Request-Id` response header. Quote this in support tickets so we can pull the matching server log line.
- `docs_url` (string, required) — URL of the per-error-code documentation page. Useful for SDK error subclasses to deep-link from a stack trace to the docs explaining the cause + remediation.

### 422 Unprocessable Entity Error

Either the transaction has no allocations and no `paired_transaction_id` link (not paired to anything), or the `paired_transaction_id` link it has involves a transaction the app invented (an ATM or internal-transfer counterpart) — undo that from the web instead.

- `error` (string, required) — Machine-readable error code. Stable across releases — clients should branch on this rather than the human-readable message.
- `message` (string, required) — Human-readable error description, localized to `Accept-Language`. Subject to wording changes between releases.
- `request_id` (string, required) — Server-side request identifier. Same value as the `X-Request-Id` response header. Quote this in support tickets so we can pull the matching server log line.
- `docs_url` (string, required) — URL of the per-error-code documentation page. Useful for SDK error subclasses to deep-link from a stack trace to the docs explaining the cause + remediation.

### 429 Too Many Requests Error

Rate limit exceeded. Retry after the window resets.

- `error` (string, required) — Machine-readable error code. Stable across releases — clients should branch on this rather than the human-readable message.
- `message` (string, required) — Human-readable error description, localized to `Accept-Language`. Subject to wording changes between releases.
- `request_id` (string, required) — Server-side request identifier. Same value as the `X-Request-Id` response header. Quote this in support tickets so we can pull the matching server log line.
- `docs_url` (string, required) — URL of the per-error-code documentation page. Useful for SDK error subclasses to deep-link from a stack trace to the docs explaining the cause + remediation.

## Types

### ResourceId

The record's numeric `id` or its `public_id` (`doc_01h455vb4pex5vsknk084sn02q`). The bare UUID form of the `public_id` is still accepted but deprecated.

- long
- string
- string

### TransactionCorrectionsItems

- `id` (long, required)
- `reason` (string, required) — Free text given by the corrector.
- `origin` (enum, required)
  - Allowed values: `web`, `api`, `mcp`
- `occurred_at` (datetime, required)
- `field_changes` (map from string to TransactionCorrectionsItemsFieldChanges, required) — Old → new per corrected field (`amount`, `booking_date`, `value_date`, `variable_symbol`, `constant_symbol`, `specific_symbol`, `counterparty_name`, `counterparty_iban`, and `counterparty_side` when the sign flipped). Values are decimal/ISO-8601 strings or null.
- `user` (TransactionCorrectionsItemsUser, optional, nullable) — The member who corrected the row; null for a workspace token or a deleted user.

### TransactionPairable

What this transaction settles, when it is paired. `matching_status` tells you a transaction is matched but not to what — this says which record, so you can tell whether a row is load-bearing for a document's payment state before acting on it. Null when unpaired.

- `type` (enum, optional) — The paired record's class.
  - Allowed values: `Expense`, `Document`
- `id` (long, optional)

### TransactionBankAccount

Slim embed of the owning payment account (routing/identity fields only — no balances).

- `id` (long, required)
- `name` (string, optional, nullable)
- `iban` (string, optional, nullable)
- `currency` (string, optional, nullable) — ISO-4217 currency code (uppercased).
- `account_type` (enum, optional) — `bank` — bank account; `cash` — cash register.
  - Allowed values: `bank`, `cash`

### TransactionCorrectionsItemsFieldChanges

- `from` (string, optional, nullable)
- `to` (string, optional, nullable)

### TransactionCorrectionsItemsUser

The member who corrected the row; null for a workspace token or a deleted user.

- `id` (long, optional)
- `name` (string, optional, nullable) — The member's name; null when they have not set one (never the e-mail).

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "id": 1,
  "public_id": "doc_01h455vb4pex5vsknk084sn02q",
  "amount": "-149.90",
  "direction": "credit",
  "matching_status": "unmatched",
  "synced_from_bank": true,
  "bank_account_id": 1,
  "created_at": "2024-01-15T09:30:00Z",
  "updated_at": "2024-01-15T09:30:00Z",
  "currency": "EUR",
  "description": "string",
  "display_name": "OMV 9999",
  "variable_symbol": "string",
  "constant_symbol": "string",
  "specific_symbol": "string",
  "payment_reference": "string",
  "remittance_info": "string",
  "creditor_name": "string",
  "creditor_iban": "string",
  "debtor_name": "string",
  "debtor_iban": "string",
  "booking_date": "2023-01-15",
  "value_date": "2023-01-15",
  "paid_on": "2023-01-15",
  "classification_subtype": "string",
  "classification_detail": "string",
  "statement_imported": true,
  "correctable": true,
  "corrections": [
    {
      "id": 1,
      "reason": "string",
      "origin": "web",
      "occurred_at": "2024-01-15T09:30:00Z",
      "field_changes": {
        "amount": {
          "from": "-18.0",
          "to": "-180.0"
        }
      },
      "user": {
        "id": 1,
        "name": "string"
      }
    }
  ],
  "payment_method": "string",
  "pairable": {
    "type": "Expense",
    "id": 1
  },
  "bank_account": {
    "id": 1,
    "name": "string",
    "iban": "string",
    "currency": "string",
    "account_type": "bank"
  }
}
```

**SDK Code**

```python
import requests

url = "https://app.lucanto.eu/api/v1/workspaces/42/transactions/1/unpair"

payload = {}
headers = {
    "Idempotency-Key": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.lucanto.eu/api/v1/workspaces/42/transactions/1/unpair';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://app.lucanto.eu/api/v1/workspaces/42/transactions/1/unpair"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://app.lucanto.eu/api/v1/workspaces/42/transactions/1/unpair")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://app.lucanto.eu/api/v1/workspaces/42/transactions/1/unpair")
  .header("Idempotency-Key", "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.lucanto.eu/api/v1/workspaces/42/transactions/1/unpair', [
  'body' => '{}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://app.lucanto.eu/api/v1/workspaces/42/transactions/1/unpair");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Idempotency-Key": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://app.lucanto.eu/api/v1/workspaces/42/transactions/1/unpair")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```