# POST /api/v1/transactions/bulk-upload/diff

> Compare a bank/card export with a ledger

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

## Description

Read-only. Compares an uploaded bank or credit-card export (CSV/Excel) with
the transactions one ledger already holds and reports which rows of the file
are missing from the ledger — the rows to upload.

Each file row is paired with at most one ledger transaction:

- **exact** — same amount, date and description;
- **strong** — same amount, dated within `date_tolerance_days` (default 3),
  and the descriptions share a word or the counterparty agrees (catches
  Plaid-synced and renamed rows);
- **ambiguous** (`amount_only`) — same amount within the window, nothing else
  agrees. Listed for review; never uploaded automatically.

Pairing is one-to-one, so two identical legitimate charges need two ledger
rows. Amounts are compared in cash-flow sign (negative = money out): a
credit-card file's positive charge matches the stored charge.

Upload the result with `POST /transactions/bulk-upload` and
`only_missing_from_diff: true` (re-runs this diff), or pass
`missing_row_numbers` (plus any ambiguous rows you checked) as
`include_row_numbers`.

## Authentication

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

## Request body

Schema: `LedgerDiffRequest`

- `s3_key` (string · required) — S3 key of the CSV/Excel export (from file upload or /bulk-upload/paste)
- `ledger_id` (string · required) — Ledger (bank account or credit card) to compare against
- `start_date` (string · date) — Only compare file rows on or after this date; also bounds the ledger rows reported missing from the file. Defaults to the file's first date.
- `end_date` (string · date) — Only compare file rows on or before this date. Defaults to the file's last date.
- `column_mapping` (object) — Mapping from DayZero field names to CSV headers: 'date', 'amount', 'description', optional 'category' and 'counterparty'. Auto-detected when omitted (see /bulk-upload/headers).
- `date_tolerance_days` (integer) — How many days a ledger date may differ from the file's and still match (bank vs posted date).
- `status_column` (string) — Header of the file's settled/pending column. Auto-detected (status, transaction_status, state, posting_status) when omitted.
- `exclude_statuses` (array · string) — File rows whose status is one of these (case-insensitive, e.g. ['Pending']) are left out of the comparison and listed separately.
- `invert_transaction_amounts` (boolean) — The file signs amounts the opposite way from usual (bank: deposits positive; credit card: charges positive).

## Responses

### 200 — Successful Response

Schema: `SuccessEnvelope_LedgerDiffResponse_`

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

### 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 POST 'https://api.ondayzero.com/api/v1/transactions/bulk-upload/diff' \
  -H 'Authorization: Bearer dz_your_token' \
  -H 'x-business-id: YOUR_BUSINESS_ID' \
  -H 'Content-Type: application/json' \
  -d '{
  "s3_key": "string",
  "ledger_id": "string"
}'
```

### JavaScript

```javascript
const response = await fetch('https://api.ondayzero.com/api/v1/transactions/bulk-upload/diff', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer dz_your_token',
    'x-business-id': 'YOUR_BUSINESS_ID',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "s3_key": "string",
  "ledger_id": "string"
}),
});
const data = await response.json();
```

### Python

```python
import httpx

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

payload = {'s3_key': 'string', 'ledger_id': 'string'}

response = httpx.post("https://api.ondayzero.com/api/v1/transactions/bulk-upload/diff", headers=headers, json=payload)
data = response.json()
```

## See also

- HTML version: https://www.ondayzero.com/docs/reference/transactions/ledger-diff-bulk-upload-export
- OpenAPI slice: https://www.ondayzero.com/docs/reference/transactions/ledger-diff-bulk-upload-export/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
