# Requests, answers and errors

The rules every endpoint follows.

## Base URL and format

- Base URL: `https://api.reconsmith.com`
- JSON in, JSON out, UTF-8.
- Field names are `snake_case`: `external_ref`, `amount_excl_tax`, `doc_date`.
- Path and query parameters are written as in the reference: `/v1/documents/{externalRef}/pdf?sourceSystem=shop`.

## Dates and amounts

- Dates are `YYYY-MM-DD` (`2026-12-01`). Moments are ISO 8601 with an offset (`2026-12-01T10:00:00+02:00`).
- Amounts are decimal numbers with two places: `1150.00`. Never cents as integers, never strings.
- Currency is ISO 4217 (`ZAR`, `EUR`). Left out, it is the company's own currency.
- A line sends its amount excluding VAT and its VAT separately (`amount_excl_tax`, `tax_amount`), as printed on the document. ReconSmiths does not recalculate your VAT; it checks the document balances.

## Your references

Everything you push carries your own id, `external_ref`, unique per `source_system`. `source_system` names your system (for example `shop`): send the same name on every call - `source_system` in a body, `sourceSystem` in a query - so your references are read as yours. Changing a document (void, notes) also accepts our document number (`INV-00042`) or our id.

## Idempotency: retry without fear

Writes that post or change documents and money require an `Idempotency-Key` header (the reference lists it on each one that does): any unique string up to 255 characters, typically a UUID made when you first try the request. A `PUT` that names its record (an employee, a period's hours) is safe to repeat without one.

| You send | You get |
|---|---|
| A new key | The request is carried out. |
| The same key and the same body again | The first answer again, word for word. Nothing is done twice. |
| The same key with a different body | `422`: the key was already used for something else. |
| The same key while the first is still running | `409`: wait and try again. |

Keep the key with the thing you are sending, and reuse it on every retry of that thing. Pushes are also matched on your `external_ref`: an invoice you already sent comes back with `created: false` rather than a second copy.

## Batches

Bulk endpoints (`/v1/parties`, `/v1/invoices`, `/v1/payments`, `/v1/allocations`, `/v1/credit-notes`, `/v1/purchase-invoices`) take a JSON array of up to 1 000 items. A batch is all or nothing: if one item is refused, nothing in it is posted, and the answer names the item.

## Answers

| Code | Means |
|---|---|
| `200` | Done (reads, and updates that change something in place). |
| `201` | Created. The body lists what was created, with our ids. |
| `400` | The request is malformed, or the `Idempotency-Key` is missing. |
| `401` | No key, or the key is unknown, switched off or expired. |
| `403` | The key lacks the permission (scope) this call needs. |
| `404` | Nothing matches the reference you gave. |
| `409` | Conflicts with the current state (already in flight, already posted, period closed). |
| `413` | More than 1 000 items in one call. |
| `422` | The ledger refused it. The reason is in the body. |
| `502`, `503` | A part behind the API (the document renderer) is unavailable. Try again. |

## Errors are written to be read

Every error is an RFC 9457 problem document:

```json
{
  "type": "about:blank",
  "title": "Unknown customer",
  "status": 422,
  "detail": "no party with external_ref 'CUST-1001'. Push it to /v1/parties first."
}
```

`title` is the short form, `detail` says what to do about it. Show `detail` to the person who can fix it.

## Paging

Lists take `limit` (default and maximum stated per endpoint). The change feed is cursor-paged: pass the `next_cursor` you were given as `since`, and stop when `has_more` is false. Cursors, not page numbers, because rows written while you read would shift a page and you would miss some.
