# HTTP API

> Every kontod route with the roles that may call it, the problem format of errors, status codes and the OpenAPI document.

kontod speaks JSON over HTTP. Every `/v1` route acts for the creditor of the bearer token,
or of the signed-in customer's session, and admits only the roles listed. The machine-readable contract is
[openapi.json](/openapi.json), also served by kontod at `GET /openapi.json`; a test keeps
it, and this page, equal to the router.

## Routes

| Route | Roles | Does |
|---|---|---|
| `GET /health` | none | liveness |
| `GET /openapi.json` | none | the OpenAPI document |
| `POST /v1/charges` | producer, clerk | deliver `rated-charge@1` documents for an account |
| `POST /v1/sections` | producer, clerk | deliver bill sections |
| `POST /v1/bills/preview` | producer, clerk | preview an explicit bill request |
| `GET /v1/bills/{number}` | clerk, portal, customer | a sealed bill with konto's verdict |
| `GET /v1/bills/{number}/document` | clerk, portal, customer | the sealed bill as the stack's `bill@1` document |
| `POST /v1/accounts/{account}/erasure` | clerk | erase the account's personal data that no law requires konto to keep; answers the `erasure@1` to emit |
| `GET /v1/erasures/{id}` | clerk | an erasure and the engines' confirmations |
| `POST /v1/erasures/{id}/confirmations` | producer, clerk | an engine confirms it erased its copies |
| `GET /v1/bills/{number}/xrechnung` | clerk, courier, portal, customer | the XRechnung, `?syntax=cii` (default) or `ubl` |
| `GET /v1/bills/{number}/html` | clerk, portal, customer | the German HTML bill |
| `GET /v1/bills/{number}/pdf` | clerk, courier, portal, customer | the PDF with the e-invoice embedded |
| `GET /v1/deliveries` | clerk, courier | deliveries by `?status=pending` (default), `sent` or `failed` |
| `POST /v1/deliveries/{number}/sent` | clerk, courier | report a delivery sent, with the courier's reference |
| `POST /v1/deliveries/{number}/failed` | clerk, courier | report a delivery failed, with a reason |
| `POST /v1/deliveries/{number}/requeue` | clerk | send a failed delivery again, by post if asked |
| `POST /v1/payments` | clerk | book a received payment |
| `GET /v1/accounts/{account}/charges` | clerk | the account's open charges (the inbox) |
| `PUT /v1/accounts/{account}/holder` | clerk | the buyer bills are addressed to; e-mail address, channel and mandate stay |
| `GET /v1/accounts/{account}/overview` | clerk, portal, customer | the account screen: open, last bill with change, Verlauf |
| `GET /v1/accounts/{account}/statement` | clerk, portal, customer | the Kontoauszug |
| `GET /v1/accounts/{account}/items` | clerk, portal, customer | the open items |
| `POST /v1/accounts/{account}/bills/preview` | clerk | preview the next bill from the inbox |
| `POST /v1/accounts/{account}/bills/review` | clerk | review the next bill: its number and the review |
| `POST /v1/accounts/{account}/bills/confirm` | clerk | seal, book, take the charges and queue the delivery |
| `POST /v1/accounts/{account}/allocations/review` | clerk | review a payment's allocation |
| `POST /v1/accounts/{account}/allocations/confirm` | clerk | confirm it |
| `POST /v1/accounts/{account}/collections/assess` | clerk | assess the account's claims against the contracts' terms |
| `POST /v1/accounts/{account}/invitations` | clerk | invite the account's holder; the code is shown once |
| `GET /v1/accounts/{account}/access` | clerk | who may read the account, with their passkeys, provider logins and pending invitations |
| `DELETE /v1/accounts/{account}/access/{id}` | clerk | revoke a grant or end a pending invitation |
| `DELETE /v1/passkeys/{id}` | clerk | remove a passkey (a lost device) and end its sessions |
| `DELETE /v1/identities/{id}` | clerk | remove a provider login's link and end its sessions |
| `GET /v1/accounts/{account}/settings` | clerk, customer (holder) | how the holder pays and receives bills; the mandate text; the changes (clerk) |
| `PUT /v1/accounts/{account}/payment` | clerk, customer (holder) | grant a SEPA direct debit mandate, or switch to transfer |
| `PUT /v1/accounts/{account}/delivery` | clerk, customer (holder) | bills by e-mail with consent, or by post |
| `GET /v1/signin` | none | which ways of signing in are on, and the provider's name |
| `POST /v1/signin` | none | start a passkey sign-in |
| `POST /v1/signin/finish` | none | finish it; sets the session cookie |
| `POST /v1/signin/register` | none | start setting up a passkey with an invitation |
| `POST /v1/signin/register/finish` | none | finish it; starts the grant and a session |
| `POST /v1/signin/oidc` | none | start a sign-in at the operator's provider; answers its address |
| `GET /v1/signin/oidc/callback` | the provider's redirect | finish it and go back to the portal |
| `POST /v1/signout` | customer | end the session; answers the provider's logout address for a provider session |
| `GET /v1/me` | customer | the signed-in person and their accounts at every creditor, with what is open and how it is paid |
| `POST /v1/me/invitations` | customer | add another invitation's account, of any creditor of the sign-in, to the signed-in person |
| `GET /v1/me/delegations` | customer (holder) | who else may read the accounts the person holds, at every creditor |
| `POST /v1/me/delegations` | customer (holder) | share an account read-only until a date |
| `DELETE /v1/me/delegations/{id}` | customer (holder) | revoke a delegation |

A `customer` is a session from [customer sign-in](sign-in.md): it reaches only the
accounts of its current grants, and its calls that change something must come from the
sign-in origin. A session with accounts at [several companies](several-creditors.md)
names one with `?creditor=` on account and bill routes.

## Requests

- Bodies are JSON; an unknown field is refused and named.
- Money is a decimal string (`"27.71"`); a JSON number for money is refused.
- Dates are `YYYY-MM-DD`; periods are half-open (`end` is the first day after).
- The request body is at most 16 MiB.

## Errors

Errors are `application/problem+json` documents [RFC 9457]:

```json
{
  "type": "urn:konto:refusal:stale_evidence",
  "title": "Neu prüfen und erneut bestätigen: Seit der Prüfung hat sich eine Eingabe geändert.",
  "status": 409,
  "detail": "Seit der Prüfung haben sich Positionen oder Abschnitte geändert; bitte neu prüfen."
}
```

`type` carries a stable code, `title` says what to do and `detail` what is wrong, both in
German. [Refusal codes](refusals.md) lists every code.

| Status | When |
|---|---|
| 400 | a body that is not JSON |
| 401 | no or unknown token, without a body; `not_signed_in` or `signin_failed` for a customer |
| 403 | the body names another creditor, the role may not use the route, or a customer call from another origin |
| 404 | an unknown bill or delivery, a payment with nothing open, or an account or bill outside a customer's grants |
| 409 | a stale or used review, a number that is not the next one, a charge reference delivered with other content, a delivery already reported otherwise |
| 413 | a body or a delivery above its limit |
| 422 | an invalid field, or any other refusal |
| 503 | stored commands do not replay to their recorded state, or customer sign-in is not available |

Another creditor's account or bill answers exactly like one that does not exist.
