# PATCH /api/v1/transactions/{transaction_id}/split

> Split a transaction across categories

- **Tag:** transactions
- **Operation ID:** `split_transaction`

## Description

Rebuild a transaction's journal entry so its single category leg becomes multiple category legs (e.g. 70% COGS / 30% Sales Tax). Allocations may be percentages, fixed amounts, or a remainder line; the resulting legs always balance against the bank leg.

## Authentication

Bearer token in `Authorization` header.
Required header: `x-business-id: <business uuid>`.

## Parameters

- `transaction_id` (path, string, required)

## Request body

Schema: `TransactionSplitRequest`

- `split` (array · SplitAllocation · required) → `SplitAllocation` — Category allocations (at least 2 lines).
  - `ledger_id` (string · required) — Category ledger for this leg
  - `allocation_type` (SplitAllocationType · required) → `SplitAllocationType` — percent | amount | remainder
  - `value` (integer) — Basis points for 'percent' (70% == 7000), cents for 'amount', ignored/None for 'remainder'.
  - `description` (string) — Optional per-line memo
  - `class_id` (string) — Optional Class dimension
  - `location_id` (string) — Optional Location dimension
  - `project_id` (string) — Optional Project for job costing
  - `counterparty_name` (string) — Optional counterparty of this leg when it is not the transaction's own, e.g. one employee's share of a payroll debit that the bank shows as 'Gusto'. Omit to inherit the transaction's counterparty.
  - `employee_id` (string) — Optional employee this leg pays. When set without counterparty_name, the employee's display name becomes the leg's counterparty.

## Example request

```json
{
  "split": [
    {
      "allocation_type": "percent",
      "ledger_id": "019ab37c-1ed6-7000-8000-000000000001",
      "value": 7000
    },
    {
      "allocation_type": "remainder",
      "ledger_id": "019ab37c-1ed6-7000-8000-000000000002"
    }
  ]
}
```

## Responses

### 200 — Successful Response

Schema: `SuccessEnvelope_TransactionListResponse_`

- `success` (boolean)
- `message` (string)
- `code` (string)
- `data` (TransactionListResponse)

### 400 — Bad Request - Invalid input

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 401 — Unauthorized - Missing or expired token, an MCP OAuth token used against the REST API, or no access to this business

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 403 — Forbidden - Insufficient permissions

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 404 — Not Found - Resource does not exist

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

### 422 — Validation Error

Schema: `ErrorResponse`

- `error` (string · required) — Error category: `validation_error`, `unauthorized`, `forbidden`, `not_found`, `conflict`, `rate_limited`, `server_error`, or `service_unavailable`.
- `message` (string · required) — Human-readable explanation, safe to show to end users.
- `code` (string · required) — Stable machine-readable code in `CATEGORY_NNN` form (e.g. `NOT_FOUND_006`, `AUTH_010`, `GEN_002`).
- `request_id` (string) — Correlation id for support requests. Echoes the `x-request-id` request header when one was supplied.
- `errors` (object) — Field-level validation messages keyed by field name. Present on 400/422 validation failures only.

## Code samples

### cURL

```bash
curl -X PATCH 'https://api.ondayzero.com/api/v1/transactions/{transaction_id}/split' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "split": [
    {
      "allocation_type": "percent",
      "ledger_id": "019ab37c-1ed6-7000-8000-000000000001",
      "value": 7000
    },
    {
      "allocation_type": "remainder",
      "ledger_id": "019ab37c-1ed6-7000-8000-000000000002"
    }
  ]
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/transactions/{transaction_id}/split', {
  method: 'PATCH',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "split": [
    {
      "allocation_type": "percent",
      "ledger_id": "019ab37c-1ed6-7000-8000-000000000001",
      "value": 7000
    },
    {
      "allocation_type": "remainder",
      "ledger_id": "019ab37c-1ed6-7000-8000-000000000002"
    }
  ]
}),
});
const data = await response.json();
```

### Python

```python
import httpx

headers = {
    "Authorization": "Bearer dz_your_token",
    "x-business-id": "YOUR_BUSINESS_ID",
}

payload = {'split': [{'allocation_type': 'percent',
            'ledger_id': '019ab37c-1ed6-7000-8000-000000000001',
            'value': 7000},
           {'allocation_type': 'remainder',
            'ledger_id': '019ab37c-1ed6-7000-8000-000000000002'}]}

response = httpx.patch("https://api.ondayzero.com/api/v1/transactions/{transaction_id}/split", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/transactions/split-transaction
- OpenAPI slice: https://www.ondayzero.com/docs/reference/transactions/split-transaction/openapi.json
- Other endpoints in **transactions**: https://www.ondayzero.com/docs/reference/transactions (markdown bundle: https://www.ondayzero.com/docs/reference/transactions.md, OpenAPI: https://www.ondayzero.com/docs/reference/transactions/openapi.json)
- Endpoint catalog: https://www.ondayzero.com/docs/reference/index.md
