{
  "openapi": "3.0.0",
  "paths": {
    "/account/{accountId}/invoice": {
      "post": {
        "description": "Creates a document and returns it with its server-assigned `id` and number. Answers **200**, not 201. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.\n\nSend an `Idempotency-Key` header to make a retry safe: repeating the identical request with the same key within 24 h returns the invoice created the first time (header `Idempotent-Replayed: true`) instead of creating a second one. Keys are scoped to the account in the path. The same key with a different body answers 422 `idempotency_key_reuse`; while the first request is still running, 409 `idempotency_in_progress`.\n\nOmit `number` to let the server continue the account series. Omit `sender` to use the account's company profile.",
        "operationId": "invoice_create",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "description": "Optional client-generated key (8–128 characters of `A–Z a–z 0–9 _ - : .`, e.g. a UUID) identifying this create. Remembered for 24 h per account together with a hash of the request body; malformed keys answer 400 `idempotency_key_invalid`.",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9_\\-:.]{8,128}$",
              "example": "9f1c2b7e-5d4a-4e1b-a3c2-7b0e6f2d1a90"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InvoiceCreateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/InvoiceCreateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created document.",
            "headers": {
              "Idempotent-Replayed": {
                "description": "`true` when this answer is a replay of an earlier request with the same `Idempotency-Key` — the document returned is the one created then (in its current state); nothing new was created. Absent on a first execution.",
                "schema": {
                  "type": "string",
                  "enum": [
                    "true"
                  ]
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/InvoiceDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "idempotency_key_invalid",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.\n\n`idempotency_in_progress` means a request with the same `Idempotency-Key` has not finished — or died without a recorded outcome, in which case the key stays blocked until it expires (24 h) rather than risk a duplicate invoice. Verify with `GET …/invoice?number=` (when you sent a number) or the list, then use a fresh key.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number",
                            "idempotency_in_progress"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "422": {
            "description": "`idempotency_key_reuse`: this `Idempotency-Key` was already used in this account with a DIFFERENT request body (or attachments). Nothing is created. Reuse a key only to repeat the identical request.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "idempotency_key_reuse"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "503": {
            "description": "`idempotency_unavailable`: an `Idempotency-Key` was sent but the server cannot record it right now. Nothing is created (fail closed) — retry later with the same key.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "idempotency_unavailable"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Create an invoice",
        "tags": [
          "Invoices"
        ]
      },
      "get": {
        "description": "Returns one page of documents, newest first. `fields` (line items) are omitted from list rows — fetch a document by id to get them. Query parameters follow the description of each parameter below; the parameter names are `sortModel` and `filterModel`.\n\nWith `shortList=true` each row collapses to `{ id, number, sender, recipient, issueDate }` where `sender`/`recipient` are bare names — see `InvoiceShortListItemDto`. Default rows are `InvoiceListItemDto`: no `fields`, `totalPrice` as a number, plus `remaining`, `isOverdue` and `correctedByCreditNote`. Rows may also carry the computed sort keys `invoice_cost` and `creditnote_count`; ignore them. `tab` narrows to a derived tab and `number` looks one invoice up by its exact number.",
        "operationId": "invoice_list",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "page",
            "required": false,
            "in": "query",
            "description": "Zero-based page index. Ignored when `cursor` is supplied. A value that is not a non-negative integer is treated as absent, not as an error.",
            "schema": {
              "minimum": 0,
              "default": 0,
              "example": 0,
              "type": "number"
            }
          },
          {
            "name": "pageSize",
            "required": false,
            "in": "query",
            "description": "Items per page. A positive integer, maximum 500 (a larger value is rejected with 400). Anything that is not a positive integer is treated as absent and the default applies.",
            "schema": {
              "minimum": 1,
              "maximum": 500,
              "default": 10,
              "example": 50,
              "type": "number"
            }
          },
          {
            "name": "ids",
            "required": false,
            "in": "query",
            "description": "Fetch exactly these rows by id (integers). Overrides `search`, `filterModel`, `sortModel`, `page`/`pageSize` and `cursor`; the answer then carries `list` and `total` only (no `nextCursor`). Accepted on the wire as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a JSON array (`ids=[\"1\",\"2\"]`).",
            "schema": {
              "example": [
                "1042",
                "1043"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "addRelations",
            "required": false,
            "in": "query",
            "description": "Extra relations to join into each row. Only relations on the endpoint's server-side allowlist are accepted (on the public document lists that is the creator, already included); any other name answers 400 `invalid_request`. Integrators normally omit it.",
            "schema": {
              "example": [
                "client"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "sortModel",
            "required": false,
            "in": "query",
            "description": "Sort order as a URL-encoded JSON array of `{ field, direction }` (query parameter name is `sortModel`, not `sort`). `field` is a column of the row (a dotted relation path is allowed); an unknown field, or a `direction` other than `ASC`/`DESC`, answers 400 `invalid_request`. Invoices also sort by the computed columns `cost`, `remaining` and `creditNotes`. Unparseable JSON, or omitting the parameter, falls back to the default order (document number descending on the document lists). Cursor paging is only available for a single plain-column sort; with a computed column the server pages by `page`/`pageSize` and returns no `nextCursor`.",
            "schema": {
              "example": "[{\"field\":\"issueDate\",\"direction\":\"DESC\"}]",
              "type": "string"
            }
          },
          {
            "name": "filterModel",
            "required": false,
            "in": "query",
            "description": "Filters as a URL-encoded JSON object `{ items: [{ field, operator, value }] }` (query parameter name is `filterModel`, not `filter`); items are ANDed. `operator` is one of `contains`, `doesnotcontain`, `equals`, `is`, `=`, `!=`, `<>`, `doesnotequal`, `not`, `isoneof`, `startswith`, `endswith`, `before`, `after`, `onorbefore`, `onorafter`, `>`, `<`, `>=`, `<=`; an unknown field or operator answers 400 `invalid_request`. Invoices also filter the computed columns `cost`, `remaining` and `creditNotes` with the numeric operators only. Anything that is not a JSON object collapses to \"no filters\".",
            "schema": {
              "example": "{\"items\":[{\"field\":\"status\",\"operator\":\"equals\",\"value\":\"PAID\"}]}",
              "type": "string"
            }
          },
          {
            "name": "search",
            "required": false,
            "in": "query",
            "description": "Search, max 100 characters. On invoice, advance invoice, credit note, price offer and income document lists the text is split into words (first 5 used, each max 40 chars) and EVERY word must match — case- and diacritics-insensitive (\"kovac\" finds \"Kováč\"), words of 4+ letters also tolerate small typos. Matched fields: the number, the payment symbols, IBAN/BIC and any `sender`/`recipient` company field (name, address, email, phone, ico, dic, icDph, court); a numeric word also matches the issue date and the total. Item names are not searched. Other lists: case-insensitive substring search. A leading document-type prefix is stripped when it stands alone or is followed by a space, dash, slash or digit (`FA 2025`, `FA2025`; `FA` invoice, `ZA` advance invoice, `DB` credit note, `CP` price offer, `PD` income document); such a prefix that belongs to a different resource returns an empty list. A word that merely starts with those letters (\"Zahradník\") is searched as text.",
            "schema": {
              "maxLength": 100,
              "example": "kovac bratislava",
              "type": "string"
            }
          },
          {
            "name": "archived",
            "required": false,
            "in": "query",
            "description": "Accepted but **not applied** by the list endpoints today: archived documents are returned either way (their `status` is `archived`). To exclude or isolate them filter on `status` with `filterModel`.",
            "schema": {
              "example": "false",
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "required": false,
            "in": "query",
            "description": "Opaque token: pass back unchanged the `nextCursor` of the previous response (it is base64 text; do not build or parse it). When present it replaces `page`. It is only valid for the same `sortModel`/filters it was issued for; with a computed-column sort it is ignored and `page` applies.",
            "schema": {
              "example": "eyJpZCI6MTA0Mn0=",
              "type": "string"
            }
          },
          {
            "name": "index",
            "required": false,
            "in": "query",
            "description": "Add the per-status aggregates to the response: `d.data.count` (rows per status) and `d.data.amount` (summed `totalPrice` per status), over the whole account, ignoring the other filters; invoices also add `d.data.tabCounts`. It does not change the rows (list rows never carry `fields`) and is ignored with `shortList`. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          },
          {
            "name": "shortList",
            "required": false,
            "in": "query",
            "description": "Invoices only: collapse each row to `{ id, number, sender, recipient, issueDate }` for a picker. The other document lists ignore it. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          },
          {
            "name": "tab",
            "required": false,
            "in": "query",
            "description": "Derived index tab. Narrows the result set on top of any other filter. `unpaid` = issued with an outstanding balance, `overdue` = `unpaid` past its due date (Europe/Bratislava calendar day), `paid` = settled, the rest map to a stored status. Omitted behaves exactly as before.",
            "schema": {
              "example": "unpaid",
              "enum": [
                "all",
                "concept",
                "unpaid",
                "overdue",
                "paid",
                "cancelled",
                "archived"
              ],
              "type": "string"
            }
          },
          {
            "name": "number",
            "required": false,
            "in": "query",
            "description": "Exact document number within this account. Whitespace is ignored; the rest must be digits (1–30). Combines with every other filter. Returns the matching invoice, or an empty list — use it to verify whether a create whose response was lost went through.",
            "schema": {
              "pattern": "^[0-9 ]+$",
              "example": "20260042",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope. `d.data.list` is the page of rows; `d.data.total` is the unpaginated match count.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "object",
                          "required": [
                            "data"
                          ],
                          "properties": {
                            "data": {
                              "allOf": [
                                {
                                  "$ref": "#/components/schemas/ApiListMeta"
                                },
                                {
                                  "type": "object",
                                  "required": [
                                    "list"
                                  ],
                                  "properties": {
                                    "list": {
                                      "type": "array",
                                      "items": {
                                        "oneOf": [
                                          {
                                            "$ref": "#/components/schemas/InvoiceListItemDto"
                                          },
                                          {
                                            "$ref": "#/components/schemas/InvoiceShortListItemDto"
                                          }
                                        ]
                                      }
                                    },
                                    "tabCounts": {
                                      "type": "object",
                                      "additionalProperties": {
                                        "type": "number"
                                      },
                                      "description": "Badge counts per derived `tab` value (`all`, `unpaid`, `overdue`, `paid`, …). Returned only with `?index=true`."
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "List invoices",
        "tags": [
          "Invoices"
        ]
      },
      "delete": {
        "description": "Archives documents by default — they leave every list but the rows and their PDFs are kept. Pass `purge=true` to delete them permanently; that cannot be undone.",
        "operationId": "invoice_delete",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "ids",
            "required": true,
            "in": "query",
            "description": "Ids to act on. Accepted as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a single value. An empty or unparseable value answers 422 (`no_ids_provided` / `invalid_ids`).",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "purge",
            "required": false,
            "in": "query",
            "description": "Hard-delete instead of archive. Truthy values: `true`, `1`.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentDeleteResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Archive or purge invoices",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/import": {
      "post": {
        "description": "Parses uploaded invoice files (PDF/XML) and creates the invoices and advance invoices it recognises. `recommendCreditNotes` is advisory — nothing is created for it. Sent as `multipart/form-data` with one or more `files` parts.",
        "operationId": "invoice_import",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "What the importer created. `d` is `null` when nothing was recognised.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/InvoiceImportResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Import invoices from uploaded files",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/import/creditnote": {
      "post": {
        "description": "Returns an **unsaved** credit note derived from the posted invoice data, for a preview or a confirm step. Nothing is persisted — call `creditnote_create` to store it.",
        "operationId": "invoice_preview_creditnote",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "invoiceData"
                ],
                "properties": {
                  "invoiceData": {
                    "$ref": "#/components/schemas/InvoiceCreateDto"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An unsaved credit note draft.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/CreditNoteDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Build a credit note draft from invoice data",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/latestNumber": {
      "get": {
        "description": "Returns the highest document number currently used in this account, as a string. Use it to show the next number in a UI — do **not** use it to allocate one: creating a document without `number` lets the server continue the series atomically, which this read cannot do.",
        "operationId": "invoice_latest_number",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "string",
                          "example": "20260042"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get the highest invoice number in use",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/summary": {
      "get": {
        "description": "Period totals for the account, one bucket per currency (never summed across currencies), per-status counts and the invoice tab counts. `from`/`to` bound `issueDate` (at most the server-side maximum range apart); `archived` defaults to excluding archived invoices. Rate limited to 30 requests per 60 s and 600 per hour. Needs `INVOICES_READ`.",
        "operationId": "invoice_summary",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "from",
            "required": false,
            "in": "query",
            "description": "Inclusive lower bound on `issueDate`: an ISO-8601 instant, or a plain `YYYY-MM-DD` (start of that day in Europe/Bratislava).",
            "schema": {
              "example": "2026-10-01T00:00:00.000Z",
              "type": "string"
            }
          },
          {
            "name": "to",
            "required": false,
            "in": "query",
            "description": "Upper bound on `issueDate`: an ISO-8601 instant (EXCLUSIVE), or a plain `YYYY-MM-DD` (INCLUSIVE — the whole Europe/Bratislava day is included).",
            "schema": {
              "example": "2026-11-01T00:00:00.000Z",
              "type": "string"
            }
          },
          {
            "name": "monthFrom",
            "required": false,
            "in": "query",
            "description": "Inclusive start of the window behind `thisMonth`. Send it together with `monthTo` so the tile follows the client timezone; omit both and the server uses the current UTC calendar month.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "monthTo",
            "required": false,
            "in": "query",
            "description": "Exclusive end of the window behind `thisMonth`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "archived",
            "required": false,
            "in": "query",
            "description": "Archived rows: omitted/falsy excludes them (default), truthy returns only them, `all` returns both.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          },
          {
            "name": "tagId",
            "required": false,
            "in": "query",
            "description": "Receipt label (\"štítok\") id. Ignored by types without a tag relation.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "currency",
            "required": false,
            "in": "query",
            "description": "Restrict the response to a single currency bucket. Omit to get every currency the account used in the period.",
            "schema": {
              "example": "EUR",
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/InvoiceSummaryDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. The envelope carries the alias `rate_limit_exceeded` plus `retryAfterSeconds`, and the `Retry-After` header repeats it — wait that long rather than retrying immediately.\n\nNote for browser clients: `Retry-After` is not a CORS-safelisted response header, which is why the interval is in the body as well.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "rate_limit_exceeded"
                          ]
                        },
                        "retryAfterSeconds": {
                          "type": "integer",
                          "description": "Whole seconds until the window resets.",
                          "example": 42
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Summarise invoices",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/{id}": {
      "get": {
        "description": "Returns one document including its line items.",
        "operationId": "invoice_get",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/InvoiceDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get one invoice",
        "tags": [
          "Invoices"
        ]
      },
      "put": {
        "description": "Updates a document. Properties are merged, never replaced: an omitted property keeps its stored value. Unknown properties are dropped by the service allowlist rather than rejected, so a typo in a property name fails silently — check the response. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.",
        "operationId": "invoice_update",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InvoiceUpdateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/InvoiceUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated document.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/InvoiceDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Update an invoice",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/{id}/pdf": {
      "get": {
        "description": "Returns the rendered PDF as a binary body — **not** the `{ s, d, t }` envelope.\n\nErrors **are** enveloped: a failure answers `{ \"s\": \"error\", \"d\": \"<alias>\", \"t\": … }` with the status that alias maps to (401 for a bad key, 403 for a key bound to another account, 404 for an unknown id), never a bare `{ \"error\": … }` body and never an exception message.",
        "operationId": "invoice_pdf",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "regen",
            "required": false,
            "in": "query",
            "description": "Force a fresh render instead of serving the cached PDF. `true` to force.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The rendered PDF.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Download the invoice PDF",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/{id}/send": {
      "post": {
        "description": "Renders the PDF server-side and e-mails it. Not idempotent — a repeated call sends another e-mail.",
        "operationId": "invoice_send",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "schema": {
              "type": "number"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentSendDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/InvoiceSendResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "E-mail the invoice",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/{id}/peppol/send": {
      "post": {
        "description": "Queues the invoice for structured e-invoice delivery and returns it with the updated `peppolStatus`. Requires the account to have passed registry identity verification; an unverified account is refused by a guard before this handler runs.",
        "operationId": "invoice_send_peppol",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the invoice to send.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The invoice, with `peppolStatus` advanced to `QUEUED` or `SENT`.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/InvoiceDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "peppol_missing_dic",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "An eFaktúra sending allowance (per day or per month) is exhausted. Only time changes this answer.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "max_daily_peppol_docs_exceeded",
                            "max_monthly_peppol_docs_exceeded"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Send the invoice over eFaktúra (Peppol)",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/{id}/status": {
      "put": {
        "description": "Unlike the other document types, this returns the **whole updated invoice** in `d`, not the bare status string.",
        "operationId": "invoice_set_status",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "schema": {
              "type": "number"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentStatusUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/InvoiceDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Set the invoice status",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/{id}/details": {
      "get": {
        "description": "Without `get` this is identical to `invoice_get`. With `get` only the named properties are returned, which keeps a polling client small. Unknown names are ignored.",
        "operationId": "invoice_get_details",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "get",
            "required": false,
            "in": "query",
            "description": "Comma-separated property names to return, e.g. `status,totalPrice`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The invoice, or — when `get` was supplied — an object with only the requested properties.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/InvoiceDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_recipient",
                            "invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_file_type",
                            "no_files_attached",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get selected invoice properties",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/creditnote": {
      "post": {
        "description": "Creates a document and returns it with its server-assigned `id` and number. Answers **200**, not 201. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.\n\nSupply `invoiceId` to link the credit note to an Účtovisko invoice, or only `invoiceNumber` to credit an invoice issued elsewhere.",
        "operationId": "creditnote_create",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreditNoteCreateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/CreditNoteCreateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created document.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/CreditNoteDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_invalid_fields",
                            "creditnote_invalid_number",
                            "creditnote_invalid_issue_date",
                            "creditnote_invalid_due_date",
                            "creditnote_invalid_sender",
                            "creditnote_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Create a credit note",
        "tags": [
          "Credit notes"
        ]
      },
      "get": {
        "description": "Returns one page of documents, newest first. `fields` (line items) are omitted from list rows — fetch a document by id to get them. Query parameters follow the description of each parameter below; the parameter names are `sortModel` and `filterModel`.",
        "operationId": "creditnote_list",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "page",
            "required": false,
            "in": "query",
            "description": "Zero-based page index. Ignored when `cursor` is supplied. A value that is not a non-negative integer is treated as absent, not as an error.",
            "schema": {
              "minimum": 0,
              "default": 0,
              "example": 0,
              "type": "number"
            }
          },
          {
            "name": "pageSize",
            "required": false,
            "in": "query",
            "description": "Items per page. A positive integer, maximum 500 (a larger value is rejected with 400). Anything that is not a positive integer is treated as absent and the default applies.",
            "schema": {
              "minimum": 1,
              "maximum": 500,
              "default": 10,
              "example": 50,
              "type": "number"
            }
          },
          {
            "name": "ids",
            "required": false,
            "in": "query",
            "description": "Fetch exactly these rows by id (integers). Overrides `search`, `filterModel`, `sortModel`, `page`/`pageSize` and `cursor`; the answer then carries `list` and `total` only (no `nextCursor`). Accepted on the wire as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a JSON array (`ids=[\"1\",\"2\"]`).",
            "schema": {
              "example": [
                "1042",
                "1043"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "addRelations",
            "required": false,
            "in": "query",
            "description": "Extra relations to join into each row. Only relations on the endpoint's server-side allowlist are accepted (on the public document lists that is the creator, already included); any other name answers 400 `invalid_request`. Integrators normally omit it.",
            "schema": {
              "example": [
                "client"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "sortModel",
            "required": false,
            "in": "query",
            "description": "Sort order as a URL-encoded JSON array of `{ field, direction }` (query parameter name is `sortModel`, not `sort`). `field` is a column of the row (a dotted relation path is allowed); an unknown field, or a `direction` other than `ASC`/`DESC`, answers 400 `invalid_request`. Invoices also sort by the computed columns `cost`, `remaining` and `creditNotes`. Unparseable JSON, or omitting the parameter, falls back to the default order (document number descending on the document lists). Cursor paging is only available for a single plain-column sort; with a computed column the server pages by `page`/`pageSize` and returns no `nextCursor`.",
            "schema": {
              "example": "[{\"field\":\"issueDate\",\"direction\":\"DESC\"}]",
              "type": "string"
            }
          },
          {
            "name": "filterModel",
            "required": false,
            "in": "query",
            "description": "Filters as a URL-encoded JSON object `{ items: [{ field, operator, value }] }` (query parameter name is `filterModel`, not `filter`); items are ANDed. `operator` is one of `contains`, `doesnotcontain`, `equals`, `is`, `=`, `!=`, `<>`, `doesnotequal`, `not`, `isoneof`, `startswith`, `endswith`, `before`, `after`, `onorbefore`, `onorafter`, `>`, `<`, `>=`, `<=`; an unknown field or operator answers 400 `invalid_request`. Invoices also filter the computed columns `cost`, `remaining` and `creditNotes` with the numeric operators only. Anything that is not a JSON object collapses to \"no filters\".",
            "schema": {
              "example": "{\"items\":[{\"field\":\"status\",\"operator\":\"equals\",\"value\":\"PAID\"}]}",
              "type": "string"
            }
          },
          {
            "name": "search",
            "required": false,
            "in": "query",
            "description": "Search, max 100 characters. On invoice, advance invoice, credit note, price offer and income document lists the text is split into words (first 5 used, each max 40 chars) and EVERY word must match — case- and diacritics-insensitive (\"kovac\" finds \"Kováč\"), words of 4+ letters also tolerate small typos. Matched fields: the number, the payment symbols, IBAN/BIC and any `sender`/`recipient` company field (name, address, email, phone, ico, dic, icDph, court); a numeric word also matches the issue date and the total. Item names are not searched. Other lists: case-insensitive substring search. A leading document-type prefix is stripped when it stands alone or is followed by a space, dash, slash or digit (`FA 2025`, `FA2025`; `FA` invoice, `ZA` advance invoice, `DB` credit note, `CP` price offer, `PD` income document); such a prefix that belongs to a different resource returns an empty list. A word that merely starts with those letters (\"Zahradník\") is searched as text.",
            "schema": {
              "maxLength": 100,
              "example": "kovac bratislava",
              "type": "string"
            }
          },
          {
            "name": "archived",
            "required": false,
            "in": "query",
            "description": "Accepted but **not applied** by the list endpoints today: archived documents are returned either way (their `status` is `archived`). To exclude or isolate them filter on `status` with `filterModel`.",
            "schema": {
              "example": "false",
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "required": false,
            "in": "query",
            "description": "Opaque token: pass back unchanged the `nextCursor` of the previous response (it is base64 text; do not build or parse it). When present it replaces `page`. It is only valid for the same `sortModel`/filters it was issued for; with a computed-column sort it is ignored and `page` applies.",
            "schema": {
              "example": "eyJpZCI6MTA0Mn0=",
              "type": "string"
            }
          },
          {
            "name": "index",
            "required": false,
            "in": "query",
            "description": "Add the per-status aggregates to the response: `d.data.count` (rows per status) and `d.data.amount` (summed `totalPrice` per status), over the whole account, ignoring the other filters; invoices also add `d.data.tabCounts`. It does not change the rows (list rows never carry `fields`) and is ignored with `shortList`. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          },
          {
            "name": "shortList",
            "required": false,
            "in": "query",
            "description": "Invoices only: collapse each row to `{ id, number, sender, recipient, issueDate }` for a picker. The other document lists ignore it. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope. `d.data.list` is the page of rows; `d.data.total` is the unpaginated match count.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "object",
                          "required": [
                            "data"
                          ],
                          "properties": {
                            "data": {
                              "allOf": [
                                {
                                  "$ref": "#/components/schemas/ApiListMeta"
                                },
                                {
                                  "type": "object",
                                  "required": [
                                    "list"
                                  ],
                                  "properties": {
                                    "list": {
                                      "type": "array",
                                      "items": {
                                        "$ref": "#/components/schemas/CreditNoteListItemDto"
                                      }
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_invalid_fields",
                            "creditnote_invalid_number",
                            "creditnote_invalid_issue_date",
                            "creditnote_invalid_due_date",
                            "creditnote_invalid_sender",
                            "creditnote_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "List credit notes",
        "tags": [
          "Credit notes"
        ]
      },
      "delete": {
        "description": "Archives documents by default — they leave every list but the rows and their PDFs are kept. Pass `purge=true` to delete them permanently; that cannot be undone.",
        "operationId": "creditnote_delete",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "ids",
            "required": true,
            "in": "query",
            "description": "Ids to act on. Accepted as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a single value. An empty or unparseable value answers 422 (`no_ids_provided` / `invalid_ids`).",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "purge",
            "required": false,
            "in": "query",
            "description": "Hard-delete instead of archive. Truthy values: `true`, `1`.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentDeleteResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_invalid_fields",
                            "creditnote_invalid_number",
                            "creditnote_invalid_issue_date",
                            "creditnote_invalid_due_date",
                            "creditnote_invalid_sender",
                            "creditnote_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Archive or purge credit notes",
        "tags": [
          "Credit notes"
        ]
      }
    },
    "/account/{accountId}/creditnote/latestNumber": {
      "get": {
        "description": "Returns the highest document number currently used in this account, as a string. Use it to show the next number in a UI — do **not** use it to allocate one: creating a document without `number` lets the server continue the series atomically, which this read cannot do.",
        "operationId": "creditnote_latest_number",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "string",
                          "example": "20260042"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_invalid_fields",
                            "creditnote_invalid_number",
                            "creditnote_invalid_issue_date",
                            "creditnote_invalid_due_date",
                            "creditnote_invalid_sender",
                            "creditnote_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get the highest credit note number in use",
        "tags": [
          "Credit notes"
        ]
      }
    },
    "/account/{accountId}/creditnote/{id}": {
      "get": {
        "description": "Returns one document including its line items.",
        "operationId": "creditnote_get",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/CreditNoteDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_invalid_fields",
                            "creditnote_invalid_number",
                            "creditnote_invalid_issue_date",
                            "creditnote_invalid_due_date",
                            "creditnote_invalid_sender",
                            "creditnote_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get one credit note",
        "tags": [
          "Credit notes"
        ]
      },
      "put": {
        "description": "Updates a document. Properties are merged, never replaced: an omitted property keeps its stored value. Unknown properties are dropped by the service allowlist rather than rejected, so a typo in a property name fails silently — check the response. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.",
        "operationId": "creditnote_update",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreditNoteUpdateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/CreditNoteUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated document.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/CreditNoteDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_invalid_fields",
                            "creditnote_invalid_number",
                            "creditnote_invalid_issue_date",
                            "creditnote_invalid_due_date",
                            "creditnote_invalid_sender",
                            "creditnote_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Update a credit note",
        "tags": [
          "Credit notes"
        ]
      }
    },
    "/account/{accountId}/creditnote/{id}/pdf": {
      "get": {
        "description": "Returns the rendered PDF as a binary body — **not** the `{ s, d, t }` envelope.\n\nErrors **are** enveloped: a failure answers `{ \"s\": \"error\", \"d\": \"<alias>\", \"t\": … }` with the status that alias maps to (401 for a bad key, 403 for a key bound to another account, 404 for an unknown id), never a bare `{ \"error\": … }` body and never an exception message.\n\nRendering is asynchronous: while it is still running the response is **202** with that same error envelope and the alias `pdf_is_loading` — retry after a short delay.",
        "operationId": "creditnote_pdf",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "fallback",
            "required": false,
            "in": "query",
            "description": "Serve a simplified fallback rendering when the full template fails. `true` to allow.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The rendered PDF.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "202": {
            "description": "The PDF is still being rendered. Retry after a short delay — the render was started, so a retry is expected to succeed rather than repeat this answer.\n\nThe body **is** the ordinary error envelope, with the alias `pdf_is_loading`:\n\n```json\n{ \"s\": \"error\", \"d\": \"pdf_is_loading\", \"t\": \"2026-10-04T09:21:44.512Z\" }\n```\n\nBranch on the **status**, not on `s`: 202 is a wait, not a failure. (Before UC-227 this status was unreachable — the alias was unmapped and a rendering PDF answered 500 with a non-envelope body.)",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "pdf_is_loading"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_invalid_fields",
                            "creditnote_invalid_number",
                            "creditnote_invalid_issue_date",
                            "creditnote_invalid_due_date",
                            "creditnote_invalid_sender",
                            "creditnote_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Download the credit note PDF",
        "tags": [
          "Credit notes"
        ]
      }
    },
    "/account/{accountId}/creditnote/{id}/send": {
      "post": {
        "description": "Renders the PDF server-side and e-mails it. The response carries **no** `d` — only `s` and `t`. Not idempotent: a repeated call sends another e-mail.",
        "operationId": "creditnote_send",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentSendDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledgement envelope. `d` is absent on this operation — only `s` and `t` are sent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiOkEnvelope"
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_invalid_fields",
                            "creditnote_invalid_number",
                            "creditnote_invalid_issue_date",
                            "creditnote_invalid_due_date",
                            "creditnote_invalid_sender",
                            "creditnote_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "E-mail the credit note",
        "tags": [
          "Credit notes"
        ]
      }
    },
    "/account/{accountId}/creditnote/{id}/status": {
      "put": {
        "description": "Sets the lifecycle status of one document. Returns the stored status as a bare string in `d`, not the whole document.",
        "operationId": "creditnote_set_status",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentStatusUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The status now stored.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "processing",
                            "issued",
                            "applied",
                            "refunded",
                            "cancelled",
                            "archived"
                          ],
                          "example": "processing"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_invalid_fields",
                            "creditnote_invalid_number",
                            "creditnote_invalid_issue_date",
                            "creditnote_invalid_due_date",
                            "creditnote_invalid_sender",
                            "creditnote_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "creditnote_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Set the credit note status",
        "tags": [
          "Credit notes"
        ]
      }
    },
    "/account/{accountId}/priceoffer": {
      "post": {
        "description": "Creates a document and returns it with its server-assigned `id` and number. Answers **200**, not 201. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.\n\nA price offer carries no payment details and no due date — use `validityDate`. Status defaults to `sent`, not `draft`.",
        "operationId": "priceoffer_create",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PriceOfferCreateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/PriceOfferCreateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created document.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/PriceOfferDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_invalid_fields",
                            "priceoffer_invalid_number",
                            "priceoffer_invalid_issue_date",
                            "priceoffer_invalid_validity_date",
                            "priceoffer_invalid_sender",
                            "priceoffer_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Create a price offer",
        "tags": [
          "Price offers"
        ]
      },
      "get": {
        "description": "Returns one page of documents, newest first. `fields` (line items) are omitted from list rows — fetch a document by id to get them. Query parameters follow the description of each parameter below; the parameter names are `sortModel` and `filterModel`.",
        "operationId": "priceoffer_list",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "page",
            "required": false,
            "in": "query",
            "description": "Zero-based page index. Ignored when `cursor` is supplied. A value that is not a non-negative integer is treated as absent, not as an error.",
            "schema": {
              "minimum": 0,
              "default": 0,
              "example": 0,
              "type": "number"
            }
          },
          {
            "name": "pageSize",
            "required": false,
            "in": "query",
            "description": "Items per page. A positive integer, maximum 500 (a larger value is rejected with 400). Anything that is not a positive integer is treated as absent and the default applies.",
            "schema": {
              "minimum": 1,
              "maximum": 500,
              "default": 10,
              "example": 50,
              "type": "number"
            }
          },
          {
            "name": "ids",
            "required": false,
            "in": "query",
            "description": "Fetch exactly these rows by id (integers). Overrides `search`, `filterModel`, `sortModel`, `page`/`pageSize` and `cursor`; the answer then carries `list` and `total` only (no `nextCursor`). Accepted on the wire as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a JSON array (`ids=[\"1\",\"2\"]`).",
            "schema": {
              "example": [
                "1042",
                "1043"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "addRelations",
            "required": false,
            "in": "query",
            "description": "Extra relations to join into each row. Only relations on the endpoint's server-side allowlist are accepted (on the public document lists that is the creator, already included); any other name answers 400 `invalid_request`. Integrators normally omit it.",
            "schema": {
              "example": [
                "client"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "sortModel",
            "required": false,
            "in": "query",
            "description": "Sort order as a URL-encoded JSON array of `{ field, direction }` (query parameter name is `sortModel`, not `sort`). `field` is a column of the row (a dotted relation path is allowed); an unknown field, or a `direction` other than `ASC`/`DESC`, answers 400 `invalid_request`. Invoices also sort by the computed columns `cost`, `remaining` and `creditNotes`. Unparseable JSON, or omitting the parameter, falls back to the default order (document number descending on the document lists). Cursor paging is only available for a single plain-column sort; with a computed column the server pages by `page`/`pageSize` and returns no `nextCursor`.",
            "schema": {
              "example": "[{\"field\":\"issueDate\",\"direction\":\"DESC\"}]",
              "type": "string"
            }
          },
          {
            "name": "filterModel",
            "required": false,
            "in": "query",
            "description": "Filters as a URL-encoded JSON object `{ items: [{ field, operator, value }] }` (query parameter name is `filterModel`, not `filter`); items are ANDed. `operator` is one of `contains`, `doesnotcontain`, `equals`, `is`, `=`, `!=`, `<>`, `doesnotequal`, `not`, `isoneof`, `startswith`, `endswith`, `before`, `after`, `onorbefore`, `onorafter`, `>`, `<`, `>=`, `<=`; an unknown field or operator answers 400 `invalid_request`. Invoices also filter the computed columns `cost`, `remaining` and `creditNotes` with the numeric operators only. Anything that is not a JSON object collapses to \"no filters\".",
            "schema": {
              "example": "{\"items\":[{\"field\":\"status\",\"operator\":\"equals\",\"value\":\"PAID\"}]}",
              "type": "string"
            }
          },
          {
            "name": "search",
            "required": false,
            "in": "query",
            "description": "Search, max 100 characters. On invoice, advance invoice, credit note, price offer and income document lists the text is split into words (first 5 used, each max 40 chars) and EVERY word must match — case- and diacritics-insensitive (\"kovac\" finds \"Kováč\"), words of 4+ letters also tolerate small typos. Matched fields: the number, the payment symbols, IBAN/BIC and any `sender`/`recipient` company field (name, address, email, phone, ico, dic, icDph, court); a numeric word also matches the issue date and the total. Item names are not searched. Other lists: case-insensitive substring search. A leading document-type prefix is stripped when it stands alone or is followed by a space, dash, slash or digit (`FA 2025`, `FA2025`; `FA` invoice, `ZA` advance invoice, `DB` credit note, `CP` price offer, `PD` income document); such a prefix that belongs to a different resource returns an empty list. A word that merely starts with those letters (\"Zahradník\") is searched as text.",
            "schema": {
              "maxLength": 100,
              "example": "kovac bratislava",
              "type": "string"
            }
          },
          {
            "name": "archived",
            "required": false,
            "in": "query",
            "description": "Accepted but **not applied** by the list endpoints today: archived documents are returned either way (their `status` is `archived`). To exclude or isolate them filter on `status` with `filterModel`.",
            "schema": {
              "example": "false",
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "required": false,
            "in": "query",
            "description": "Opaque token: pass back unchanged the `nextCursor` of the previous response (it is base64 text; do not build or parse it). When present it replaces `page`. It is only valid for the same `sortModel`/filters it was issued for; with a computed-column sort it is ignored and `page` applies.",
            "schema": {
              "example": "eyJpZCI6MTA0Mn0=",
              "type": "string"
            }
          },
          {
            "name": "index",
            "required": false,
            "in": "query",
            "description": "Add the per-status aggregates to the response: `d.data.count` (rows per status) and `d.data.amount` (summed `totalPrice` per status), over the whole account, ignoring the other filters; invoices also add `d.data.tabCounts`. It does not change the rows (list rows never carry `fields`) and is ignored with `shortList`. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          },
          {
            "name": "shortList",
            "required": false,
            "in": "query",
            "description": "Invoices only: collapse each row to `{ id, number, sender, recipient, issueDate }` for a picker. The other document lists ignore it. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope. `d.data.list` is the page of rows; `d.data.total` is the unpaginated match count.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "object",
                          "required": [
                            "data"
                          ],
                          "properties": {
                            "data": {
                              "allOf": [
                                {
                                  "$ref": "#/components/schemas/ApiListMeta"
                                },
                                {
                                  "type": "object",
                                  "required": [
                                    "list"
                                  ],
                                  "properties": {
                                    "list": {
                                      "type": "array",
                                      "items": {
                                        "$ref": "#/components/schemas/PriceOfferListItemDto"
                                      }
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_invalid_fields",
                            "priceoffer_invalid_number",
                            "priceoffer_invalid_issue_date",
                            "priceoffer_invalid_validity_date",
                            "priceoffer_invalid_sender",
                            "priceoffer_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "List price offers",
        "tags": [
          "Price offers"
        ]
      },
      "delete": {
        "description": "Archives documents by default — they leave every list but the rows and their PDFs are kept. Pass `purge=true` to delete them permanently; that cannot be undone.",
        "operationId": "priceoffer_delete",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "ids",
            "required": true,
            "in": "query",
            "description": "Ids to act on. Accepted as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a single value. An empty or unparseable value answers 422 (`no_ids_provided` / `invalid_ids`).",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "purge",
            "required": false,
            "in": "query",
            "description": "Hard-delete instead of archive. Truthy values: `true`, `1`.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentDeleteResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_invalid_fields",
                            "priceoffer_invalid_number",
                            "priceoffer_invalid_issue_date",
                            "priceoffer_invalid_validity_date",
                            "priceoffer_invalid_sender",
                            "priceoffer_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Archive or purge price offers",
        "tags": [
          "Price offers"
        ]
      }
    },
    "/account/{accountId}/priceoffer/latestNumber": {
      "get": {
        "description": "Returns the highest document number currently used in this account, as a string. Use it to show the next number in a UI — do **not** use it to allocate one: creating a document without `number` lets the server continue the series atomically, which this read cannot do.",
        "operationId": "priceoffer_latest_number",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "string",
                          "example": "20260042"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_invalid_fields",
                            "priceoffer_invalid_number",
                            "priceoffer_invalid_issue_date",
                            "priceoffer_invalid_validity_date",
                            "priceoffer_invalid_sender",
                            "priceoffer_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get the highest price offer number in use",
        "tags": [
          "Price offers"
        ]
      }
    },
    "/account/{accountId}/priceoffer/{id}": {
      "get": {
        "description": "Returns one document including its line items.",
        "operationId": "priceoffer_get",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/PriceOfferDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_invalid_fields",
                            "priceoffer_invalid_number",
                            "priceoffer_invalid_issue_date",
                            "priceoffer_invalid_validity_date",
                            "priceoffer_invalid_sender",
                            "priceoffer_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get one price offer",
        "tags": [
          "Price offers"
        ]
      },
      "put": {
        "description": "Updates a document. Properties are merged, never replaced: an omitted property keeps its stored value. Unknown properties are dropped by the service allowlist rather than rejected, so a typo in a property name fails silently — check the response. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.",
        "operationId": "priceoffer_update",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PriceOfferUpdateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/PriceOfferUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated document.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/PriceOfferDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_invalid_fields",
                            "priceoffer_invalid_number",
                            "priceoffer_invalid_issue_date",
                            "priceoffer_invalid_validity_date",
                            "priceoffer_invalid_sender",
                            "priceoffer_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Update a price offer",
        "tags": [
          "Price offers"
        ]
      }
    },
    "/account/{accountId}/priceoffer/{id}/pdf": {
      "get": {
        "description": "Returns the rendered PDF as a binary body — **not** the `{ s, d, t }` envelope.\n\nErrors **are** enveloped: a failure answers `{ \"s\": \"error\", \"d\": \"<alias>\", \"t\": … }` with the status that alias maps to (401 for a bad key, 403 for a key bound to another account, 404 for an unknown id), never a bare `{ \"error\": … }` body and never an exception message.",
        "operationId": "priceoffer_pdf",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "fallback",
            "required": false,
            "in": "query",
            "description": "Serve a simplified fallback rendering when the full template fails. `true` to allow.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The rendered PDF.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_invalid_fields",
                            "priceoffer_invalid_number",
                            "priceoffer_invalid_issue_date",
                            "priceoffer_invalid_validity_date",
                            "priceoffer_invalid_sender",
                            "priceoffer_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Download the price offer PDF",
        "tags": [
          "Price offers"
        ]
      }
    },
    "/account/{accountId}/priceoffer/{id}/send": {
      "post": {
        "description": "Renders the PDF server-side and e-mails it. The response carries **no** `d` — only `s` and `t`. Not idempotent: a repeated call sends another e-mail.",
        "operationId": "priceoffer_send",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentSendDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledgement envelope. `d` is absent on this operation — only `s` and `t` are sent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiOkEnvelope"
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_invalid_fields",
                            "priceoffer_invalid_number",
                            "priceoffer_invalid_issue_date",
                            "priceoffer_invalid_validity_date",
                            "priceoffer_invalid_sender",
                            "priceoffer_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "E-mail the price offer",
        "tags": [
          "Price offers"
        ]
      }
    },
    "/account/{accountId}/priceoffer/{id}/status": {
      "put": {
        "description": "Sets the lifecycle status of one document. Returns the stored status as a bare string in `d`, not the whole document.",
        "operationId": "priceoffer_set_status",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentStatusUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The status now stored.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "draft",
                            "sent",
                            "accepted",
                            "rejected",
                            "expired",
                            "archived"
                          ],
                          "example": "draft"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_invalid_fields",
                            "priceoffer_invalid_number",
                            "priceoffer_invalid_issue_date",
                            "priceoffer_invalid_validity_date",
                            "priceoffer_invalid_sender",
                            "priceoffer_invalid_recipient",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "priceoffer_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Set the price offer status",
        "tags": [
          "Price offers"
        ]
      }
    },
    "/account/{accountId}/incomeDocument": {
      "post": {
        "description": "Creates a document and returns it with its server-assigned `id` and number. Answers **200**, not 201. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.\n\nAn income document records a payment received against an invoice and has no line items. Give `invoiceId` for an Účtovisko invoice, or `invoiceNumber` plus `invoicePrice` for an external one.",
        "operationId": "income_document_create",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IncomeDocumentCreateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/IncomeDocumentCreateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created document.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/IncomeDocumentDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Create an income document",
        "tags": [
          "Income documents"
        ]
      },
      "get": {
        "description": "Returns one page of documents, newest first. `fields` (line items) are omitted from list rows — fetch a document by id to get them. Query parameters follow the description of each parameter below; the parameter names are `sortModel` and `filterModel`.",
        "operationId": "income_document_list",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "page",
            "required": false,
            "in": "query",
            "description": "Zero-based page index. Ignored when `cursor` is supplied. A value that is not a non-negative integer is treated as absent, not as an error.",
            "schema": {
              "minimum": 0,
              "default": 0,
              "example": 0,
              "type": "number"
            }
          },
          {
            "name": "pageSize",
            "required": false,
            "in": "query",
            "description": "Items per page. A positive integer, maximum 500 (a larger value is rejected with 400). Anything that is not a positive integer is treated as absent and the default applies.",
            "schema": {
              "minimum": 1,
              "maximum": 500,
              "default": 10,
              "example": 50,
              "type": "number"
            }
          },
          {
            "name": "ids",
            "required": false,
            "in": "query",
            "description": "Fetch exactly these rows by id (integers). Overrides `search`, `filterModel`, `sortModel`, `page`/`pageSize` and `cursor`; the answer then carries `list` and `total` only (no `nextCursor`). Accepted on the wire as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a JSON array (`ids=[\"1\",\"2\"]`).",
            "schema": {
              "example": [
                "1042",
                "1043"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "addRelations",
            "required": false,
            "in": "query",
            "description": "Extra relations to join into each row. Only relations on the endpoint's server-side allowlist are accepted (on the public document lists that is the creator, already included); any other name answers 400 `invalid_request`. Integrators normally omit it.",
            "schema": {
              "example": [
                "client"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "sortModel",
            "required": false,
            "in": "query",
            "description": "Sort order as a URL-encoded JSON array of `{ field, direction }` (query parameter name is `sortModel`, not `sort`). `field` is a column of the row (a dotted relation path is allowed); an unknown field, or a `direction` other than `ASC`/`DESC`, answers 400 `invalid_request`. Invoices also sort by the computed columns `cost`, `remaining` and `creditNotes`. Unparseable JSON, or omitting the parameter, falls back to the default order (document number descending on the document lists). Cursor paging is only available for a single plain-column sort; with a computed column the server pages by `page`/`pageSize` and returns no `nextCursor`.",
            "schema": {
              "example": "[{\"field\":\"issueDate\",\"direction\":\"DESC\"}]",
              "type": "string"
            }
          },
          {
            "name": "filterModel",
            "required": false,
            "in": "query",
            "description": "Filters as a URL-encoded JSON object `{ items: [{ field, operator, value }] }` (query parameter name is `filterModel`, not `filter`); items are ANDed. `operator` is one of `contains`, `doesnotcontain`, `equals`, `is`, `=`, `!=`, `<>`, `doesnotequal`, `not`, `isoneof`, `startswith`, `endswith`, `before`, `after`, `onorbefore`, `onorafter`, `>`, `<`, `>=`, `<=`; an unknown field or operator answers 400 `invalid_request`. Invoices also filter the computed columns `cost`, `remaining` and `creditNotes` with the numeric operators only. Anything that is not a JSON object collapses to \"no filters\".",
            "schema": {
              "example": "{\"items\":[{\"field\":\"status\",\"operator\":\"equals\",\"value\":\"PAID\"}]}",
              "type": "string"
            }
          },
          {
            "name": "search",
            "required": false,
            "in": "query",
            "description": "Search, max 100 characters. On invoice, advance invoice, credit note, price offer and income document lists the text is split into words (first 5 used, each max 40 chars) and EVERY word must match — case- and diacritics-insensitive (\"kovac\" finds \"Kováč\"), words of 4+ letters also tolerate small typos. Matched fields: the number, the payment symbols, IBAN/BIC and any `sender`/`recipient` company field (name, address, email, phone, ico, dic, icDph, court); a numeric word also matches the issue date and the total. Item names are not searched. Other lists: case-insensitive substring search. A leading document-type prefix is stripped when it stands alone or is followed by a space, dash, slash or digit (`FA 2025`, `FA2025`; `FA` invoice, `ZA` advance invoice, `DB` credit note, `CP` price offer, `PD` income document); such a prefix that belongs to a different resource returns an empty list. A word that merely starts with those letters (\"Zahradník\") is searched as text.",
            "schema": {
              "maxLength": 100,
              "example": "kovac bratislava",
              "type": "string"
            }
          },
          {
            "name": "archived",
            "required": false,
            "in": "query",
            "description": "Accepted but **not applied** by the list endpoints today: archived documents are returned either way (their `status` is `archived`). To exclude or isolate them filter on `status` with `filterModel`.",
            "schema": {
              "example": "false",
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "required": false,
            "in": "query",
            "description": "Opaque token: pass back unchanged the `nextCursor` of the previous response (it is base64 text; do not build or parse it). When present it replaces `page`. It is only valid for the same `sortModel`/filters it was issued for; with a computed-column sort it is ignored and `page` applies.",
            "schema": {
              "example": "eyJpZCI6MTA0Mn0=",
              "type": "string"
            }
          },
          {
            "name": "index",
            "required": false,
            "in": "query",
            "description": "Add the per-status aggregates to the response: `d.data.count` (rows per status) and `d.data.amount` (summed `totalPrice` per status), over the whole account, ignoring the other filters; invoices also add `d.data.tabCounts`. It does not change the rows (list rows never carry `fields`) and is ignored with `shortList`. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          },
          {
            "name": "shortList",
            "required": false,
            "in": "query",
            "description": "Invoices only: collapse each row to `{ id, number, sender, recipient, issueDate }` for a picker. The other document lists ignore it. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope. `d.data.list` is the page of rows; `d.data.total` is the unpaginated match count.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "object",
                          "required": [
                            "data"
                          ],
                          "properties": {
                            "data": {
                              "allOf": [
                                {
                                  "$ref": "#/components/schemas/ApiListMeta"
                                },
                                {
                                  "type": "object",
                                  "required": [
                                    "list"
                                  ],
                                  "properties": {
                                    "list": {
                                      "type": "array",
                                      "items": {
                                        "$ref": "#/components/schemas/IncomeDocumentListItemDto"
                                      }
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "List income documents",
        "tags": [
          "Income documents"
        ]
      },
      "delete": {
        "description": "Archives documents by default — they leave every list but the rows and their PDFs are kept. Pass `purge=true` to delete them permanently; that cannot be undone.",
        "operationId": "income_document_delete",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "ids",
            "required": true,
            "in": "query",
            "description": "Ids to act on. Accepted as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a single value. An empty or unparseable value answers 422 (`no_ids_provided` / `invalid_ids`).",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "purge",
            "required": false,
            "in": "query",
            "description": "Hard-delete instead of archive. Truthy values: `true`, `1`.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentDeleteResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Archive or purge income documents",
        "tags": [
          "Income documents"
        ]
      }
    },
    "/account/{accountId}/incomeDocument/latestNumber": {
      "get": {
        "description": "Returns the highest document number currently used in this account, as a string. Use it to show the next number in a UI — do **not** use it to allocate one: creating a document without `number` lets the server continue the series atomically, which this read cannot do.",
        "operationId": "income_document_latest_number",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "string",
                          "example": "20260042"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get the highest income document number in use",
        "tags": [
          "Income documents"
        ]
      }
    },
    "/account/{accountId}/incomeDocument/{id}": {
      "get": {
        "description": "Returns one document including its line items.",
        "operationId": "income_document_get",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/IncomeDocumentDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get one income document",
        "tags": [
          "Income documents"
        ]
      },
      "put": {
        "description": "Updates a document. Properties are merged, never replaced: an omitted property keeps its stored value. Unknown properties are dropped by the service allowlist rather than rejected, so a typo in a property name fails silently — check the response. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.",
        "operationId": "income_document_update",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IncomeDocumentUpdateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/IncomeDocumentUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated document.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/IncomeDocumentDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Update an income document",
        "tags": [
          "Income documents"
        ]
      }
    },
    "/account/{accountId}/incomeDocument/{id}/pdf": {
      "get": {
        "description": "Returns the rendered PDF as a binary body — **not** the `{ s, d, t }` envelope.\n\nErrors **are** enveloped: a failure answers `{ \"s\": \"error\", \"d\": \"<alias>\", \"t\": … }` with the status that alias maps to (401 for a bad key, 403 for a key bound to another account, 404 for an unknown id), never a bare `{ \"error\": … }` body and never an exception message.\n\nRendering is asynchronous: while it is still running the response is **202** with that same error envelope and the alias `pdf_is_loading` — retry after a short delay.",
        "operationId": "income_document_pdf",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "fallback",
            "required": false,
            "in": "query",
            "description": "Serve a simplified fallback rendering when the full template fails. `true` to allow.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The rendered PDF.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "202": {
            "description": "The PDF is still being rendered. Retry after a short delay — the render was started, so a retry is expected to succeed rather than repeat this answer.\n\nThe body **is** the ordinary error envelope, with the alias `pdf_is_loading`:\n\n```json\n{ \"s\": \"error\", \"d\": \"pdf_is_loading\", \"t\": \"2026-10-04T09:21:44.512Z\" }\n```\n\nBranch on the **status**, not on `s`: 202 is a wait, not a failure. (Before UC-227 this status was unreachable — the alias was unmapped and a rendering PDF answered 500 with a non-envelope body.)",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "pdf_is_loading"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Download the income document PDF",
        "tags": [
          "Income documents"
        ]
      }
    },
    "/account/{accountId}/incomeDocument/{id}/send": {
      "post": {
        "description": "Renders the PDF server-side and e-mails it. The response carries **no** `d` — only `s` and `t`. Not idempotent: a repeated call sends another e-mail.",
        "operationId": "income_document_send",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentSendDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledgement envelope. `d` is absent on this operation — only `s` and `t` are sent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiOkEnvelope"
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "E-mail the income document",
        "tags": [
          "Income documents"
        ]
      }
    },
    "/account/{accountId}/incomeDocument/{id}/status": {
      "put": {
        "description": "Sets the lifecycle status of one document. Returns the stored status as a bare string in `d`, not the whole document.",
        "operationId": "income_document_set_status",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentStatusUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The status now stored.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "draft",
                            "issued",
                            "cancelled",
                            "archived"
                          ],
                          "example": "draft"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Set the income document status",
        "tags": [
          "Income documents"
        ]
      }
    },
    "/account/{accountId}/advanceInvoice": {
      "post": {
        "description": "Creates a document and returns it with its server-assigned `id` and number. Answers **200**, not 201. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.\n\nStatus `settled` means the advance was consumed by a final invoice; it is set by the invoicing flow, not by a client.",
        "operationId": "advance_invoice_create",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AdvanceInvoiceCreateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/AdvanceInvoiceCreateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created document.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/AdvanceInvoiceDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_sender",
                            "invoice_invalid_recipient",
                            "advance_invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Create an advance invoice",
        "tags": [
          "Advance invoices"
        ]
      },
      "get": {
        "description": "Returns one page of documents, newest first. `fields` (line items) are omitted from list rows — fetch a document by id to get them. Query parameters follow the description of each parameter below; the parameter names are `sortModel` and `filterModel`.",
        "operationId": "advance_invoice_list",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "page",
            "required": false,
            "in": "query",
            "description": "Zero-based page index. Ignored when `cursor` is supplied. A value that is not a non-negative integer is treated as absent, not as an error.",
            "schema": {
              "minimum": 0,
              "default": 0,
              "example": 0,
              "type": "number"
            }
          },
          {
            "name": "pageSize",
            "required": false,
            "in": "query",
            "description": "Items per page. A positive integer, maximum 500 (a larger value is rejected with 400). Anything that is not a positive integer is treated as absent and the default applies.",
            "schema": {
              "minimum": 1,
              "maximum": 500,
              "default": 10,
              "example": 50,
              "type": "number"
            }
          },
          {
            "name": "ids",
            "required": false,
            "in": "query",
            "description": "Fetch exactly these rows by id (integers). Overrides `search`, `filterModel`, `sortModel`, `page`/`pageSize` and `cursor`; the answer then carries `list` and `total` only (no `nextCursor`). Accepted on the wire as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a JSON array (`ids=[\"1\",\"2\"]`).",
            "schema": {
              "example": [
                "1042",
                "1043"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "addRelations",
            "required": false,
            "in": "query",
            "description": "Extra relations to join into each row. Only relations on the endpoint's server-side allowlist are accepted (on the public document lists that is the creator, already included); any other name answers 400 `invalid_request`. Integrators normally omit it.",
            "schema": {
              "example": [
                "client"
              ],
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "sortModel",
            "required": false,
            "in": "query",
            "description": "Sort order as a URL-encoded JSON array of `{ field, direction }` (query parameter name is `sortModel`, not `sort`). `field` is a column of the row (a dotted relation path is allowed); an unknown field, or a `direction` other than `ASC`/`DESC`, answers 400 `invalid_request`. Invoices also sort by the computed columns `cost`, `remaining` and `creditNotes`. Unparseable JSON, or omitting the parameter, falls back to the default order (document number descending on the document lists). Cursor paging is only available for a single plain-column sort; with a computed column the server pages by `page`/`pageSize` and returns no `nextCursor`.",
            "schema": {
              "example": "[{\"field\":\"issueDate\",\"direction\":\"DESC\"}]",
              "type": "string"
            }
          },
          {
            "name": "filterModel",
            "required": false,
            "in": "query",
            "description": "Filters as a URL-encoded JSON object `{ items: [{ field, operator, value }] }` (query parameter name is `filterModel`, not `filter`); items are ANDed. `operator` is one of `contains`, `doesnotcontain`, `equals`, `is`, `=`, `!=`, `<>`, `doesnotequal`, `not`, `isoneof`, `startswith`, `endswith`, `before`, `after`, `onorbefore`, `onorafter`, `>`, `<`, `>=`, `<=`; an unknown field or operator answers 400 `invalid_request`. Invoices also filter the computed columns `cost`, `remaining` and `creditNotes` with the numeric operators only. Anything that is not a JSON object collapses to \"no filters\".",
            "schema": {
              "example": "{\"items\":[{\"field\":\"status\",\"operator\":\"equals\",\"value\":\"PAID\"}]}",
              "type": "string"
            }
          },
          {
            "name": "search",
            "required": false,
            "in": "query",
            "description": "Search, max 100 characters. On invoice, advance invoice, credit note, price offer and income document lists the text is split into words (first 5 used, each max 40 chars) and EVERY word must match — case- and diacritics-insensitive (\"kovac\" finds \"Kováč\"), words of 4+ letters also tolerate small typos. Matched fields: the number, the payment symbols, IBAN/BIC and any `sender`/`recipient` company field (name, address, email, phone, ico, dic, icDph, court); a numeric word also matches the issue date and the total. Item names are not searched. Other lists: case-insensitive substring search. A leading document-type prefix is stripped when it stands alone or is followed by a space, dash, slash or digit (`FA 2025`, `FA2025`; `FA` invoice, `ZA` advance invoice, `DB` credit note, `CP` price offer, `PD` income document); such a prefix that belongs to a different resource returns an empty list. A word that merely starts with those letters (\"Zahradník\") is searched as text.",
            "schema": {
              "maxLength": 100,
              "example": "kovac bratislava",
              "type": "string"
            }
          },
          {
            "name": "archived",
            "required": false,
            "in": "query",
            "description": "Accepted but **not applied** by the list endpoints today: archived documents are returned either way (their `status` is `archived`). To exclude or isolate them filter on `status` with `filterModel`.",
            "schema": {
              "example": "false",
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "required": false,
            "in": "query",
            "description": "Opaque token: pass back unchanged the `nextCursor` of the previous response (it is base64 text; do not build or parse it). When present it replaces `page`. It is only valid for the same `sortModel`/filters it was issued for; with a computed-column sort it is ignored and `page` applies.",
            "schema": {
              "example": "eyJpZCI6MTA0Mn0=",
              "type": "string"
            }
          },
          {
            "name": "index",
            "required": false,
            "in": "query",
            "description": "Add the per-status aggregates to the response: `d.data.count` (rows per status) and `d.data.amount` (summed `totalPrice` per status), over the whole account, ignoring the other filters; invoices also add `d.data.tabCounts`. It does not change the rows (list rows never carry `fields`) and is ignored with `shortList`. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          },
          {
            "name": "shortList",
            "required": false,
            "in": "query",
            "description": "Invoices only: collapse each row to `{ id, number, sender, recipient, issueDate }` for a picker. The other document lists ignore it. Truthy values: `1`, `true`, `yes`, `y`, `on`.",
            "schema": {
              "example": false,
              "type": "boolean"
            }
          },
          {
            "name": "tab",
            "required": false,
            "in": "query",
            "description": "Derived payment tab. Narrows the result set on top of any other filter. `unpaid` = issued and not settled, `overdue` = `unpaid` with a due date before today (Europe/Bratislava calendar day). Omitted behaves exactly as before; `status=` filters keep working unchanged.",
            "schema": {
              "example": "unpaid",
              "enum": [
                "unpaid",
                "overdue"
              ],
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope. `d.data.list` is the page of rows; `d.data.total` is the unpaginated match count.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "object",
                          "required": [
                            "data"
                          ],
                          "properties": {
                            "data": {
                              "allOf": [
                                {
                                  "$ref": "#/components/schemas/ApiListMeta"
                                },
                                {
                                  "type": "object",
                                  "required": [
                                    "list"
                                  ],
                                  "properties": {
                                    "list": {
                                      "type": "array",
                                      "items": {
                                        "$ref": "#/components/schemas/AdvanceInvoiceListItemDto"
                                      }
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_sender",
                            "invoice_invalid_recipient",
                            "advance_invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "List advance invoices",
        "tags": [
          "Advance invoices"
        ]
      },
      "delete": {
        "description": "Archives documents by default — they leave every list but the rows and their PDFs are kept. Pass `purge=true` to delete them permanently; that cannot be undone.",
        "operationId": "advance_invoice_delete",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "ids",
            "required": true,
            "in": "query",
            "description": "Ids to act on. Accepted as CSV (`ids=1,2,3`), a repeated param (`ids[]=1&ids[]=2`) or a single value. An empty or unparseable value answers 422 (`no_ids_provided` / `invalid_ids`).",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "purge",
            "required": false,
            "in": "query",
            "description": "Hard-delete instead of archive. Truthy values: `true`, `1`.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentDeleteResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_sender",
                            "invoice_invalid_recipient",
                            "advance_invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Archive or purge advance invoices",
        "tags": [
          "Advance invoices"
        ]
      }
    },
    "/account/{accountId}/advanceInvoice/latestNumber": {
      "get": {
        "description": "Returns the highest document number currently used in this account, as a string. Use it to show the next number in a UI — do **not** use it to allocate one: creating a document without `number` lets the server continue the series atomically, which this read cannot do.",
        "operationId": "advance_invoice_latest_number",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "string",
                          "example": "20260042"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_sender",
                            "invoice_invalid_recipient",
                            "advance_invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get the highest advance invoice number in use",
        "tags": [
          "Advance invoices"
        ]
      }
    },
    "/account/{accountId}/advanceInvoice/{id}": {
      "get": {
        "description": "Returns one document including its line items.",
        "operationId": "advance_invoice_get",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/AdvanceInvoiceDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_sender",
                            "invoice_invalid_recipient",
                            "advance_invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get one advance invoice",
        "tags": [
          "Advance invoices"
        ]
      },
      "put": {
        "description": "Updates a document. Properties are merged, never replaced: an omitted property keeps its stored value. Unknown properties are dropped by the service allowlist rather than rejected, so a typo in a property name fails silently — check the response. Accepts `multipart/form-data` as well as `application/json`. In multipart form the document properties are ordinary form fields and the optional `logo` / `signature` / `stamp` parts carry image files (one each). Send JSON unless you are uploading an image.",
        "operationId": "advance_invoice_update",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AdvanceInvoiceUpdateDto"
              }
            },
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/AdvanceInvoiceUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated document.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/AdvanceInvoiceDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_sender",
                            "invoice_invalid_recipient",
                            "advance_invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Update an advance invoice",
        "tags": [
          "Advance invoices"
        ]
      }
    },
    "/account/{accountId}/advanceInvoice/{id}/pdf": {
      "get": {
        "description": "Returns the rendered PDF as a binary body — **not** the `{ s, d, t }` envelope.\n\nErrors **are** enveloped: a failure answers `{ \"s\": \"error\", \"d\": \"<alias>\", \"t\": … }` with the status that alias maps to (401 for a bad key, 403 for a key bound to another account, 404 for an unknown id), never a bare `{ \"error\": … }` body and never an exception message.\n\nRendering is asynchronous: while it is still running the response is **202** with that same error envelope and the alias `pdf_is_loading` — retry after a short delay.",
        "operationId": "advance_invoice_pdf",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "fallback",
            "required": false,
            "in": "query",
            "description": "Serve a simplified fallback rendering when the full template fails. `true` to allow.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The rendered PDF.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "202": {
            "description": "The PDF is still being rendered. Retry after a short delay — the render was started, so a retry is expected to succeed rather than repeat this answer.\n\nThe body **is** the ordinary error envelope, with the alias `pdf_is_loading`:\n\n```json\n{ \"s\": \"error\", \"d\": \"pdf_is_loading\", \"t\": \"2026-10-04T09:21:44.512Z\" }\n```\n\nBranch on the **status**, not on `s`: 202 is a wait, not a failure. (Before UC-227 this status was unreachable — the alias was unmapped and a rendering PDF answered 500 with a non-envelope body.)",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "pdf_is_loading"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_sender",
                            "invoice_invalid_recipient",
                            "advance_invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Download the advance invoice PDF",
        "tags": [
          "Advance invoices"
        ]
      }
    },
    "/account/{accountId}/advanceInvoice/{id}/send": {
      "post": {
        "description": "Renders the PDF server-side and e-mails it. The response carries **no** `d` — only `s` and `t`. Not idempotent: a repeated call sends another e-mail.",
        "operationId": "advance_invoice_send",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentSendDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Acknowledgement envelope. `d` is absent on this operation — only `s` and `t` are sent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiOkEnvelope"
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_sender",
                            "invoice_invalid_recipient",
                            "advance_invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "E-mail the advance invoice",
        "tags": [
          "Advance invoices"
        ]
      }
    },
    "/account/{accountId}/advanceInvoice/{id}/status": {
      "put": {
        "description": "Sets the lifecycle status of one document. Returns the stored status as a bare string in `d`, not the whole document.",
        "operationId": "advance_invoice_set_status",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the document.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentStatusUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The status now stored.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "paid",
                            "draft",
                            "processing",
                            "archived",
                            "overdue",
                            "cancelled",
                            "closed",
                            "settled"
                          ],
                          "example": "paid"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_invalid_fields",
                            "invoice_invalid_number",
                            "invoice_invalid_issue_date",
                            "invoice_invalid_due_date",
                            "invoice_invalid_sender",
                            "invoice_invalid_recipient",
                            "advance_invoice_invalid_iban",
                            "invalid_ids",
                            "no_ids_provided",
                            "email_missing",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "document_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "document_duplicate_number"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Set the advance invoice status",
        "tags": [
          "Advance invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/{id}/payments": {
      "get": {
        "description": "Returns the payment history of one invoice together with what is due, paid and remaining.\n\nRequest bodies are validated strictly: an unknown property is rejected, not dropped. Rate limited to 60 requests per 60 s and 600 per hour (429, see the response).",
        "operationId": "invoice_payment_list",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the invoice.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The invoice's payment state after the call: totals, status and the full list of payments.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentPaymentsResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_body",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. This route is guarded by the framework's stock throttler, so the body is NOT the usual envelope: branch on the status. The `Retry-After` header says how many seconds to wait.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "statusCode": {
                      "type": "integer",
                      "enum": [
                        429
                      ]
                    },
                    "message": {
                      "type": "string",
                      "example": "ThrottlerException: Too Many Requests"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "List payments of an invoice",
        "tags": [
          "Invoices"
        ]
      },
      "post": {
        "description": "Adds a payment to the invoice in one transaction and re-derives its status from the payments. Answers **200**, not 201.\n\nRequest bodies are validated strictly: an unknown property is rejected, not dropped. Rate limited to 60 requests per 60 s and 600 per hour (429, see the response).",
        "operationId": "invoice_payment_create",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the invoice.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentPaymentCreateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The invoice's payment state after the call: totals, status and the full list of payments.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentPaymentsResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_body",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. This route is guarded by the framework's stock throttler, so the body is NOT the usual envelope: branch on the status. The `Retry-After` header says how many seconds to wait.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "statusCode": {
                      "type": "integer",
                      "enum": [
                        429
                      ]
                    },
                    "message": {
                      "type": "string",
                      "example": "ThrottlerException: Too Many Requests"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Record a payment on an invoice",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/invoice/{id}/payments/{paymentId}": {
      "patch": {
        "description": "Changes only the properties sent. Re-derives the document status.\n\nRequest bodies are validated strictly: an unknown property is rejected, not dropped. Rate limited to 60 requests per 60 s and 600 per hour (429, see the response).",
        "operationId": "invoice_payment_update",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the invoice.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "paymentId",
            "required": true,
            "in": "path",
            "description": "Payment id (decimal string) from `payments[].id`.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{1,20}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentPaymentUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The invoice's payment state after the call: totals, status and the full list of payments.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentPaymentsResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_body",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.\n\nFor this operation the only alias is `conflict`: the payment is bank-confirmed (`source: \"openBanking\"`) and its `amount` cannot be changed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "conflict"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. This route is guarded by the framework's stock throttler, so the body is NOT the usual envelope: branch on the status. The `Retry-After` header says how many seconds to wait.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "statusCode": {
                      "type": "integer",
                      "enum": [
                        429
                      ]
                    },
                    "message": {
                      "type": "string",
                      "example": "ThrottlerException: Too Many Requests"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Edit a payment of an invoice",
        "tags": [
          "Invoices"
        ]
      },
      "delete": {
        "description": "Removes the payment and re-derives the document status. Returns the remaining state.\n\nRequest bodies are validated strictly: an unknown property is rejected, not dropped. Rate limited to 60 requests per 60 s and 600 per hour (429, see the response).",
        "operationId": "invoice_payment_delete",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the invoice.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "paymentId",
            "required": true,
            "in": "path",
            "description": "Payment id (decimal string) from `payments[].id`.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{1,20}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The invoice's payment state after the call: totals, status and the full list of payments.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentPaymentsResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_body",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invoice_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. This route is guarded by the framework's stock throttler, so the body is NOT the usual envelope: branch on the status. The `Retry-After` header says how many seconds to wait.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "statusCode": {
                      "type": "integer",
                      "enum": [
                        429
                      ]
                    },
                    "message": {
                      "type": "string",
                      "example": "ThrottlerException: Too Many Requests"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Delete a payment of an invoice",
        "tags": [
          "Invoices"
        ]
      }
    },
    "/account/{accountId}/advanceInvoice/{id}/payments": {
      "get": {
        "description": "Returns the payment history of one advance invoice together with what is due, paid and remaining.\n\nRequest bodies are validated strictly: an unknown property is rejected, not dropped. Rate limited to 60 requests per 60 s and 600 per hour (429, see the response).",
        "operationId": "advance_invoice_payment_list",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the advance invoice.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The advance invoice's payment state after the call: totals, status and the full list of payments.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentPaymentsResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_body",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. This route is guarded by the framework's stock throttler, so the body is NOT the usual envelope: branch on the status. The `Retry-After` header says how many seconds to wait.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "statusCode": {
                      "type": "integer",
                      "enum": [
                        429
                      ]
                    },
                    "message": {
                      "type": "string",
                      "example": "ThrottlerException: Too Many Requests"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "List payments of an advance invoice",
        "tags": [
          "Advance invoices"
        ]
      },
      "post": {
        "description": "Adds a payment to the advance invoice in one transaction and re-derives its status from the payments. Answers **200**, not 201.\n\nRequest bodies are validated strictly: an unknown property is rejected, not dropped. Rate limited to 60 requests per 60 s and 600 per hour (429, see the response).",
        "operationId": "advance_invoice_payment_create",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the advance invoice.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentPaymentCreateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The advance invoice's payment state after the call: totals, status and the full list of payments.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentPaymentsResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_body",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. This route is guarded by the framework's stock throttler, so the body is NOT the usual envelope: branch on the status. The `Retry-After` header says how many seconds to wait.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "statusCode": {
                      "type": "integer",
                      "enum": [
                        429
                      ]
                    },
                    "message": {
                      "type": "string",
                      "example": "ThrottlerException: Too Many Requests"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Record a payment on an advance invoice",
        "tags": [
          "Advance invoices"
        ]
      }
    },
    "/account/{accountId}/advanceInvoice/{id}/payments/{paymentId}": {
      "patch": {
        "description": "Changes only the properties sent. Re-derives the document status.\n\nRequest bodies are validated strictly: an unknown property is rejected, not dropped. Rate limited to 60 requests per 60 s and 600 per hour (429, see the response).",
        "operationId": "advance_invoice_payment_update",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the advance invoice.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "paymentId",
            "required": true,
            "in": "path",
            "description": "Payment id (decimal string) from `payments[].id`.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{1,20}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DocumentPaymentUpdateDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The advance invoice's payment state after the call: totals, status and the full list of payments.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentPaymentsResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_body",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The request was well formed and the caller is not at fault — the state of the world is the refusal. `document_duplicate_number` means that number is already used in this account; omit `number` entirely and the server continues the series atomically.\n\nFor this operation the only alias is `conflict`: the payment is bank-confirmed (`source: \"openBanking\"`) and its `amount` cannot be changed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "conflict"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. This route is guarded by the framework's stock throttler, so the body is NOT the usual envelope: branch on the status. The `Retry-After` header says how many seconds to wait.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "statusCode": {
                      "type": "integer",
                      "enum": [
                        429
                      ]
                    },
                    "message": {
                      "type": "string",
                      "example": "ThrottlerException: Too Many Requests"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Edit a payment of an advance invoice",
        "tags": [
          "Advance invoices"
        ]
      },
      "delete": {
        "description": "Removes the payment and re-derives the document status. Returns the remaining state.\n\nRequest bodies are validated strictly: an unknown property is rejected, not dropped. Rate limited to 60 requests per 60 s and 600 per hour (429, see the response).",
        "operationId": "advance_invoice_payment_delete",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Id of the advance invoice.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "paymentId",
            "required": true,
            "in": "path",
            "description": "Payment id (decimal string) from `payments[].id`.",
            "schema": {
              "type": "string",
              "pattern": "^[0-9]{1,20}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The advance invoice's payment state after the call: totals, status and the full list of payments.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/DocumentPaymentsResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_body",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "advance_invoice_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. This route is guarded by the framework's stock throttler, so the body is NOT the usual envelope: branch on the status. The `Retry-After` header says how many seconds to wait.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "statusCode": {
                      "type": "integer",
                      "enum": [
                        429
                      ]
                    },
                    "message": {
                      "type": "string",
                      "example": "ThrottlerException: Too Many Requests"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Delete a payment of an advance invoice",
        "tags": [
          "Advance invoices"
        ]
      }
    },
    "/account/{accountId}/receipt": {
      "post": {
        "description": "Stores an eKasa receipt or a hand-written `paragón`. Look the eKasa receipt up with `receipt_find` first — it also tells you whether the account already has it. Answers **200**, not 201.",
        "operationId": "receipt_create",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Sent as `multipart/form-data`, not JSON. The `receiptData` part is a **JSON string** whose parsed shape is `ReceiptWriteDto`. Up to 10 further parts are attachment files; each file's basename (without extension) is used as its attachment reference id.",
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "receiptData"
                ],
                "properties": {
                  "receiptData": {
                    "type": "string",
                    "description": "JSON-encoded `ReceiptWriteDto`.",
                    "example": "{\"receiptId\":\"O-0A1B…\",\"totalPrice\":11.98,\"items\":[]}"
                  },
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    },
                    "description": "Up to 10 attachment files."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The stored receipt, with its attachments.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/ReceiptDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "receipt_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Store a receipt",
        "tags": [
          "Receipts"
        ]
      },
      "get": {
        "description": "Returns a page of receipts plus an aggregate `stats` block. Note the envelope shape: `d.data.list`, `d.data.total` and `d.data.stats` — receipts carry `stats` where the document resources carry `nextCursor`.",
        "operationId": "receipt_list",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "shortList",
            "required": false,
            "in": "query",
            "description": "Accepted but has **no effect** on receipts (no reduced projection exists).",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "archived",
            "required": false,
            "in": "query",
            "description": "Accepted but **not applied** by the list today; filter on the `archived` column with `filterModel` instead.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "required": false,
            "in": "query",
            "description": "Case-insensitive substring search across every stored column of the receipt (each cast to text), e.g. organisation, eKasa identifier, amounts, dates.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "filterModel",
            "required": false,
            "in": "query",
            "description": "URL-encoded JSON object `{ items: [{ field, operator, value }] }`, items ANDed; the parameter is `filterModel`, not `filter`. Operators: `contains`, `doesnotcontain`, `equals`, `is`, `=`, `!=`, `<>`, `doesnotequal`, `not`, `isoneof`, `startswith`, `endswith`, `before`, `after`, `onorbefore`, `onorafter`, `>`, `<`, `>=`, `<=`; an unknown field or operator answers 400 `invalid_request`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sortModel",
            "required": false,
            "in": "query",
            "description": "URL-encoded JSON array of `{ field, direction }` (`ASC`/`DESC`); the parameter is `sortModel`, not `sort`. An unknown field or direction answers 400 `invalid_request`; unparseable JSON falls back to the default order.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ids",
            "required": false,
            "in": "query",
            "description": "Fetch exactly these rows by id (integers). Overrides `search`, `filterModel`, `sortModel` and paging. CSV (`ids=1,2`), repeated (`ids[]=1&ids[]=2`) or a JSON array.",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "name": "pageSize",
            "required": false,
            "in": "query",
            "description": "Items per page, 1-500 (default 10). A larger value is rejected with 400; a value that is not a positive integer is treated as absent.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 10
            }
          },
          {
            "name": "page",
            "required": false,
            "in": "query",
            "description": "Zero-based page index. Ignored when `cursor` is supplied.",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "`d.data.list` is the page of receipts and `d.data.stats` the aggregate block. `nextCursor`, `count` and `amount` are **not** returned on this resource.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "type": "object",
                          "required": [
                            "data"
                          ],
                          "properties": {
                            "data": {
                              "allOf": [
                                {
                                  "$ref": "#/components/schemas/ApiListMeta"
                                },
                                {
                                  "type": "object",
                                  "required": [
                                    "list"
                                  ],
                                  "properties": {
                                    "list": {
                                      "type": "array",
                                      "items": {
                                        "$ref": "#/components/schemas/ReceiptDto"
                                      }
                                    },
                                    "stats": {
                                      "$ref": "#/components/schemas/ReceiptStatsDto"
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "receipt_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "List receipts",
        "tags": [
          "Receipts"
        ]
      }
    },
    "/account/{accountId}/receipt/{receiptId}": {
      "put": {
        "description": "Merge update. Attachments are reconciled against the files sent: a stored attachment whose URL is absent from this request is removed.",
        "operationId": "receipt_update",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "receiptId",
            "required": true,
            "in": "path",
            "description": "Numeric `id` of the stored receipt — **not** the eKasa `receiptId` string.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Sent as `multipart/form-data`, not JSON. The `receiptData` part is a **JSON string** whose parsed shape is `ReceiptWriteDto`. Up to 10 further parts are attachment files; each file's basename (without extension) is used as its attachment reference id.",
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "receiptData"
                ],
                "properties": {
                  "receiptData": {
                    "type": "string",
                    "description": "JSON-encoded `ReceiptWriteDto`.",
                    "example": "{\"receiptId\":\"O-0A1B…\",\"totalPrice\":11.98,\"items\":[]}"
                  },
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    },
                    "description": "Up to 10 attachment files."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated receipt.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/ReceiptDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "receipt_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Update a receipt",
        "tags": [
          "Receipts"
        ]
      },
      "delete": {
        "description": "Archives by default. `d` reports which happened: `{ id, archived: true }` or, with `purge=true`, `{ id, purged: true }` — the two keys are mutually exclusive and only the applicable one is present.",
        "operationId": "receipt_delete",
        "parameters": [
          {
            "name": "receiptId",
            "required": true,
            "in": "path",
            "description": "Numeric `id` of the stored receipt.",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "purge",
            "required": false,
            "in": "query",
            "description": "Hard-delete instead of archive. Only the literal `true` enables it.",
            "schema": {
              "type": "string",
              "default": "false"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/ReceiptDeleteResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "receipt_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Archive or purge a receipt",
        "tags": [
          "Receipts"
        ]
      }
    },
    "/account/{accountId}/receipt/export": {
      "get": {
        "description": "Returns a binary body, **not** the `{ s, d, t }` envelope. Declared before `:id`, so `export` is never read as a receipt id.",
        "operationId": "receipt_export",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "ids",
            "required": true,
            "in": "query",
            "description": "Comma-separated receipt ids to include.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "provider",
            "required": false,
            "in": "query",
            "description": "Export format. `ZIP` bundles the receipts; `XML` emits an accounting feed.",
            "schema": {
              "type": "string",
              "enum": [
                "ZIP",
                "XML"
              ],
              "default": "ZIP"
            }
          },
          {
            "name": "translations",
            "required": false,
            "in": "query",
            "description": "JSON-encoded label overrides for the generated file.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The export archive or XML document.",
            "content": {
              "application/zip": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "receipt_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Export receipts as ZIP or XML",
        "tags": [
          "Receipts"
        ]
      }
    },
    "/account/{accountId}/receipt/find/{receiptId}": {
      "get": {
        "description": "Queries the Slovak eKasa service for a receipt by its printed identifier and reports whether this account already stored it. Rate-limited to 20 calls per 60 s per caller because it makes an outbound request to Finančná správa — expect 429 above that.",
        "operationId": "receipt_find",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "receiptId",
            "required": true,
            "in": "path",
            "description": "The eKasa receipt identifier printed on the receipt (an `O-…` string), not a stored id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/ReceiptLookupResultDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "receipt_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Too many calls to this route in the current window. The envelope carries the alias `rate_limit_exceeded` plus `retryAfterSeconds`, and the `Retry-After` header repeats it — wait that long rather than retrying immediately.\n\nNote for browser clients: `Retry-After` is not a CORS-safelisted response header, which is why the interval is in the body as well.",
            "headers": {
              "Retry-After": {
                "description": "Whole seconds to wait before retrying.",
                "schema": {
                  "type": "integer",
                  "example": 42
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "rate_limit_exceeded"
                          ]
                        },
                        "retryAfterSeconds": {
                          "type": "integer",
                          "description": "Whole seconds until the window resets.",
                          "example": 42
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Look a receipt up in eKasa",
        "tags": [
          "Receipts"
        ]
      }
    },
    "/account/{accountId}/receipt/{id}": {
      "get": {
        "description": "Returns the receipt with its items and attachments, or `null` in `d`.",
        "operationId": "receipt_get",
        "parameters": [
          {
            "name": "accountId",
            "required": true,
            "in": "path",
            "description": "The account the document belongs to: either the numeric account id or the account's `publicId` string (the id in the web app URL). Must be the account the API key was issued for — a key used against another account answers 403 `api_key_account_mismatch`.",
            "schema": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string"
                }
              ]
            }
          },
          {
            "name": "id",
            "required": true,
            "in": "path",
            "description": "Numeric `id` of the stored receipt.",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The receipt. `d` is `null` when no such receipt exists in this account.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiOkEnvelope"
                    },
                    {
                      "type": "object",
                      "required": [
                        "d"
                      ],
                      "properties": {
                        "d": {
                          "$ref": "#/components/schemas/ReceiptDto"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Rejected input. The alias names what was refused — a field that failed validation, a malformed or empty `ids` query on a bulk operation, a missing recipient on `send`, or a rejected attachment. No retry of the same request changes the answer.\n\nUC-227: these answered **500** before, because their aliases were unmapped. That contradicted this spec, which has promised a 4xx for rejected input since `/v1` shipped.\n\nUC-992: on `invalid_request` the body also carries `details` — one entry per FAILING field (`{ field, rule, message }`), with no submitted value echoed back. Fields that validated are not listed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_ids",
                            "no_ids_provided",
                            "too_many_files",
                            "invalid_request"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "The `Authorization: Bearer` key is missing, malformed, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "invalid_api_key",
                            "api_key_expired",
                            "unauthorized"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but may not do this: `insufficient_permissions_api_key` when its permission bitfield does not cover the operation, `api_key_account_mismatch` when the key is bound to an account other than the `accountId` in the path. UC-227: the second alias was unmapped and answered **500** until now, so the most common integration mistake looked like a server fault; it is a 403, as this text always claimed.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "insufficient_permissions_api_key",
                            "api_key_account_mismatch"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No such record in this account. The same alias is returned for a foreign id as for a non-existent one, so the route is not an id oracle.\n\nUC-227: also a 500 until now. Each resource has its own alias so a bulk call can say *which* id missed; branch on the alias, not on the status.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "receipt_not_found",
                            "resource_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "An uploaded attachment is larger than the per-file limit.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "file_too_large"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "description": "A genuine server fault. Every ordinary client mistake on these routes now has its own 4xx (UC-227 mapped the document aliases that used to land here), so a 500 means something broke on our side and an idempotent read is safe to retry.\n\n`account_not_found` appears here rather than at 404 deliberately: on these routes it is only reachable after the key has already been authorised for the account, so it signals a broken server invariant, not a bad `accountId` — a wrong `accountId` is the 403 `api_key_account_mismatch` above.",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/ApiErrorEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "d": {
                          "type": "string",
                          "enum": [
                            "internal_server_error",
                            "account_not_found"
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "summary": "Get one receipt",
        "tags": [
          "Receipts"
        ]
      }
    }
  },
  "info": {
    "title": "Účtovisko Public API",
    "description": "Public API of Účtovisko for third-party integrations. It covers the\nsix document resources: invoices, receipts, credit notes, advance invoices, price offers and\nincome documents, plus the payment history of invoices and advance invoices and the invoice\nsummary.\n\n## Authentication\n\nSend the account's API key as an HTTP bearer token:\n\n```\nAuthorization: Bearer uk_live_<publicId>_<secret>\n```\n\nKeys are created per account in *Nastavenia → API*. The secret is shown once at creation; only a\nmasked prefix is retrievable afterwards. A key is bound to one account — using it against a\ndifferent `accountId` is a 403 (`api_key_account_mismatch`), not a 404. An expired key answers\n`api_key_expired`, a revoked or unknown one `invalid_api_key`.\n\nTwo independent checks decide whether a valid key may call an operation, and the key needs both:\n\n- **Scope.** `read` allows `GET`, `HEAD` and `OPTIONS`; `write` allows every other\n  method and implies `read`. New keys default to `read` only; keys created before scopes\n  existed have both. The scope is chosen when the key is created.\n- **Permission bit.** The key carries a permission bitfield, set when the key is created and\n  bounded by the permissions of the user who created it. Each operation needs the bit of its\n  resource: `<RESOURCE>_READ` for lists and reads, `<RESOURCE>_WRITE` for create, update,\n  delete, status change and send, with `<RESOURCE>` one of `INVOICES`, `RECEIPTS`,\n  `CREDIT_NOTES`, `ADVANCE_INVOICES`, `PRICE_OFFERS`, `INCOME_DOCUMENTS`. Some download\n  routes check a further `<RESOURCE>_DOWNLOAD` bit (for example `ADVANCE_INVOICES_DOWNLOAD`).\n\nA key that fails either check is refused with 403 `insufficient_permissions_api_key`; the\nalias does not say which of the two failed. Operations carry no machine-readable permission\nannotation — the mapping above is the contract.\n\nThere is no OAuth flow and no refresh. A key is a long-lived credential: keep it server-side.\n\n## Response envelope\n\n**Every** JSON response — success and failure alike — is the same three-key envelope:\n\n```json\n{ \"s\": \"ok\", \"d\": { \"id\": 1042 }, \"t\": \"2026-10-04T09:21:44.512Z\" }\n{ \"s\": \"error\", \"d\": \"invalid_api_key\", \"t\": \"2026-10-04T09:21:44.512Z\" }\n```\n\n- `s` is `\"ok\"` or `\"error\"` and is the **only** field to branch on. Do not test for the\n  presence of `d`: it is populated on both branches.\n- `d` carries the payload on success and a single lowercase snake_case **error alias** on\n  failure. It is never a message object and never a stack trace — treat an unrecognised alias as a\n  generic failure of the response's HTTP class.\n- `t` is the server timestamp, ISO-8601.\n\nOne documented exception, deliberate:\n\n- **PDF, ZIP and XML downloads** return a binary body with no envelope **on success**. Their\n  *failures* are enveloped like everywhere else — including the **202** that\n  `advanceInvoice`, `creditnote` and `incomeDocument` answer while a render is still in\n  flight, which carries `{ \"s\": \"error\", \"d\": \"pdf_is_loading\", \"t\": … }`. Branch on the\n  status there: 202 means retry shortly, not failure. The `invoice` and `priceoffer` PDF\n  routes never answer 202.\n\n`POST …/{id}/send` is **not** an exception, contrary to what this document said before\nUC-227: `invoice_send` returns a populated `d` (an `InvoiceSendResultDto`, with the\ndelivery outcome). The other five send operations are the ones that answer\n`{ \"s\": \"ok\", \"t\": … }` with no `d` — and each operation's own response schema says which,\nso read that rather than assuming a shared shape.\n\n### Statuses\n\nBranch on the HTTP status first and read `d` to find out *which* failure it was:\n\n| status | meaning |\n|---|---|\n| 400 | rejected input — a field failed validation, a bad `ids` query, a missing recipient |\n| 401 | the key is missing, malformed, revoked or expired |\n| 403 | the key is valid but lacks the permission, or is bound to another `accountId` |\n| 404 | no such record in this account (the alias names the resource) |\n| 409 | the document number is already used — omit `number` and the server allocates one; on a payment edit, `conflict` (a bank-confirmed payment's amount cannot change) |\n| 413 | an attachment is over the per-file limit |\n| 429 | a rate limit or an eFaktúra sending allowance is exhausted |\n| 500 | a genuine server fault; an idempotent read is safe to retry |\n\nA 500 really does mean our side broke: UC-227 moved every caller-fixable document alias onto its\nproper 4xx, so there are no ordinary client mistakes left in the 5xx class. Each operation's\nresponse list enumerates the exact aliases it can return.\n\nCreates answer **200**, not 201.\n\n## Pagination\n\nDocument lists wrap the page one level deeper than you may expect:\n\n```json\n{ \"s\": \"ok\", \"d\": { \"data\": { \"list\": [ … ], \"total\": 128, \"nextCursor\": \"1042\" } }, \"t\": … }\n```\n\nRead the rows from `d.data.list` and the unpaginated match count from `d.data.total` —\n`d.list` does not exist.\n\nQuery parameters (each is described on the operation):\n\n- `page` (zero-based) and `pageSize` (default 10, **maximum 500** — a larger value is a 400).\n  A value that is not a usable positive integer is treated as *absent* and the default applies.\n- `sortModel` and `filterModel` — URL-encoded **JSON**, not `sort`/`filter`. Sort is\n  `[{\"field\":\"issueDate\",\"direction\":\"DESC\"}]`; filter is\n  `{\"items\":[{\"field\":\"status\",\"operator\":\"equals\",\"value\":\"paid\"}]}`. An unknown field or\n  operator is a 400 `invalid_request`; unparseable JSON is ignored. The default order is the\n  document number, newest first.\n- `search` — case-insensitive substring match over number, dates, sender/recipient fields,\n  payment symbols and total. `ids` — fetch exactly those rows; it overrides every other\n  parameter and returns no `nextCursor`.\n- `archived` is accepted but not applied: archived documents (`status` `archived`) are in the\n  list; filter on `status` to exclude them.\n- Invoices only: `tab` (derived tab such as `unpaid` or `overdue`), `number` (exact number\n  lookup) and `shortList=true` (picker projection `{ id, number, sender, recipient, issueDate }`).\n- `index=true` does not change the rows. It adds `d.data.count` and `d.data.amount` — row\n  count and summed `totalPrice` per status over the whole account — and, on invoices,\n  `d.data.tabCounts`. List rows never contain the line items (`fields`); fetch one document by\n  id for those. In list rows `totalPrice` is a JSON number, on the single-document endpoint it is\n  a decimal string.\n\nCursor paging: `d.data.nextCursor` is an **opaque token** (base64 text — it is not an id; ids\nare 32-bit integers). Send it back unchanged as `cursor` for the next page; when `cursor` is\nsupplied `page` is ignored, and the token is only valid for the same sort and filters it was issued\nfor. A page that has rows always carries a `nextCursor`, including the last one — stop when\n`list` is empty or shorter than `pageSize`. There is no `nextCursor` for `ids` lookups, for\nsorts on a computed column (`cost`, `remaining`, `creditNotes` on invoices — page with `page`\nthere) or for an empty page.\n\nOne resource differs, and the difference is not cosmetic: **receipts** return `d.data.stats`\n(aggregate totals) instead of `nextCursor`, so they page with `page`/`pageSize` only.\n\n## Numbers, dates and ids\n\nMoney is **not** uniformly typed, and a client has to cope with both forms:\n\n- Document totals and numbers (`totalPrice`, `number`, `invoicePrice`, …) come from Postgres\n  `decimal` columns and arrive as **strings** (`\"724.80\"`) on the single-document endpoints.\n  The driver does not narrow them to JS numbers, because that would lose precision. Parse them\n  with a decimal library, not `parseFloat`, if you do arithmetic. The one exception is\n  `totalPrice` in **list rows**, which the list endpoints convert to a JSON number.\n- Amounts inside the `fields` line-item blob, and every receipt amount, are JSON **numbers**\n  (the underlying columns are `jsonb` and `float`).\n\nDates are ISO-8601 strings. Ids are 32-bit integers, unique per document type — an invoice `12`\nand a receipt `12` are unrelated records.\n\n## Rate limiting\n\nA refused call answers **429**. Where the limiter is ours it uses the normal envelope plus a\nheader:\n\n```json\n{ \"s\": \"error\", \"d\": \"rate_limit_exceeded\", \"retryAfterSeconds\": 42, \"t\": \"2026-10-04T09:21:44.512Z\" }\n```\n\nwith `Retry-After: 42` (whole seconds) — wait that long before retrying. Documented limits:\n\n- `receipt_find`: **20 requests per 60 s** per caller (it makes an outbound call to the\n  Finančná správa eKasa service).\n- The invoice `summary` route: 30 requests per 60 s and 600 per hour.\n- The payments routes of invoices and advance invoices: 60 requests per 60 s and 600 per hour.\n\nThe payments routes are guarded by the framework's stock throttler, so their 429 body is\n`{ \"statusCode\": 429, \"message\": \"ThrottlerException: Too Many Requests\" }` rather than the\nenvelope; branch on the status. The `Retry-After` header is set there too.\n\nThe other document endpoints (list, get, create, update, delete, status, send, PDF) have **no**\nper-route limiter — the throttler guards are opt-in per route and are not registered globally. Do\nnot read that as a licence to hammer them: it is the current implementation, not a guarantee, and\na limiter may be added within `v1` (adding one is not a breaking change under the versioning\npolicy). Build backoff on 429 and 5xx now.\n\n## Webhooks\n\nÚčtovisko POSTs a JSON event to every webhook URL configured on an API key when a document of the\naccount is created, updated or deleted. Delivery is asynchronous: the API call that changed the\ndocument does not wait for your endpoint. Full reference: `https://uctovisko.sk/docs/api#/webhooky`\n(source `server/docs/webhooks.md`).\n\n### Setup\n\nAdd webhook URLs in the API key settings (Nastavenia → API → the key → Webhooky). The webhook\nsecret (`whsec_…`) is shown **once**: when a key is created with at least one URL, when the first\nURL is added to a key, or when the secret is rotated\n(`POST /account/{accountId}/api/keys/{id}/webhook-secret`; the old secret stops working at once).\nStore it server-side. Every webhook is signed; a key that has URLs but no secret gets **no**\ndeliveries (rotate to create one — earlier events are not re-sent).\n\n### Request\n\n`POST <your URL>`, `Content-Type: application/json`, `User-Agent: Uctovisko-Webhook-Service/1.0`\nand these headers:\n\n- `X-Webhook-Id` — UUID v4 of the event; stable across retries and shared by every URL of the\n  event. Dedupe on it.\n- `X-Webhook-Timestamp` — ISO-8601 time of this delivery attempt.\n- `X-Webhook-Signature` — `t=<unix seconds>,v1=<hex HMAC-SHA256>`.\n- `X-Webhook-Attempt` — 1-based attempt number (`1` on the first try).\n\nBody (`id` equals `X-Webhook-Id`; new fields may appear, ignore unknown ones):\n\n```json\n{\n  \"id\": \"6f1c0e8a-3b5d-4c47-9a7e-2f0d9b1e4a53\",\n  \"type\": \"create\",\n  \"data\": {\n    \"documentId\": 123,\n    \"documentType\": \"invoice\",\n    \"accountId\": 7,\n    \"timestamp\": \"2026-10-27T10:00:00.000Z\",\n    \"payload\": { \"...\": \"document data\" }\n  }\n}\n```\n\n### Event types\n\n- `type`: `create`, `update` or `delete`.\n- `documentType`: `invoice`, `advanceInvoice`, `incomeDocument`, `priceOffer`, `creditNote`,\n  `receipt`, `travelOrder`, `fulfillment`, `ride`, `vehicle`, `warehouseReceipt`,\n  `warehouseIssue`, `order`.\n- `ride` has no `delete` event.\n- `update` of `invoice` / `advanceInvoice`: `payload` holds only the changed fields.\n- `delete`: `payload` is `null` for `invoice` and `{ \"id\": … }` for every other type.\n\n### Verifying the signature\n\n1. Read the **raw** request body bytes, before any JSON parsing or re-serialisation.\n2. Split `X-Webhook-Signature` on `,`; take `t` (unix seconds) and `v1` (64 hex characters).\n3. Reject when `|now - t| > 300` seconds (5-minute tolerance, replay protection).\n4. Compute `HMAC-SHA256(secret, \"${t}.${rawBody}\")` — the decimal `t`, a dot, the raw body — as hex.\n5. Compare with `v1` in **constant time** (`crypto.timingSafeEqual`, PHP `hash_equals`); reject on\n   mismatch.\n6. Dedupe on `X-Webhook-Id`, then answer `2xx`.\n\nNode.js:\n\n```js\nconst crypto = require('node:crypto');\n\n// rawBody: unparsed request body (e.g. express.raw({ type: 'application/json' }))\nfunction verifyWebhook(rawBody, signatureHeader, secret, toleranceSec = 300) {\n  const parts = Object.fromEntries(\n    String(signatureHeader || '').split(',').map((p) => p.split('=', 2)),\n  );\n  const t = Number(parts.t);\n  if (!Number.isInteger(t) || !/^[0-9a-f]{64}$/.test(parts.v1 || '')) return false;\n  if (Math.abs(Math.floor(Date.now() / 1000) - t) > toleranceSec) return false;\n\n  const expected = crypto.createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();\n  const received = Buffer.from(parts.v1, 'hex');\n  return received.length === expected.length && crypto.timingSafeEqual(received, expected);\n}\n```\n\nPHP:\n\n```php\n<?php\nfunction verify_webhook(string $rawBody, string $signatureHeader, string $secret, int $toleranceSec = 300): bool {\n    $parts = [];\n    foreach (explode(',', $signatureHeader) as $p) {\n        $kv = explode('=', $p, 2);\n        if (count($kv) === 2) { $parts[$kv[0]] = $kv[1]; }\n    }\n    if (!isset($parts['t'], $parts['v1']) || !ctype_digit($parts['t']) || !preg_match('/^[0-9a-f]{64}$/', $parts['v1'])) {\n        return false;\n    }\n    $t = (int) $parts['t'];\n    if (abs(time() - $t) > $toleranceSec) { return false; }\n    $expected = hash_hmac('sha256', $t . '.' . $rawBody, $secret);\n    return hash_equals($expected, $parts['v1']);\n}\n\n$rawBody = file_get_contents('php://input');\n$ok = verify_webhook($rawBody, $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '', getenv('WEBHOOK_SECRET'));\nif (!$ok) { http_response_code(401); exit; }\n```\n\nTest vector — check your implementation against it. Secret `whsec_test_secret_0123456789abcdef`,\n`t = 1792576800`, body (exactly these bytes, no trailing newline):\n\n```\n{\"id\":\"6f1c0e8a-3b5d-4c47-9a7e-2f0d9b1e4a53\",\"type\":\"update\",\"data\":{\"documentId\":4812,\"documentType\":\"invoice\",\"accountId\":137,\"timestamp\":\"2026-10-27T10:00:00.000Z\",\"payload\":{\"note\":\"Test\"}}}\n```\n\nThe signed string is `1792576800.` followed by that body; the expected\n`v1` is `ea0704d8b5469043cff17e8382e5a055a05305b1f52fe9fe288b8ccf95c29a3a`, i.e. the header\n`X-Webhook-Signature: t=1792576800,v1=ea0704d8b5469043cff17e8382e5a055a05305b1f52fe9fe288b8ccf95c29a3a`.\n`t` is a fixed past value, so skip (or freeze the clock for) the 5-minute tolerance check when\nverifying this vector.\n\n### Delivery and retries\n\n- 5 s timeout per attempt, redirects are not followed, any `2xx` = delivered. Order of events is\n  not guaranteed; answer fast and work asynchronously.\n- Up to **5 attempts**: immediately, then after about 1 min, 5 min, 30 min and 2 h (each ±10 %);\n  then the delivery is dropped.\n- Retried on: no response / connection error, timeout, `5xx`, `408`, `429`. `Retry-After` is\n  honoured (never earlier than asked, capped at 2 h). Any other `4xx` and any `3xx` are **not**\n  retried.\n- Every attempt carries the byte-identical body and the same `X-Webhook-Id`; `X-Webhook-Timestamp`,\n  the signature `t` and `X-Webhook-Attempt` are fresh per attempt. A late success of an earlier\n  attempt can still arrive — **dedupe on `X-Webhook-Id`**.\n- Each attempt is signed with the key's current secret; retries stop when the key is revoked or\n  deleted, its secret is removed or the URL is removed.\n\n### URL rules\n\n`https://` only, no credentials in the URL, must resolve to public IP addresses (checked on save and\non every delivery), at most 10 URLs per API key.\n\n## Versioning\n\n`/v1` is the stable prefix; the unprefixed paths exist for backwards compatibility. Additive\nchanges (a new endpoint, a new optional property, a new enum value) ship inside `v1` without\nnotice, so **ignore properties you do not know** rather than failing on them. Removals and\nsemantic changes go through a deprecation window and a new major prefix.\n\nPolicy: `docs/api-versioning.md`. The machine-readable snapshot of this contract is committed at\n`server/openapi/v1.json` and served at `https://api.uctovisko.sk/v1/openapi.json`; an agent-oriented\nsummary lives at `https://uctovisko.sk/llms.txt` and `https://uctovisko.sk/llms-full.txt`.",
    "version": "1.0.0",
    "contact": {}
  },
  "tags": [],
  "servers": [
    {
      "url": "https://api.uctovisko.sk/v1",
      "description": "Produkcia"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "opaque",
        "description": "API key of the account, sent as `Authorization: Bearer uk_live_<publicId>_<secret>`. Keys are created per account in Nastavenia → API. The secret is shown once at creation; only a masked prefix is retrievable afterwards. The key is bound to one account and carries a scope (`read` or `write`) and a permission bitfield, so a valid key can still be refused for an individual operation (403 `insufficient_permissions_api_key`)."
      }
    },
    "schemas": {
      "ApiErrorEnvelope": {
        "type": "object",
        "properties": {
          "s": {
            "type": "string",
            "description": "Always `error` on a non-2xx response.",
            "enum": [
              "error"
            ],
            "example": "error"
          },
          "d": {
            "type": "string",
            "description": "Error alias — a single lowercase snake_case token, never free text and never a nested object (`sanitizeErrorPayload` enforces that). Unknown aliases must be handled as a generic failure of the response's HTTP class.",
            "enum": [
              "invalid_request",
              "invalid_api_key",
              "api_key_expired",
              "insufficient_permissions_api_key",
              "unauthorized",
              "not_found",
              "no_ids_provided",
              "invalid_ids",
              "email_missing",
              "internal_server_error"
            ],
            "example": "invalid_api_key"
          },
          "details": {
            "type": "array",
            "description": "UC-992 — present **only** on `400 invalid_request`, and only for the fields that FAILED DTO validation; a field that validated is never listed. Omitted entirely otherwise, so its absence is not a signal.\n\n`field` is the dotted path with bracketed array indexes (`items[0].vat`). `rule` is the stable validator token (`isIn`, `isNotEmpty`, `whitelistValidation` for an extra key) — branch on it rather than on `message`. `message` is short English for a human reader.\n\n**No submitted value is ever echoed back** (the body may carry personal data or credentials) and no server internal is named. At most 20 entries.",
            "maxItems": 20,
            "items": {
              "type": "object",
              "required": [
                "field",
                "rule",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string",
                  "example": "items[0].vat"
                },
                "rule": {
                  "type": "string",
                  "example": "isIn"
                },
                "message": {
                  "type": "string",
                  "example": "must be one of 0, 5, 10, 19, 23"
                }
              }
            },
            "example": [
              {
                "field": "items[0].vat",
                "rule": "isIn",
                "message": "must be one of 0, 5, 10, 19, 23"
              },
              {
                "field": "noVatReason",
                "rule": "isNotEmpty",
                "message": "required"
              },
              {
                "field": "foo",
                "rule": "whitelistValidation",
                "message": "unknown field"
              }
            ]
          },
          "t": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "s",
          "d",
          "t"
        ]
      },
      "ApiOkEnvelope": {
        "type": "object",
        "properties": {
          "s": {
            "type": "string",
            "description": "Outcome discriminator. Always `ok` on a 2xx response. Branch on this field, not on whether `d` is present — `d` is populated on both branches.",
            "enum": [
              "ok"
            ],
            "example": "ok"
          },
          "t": {
            "type": "string",
            "description": "Server timestamp of the response, ISO-8601 in UTC.",
            "format": "date-time",
            "example": "2026-10-04T09:21:44.512Z"
          }
        },
        "required": [
          "s",
          "t"
        ]
      },
      "DocumentUserDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "example": 42
          },
          "publicId": {
            "type": "string",
            "nullable": true,
            "description": "Unguessable external id. Use this in URLs and links, never `id`.",
            "example": "10871635410944"
          },
          "username": {
            "type": "string",
            "description": "Login identifier of the creator (an e-mail address).",
            "example": "jana@example.sk"
          },
          "settings": {
            "type": "object",
            "description": "Display fields only.",
            "properties": {
              "firstName": {
                "type": "string",
                "example": "Jana"
              },
              "lastName": {
                "type": "string",
                "example": "Kováčová"
              },
              "avatar": {
                "type": "string",
                "nullable": true,
                "example": null
              }
            }
          }
        },
        "required": [
          "id",
          "publicId",
          "username",
          "settings"
        ]
      },
      "DocumentFieldDto": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "description": "Item name as printed.",
            "example": "Konzultácie"
          },
          "description": {
            "type": "string",
            "description": "Longer description printed under the label. May be an empty string.",
            "example": "Analýza integrácie, 2026-09"
          },
          "quantity": {
            "type": "number",
            "example": 8
          },
          "unitPrice": {
            "type": "number",
            "description": "Unit price excluding VAT, in the document currency.",
            "example": 75.5
          },
          "vat": {
            "type": "number",
            "description": "VAT rate as a percentage (`20` = 20 %). Use `0` with `useVat: false`.",
            "example": 20
          },
          "unit": {
            "type": "string",
            "description": "Unit of measure as printed.",
            "example": "h"
          },
          "stockItemId": {
            "type": "string",
            "description": "Links the line to a warehouse stock item. When set on a receipt/issue the server also records a stock movement.",
            "example": "4812"
          }
        },
        "required": [
          "label",
          "description",
          "quantity",
          "unitPrice",
          "vat",
          "unit"
        ]
      },
      "CompanyDetailsDto": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Legal name.",
            "example": "Ultra Labs s. r. o."
          },
          "address": {
            "type": "string",
            "description": "Full address as one line, as entered.",
            "example": "Hlavná 12, 040 01 Košice"
          },
          "email": {
            "type": "string",
            "example": "fakturacia@example.sk"
          },
          "phone": {
            "type": "string",
            "example": "+421 900 000 000"
          },
          "ico": {
            "type": "number",
            "description": "IČO (company registration number) as a **number** — a leading zero is not preserved.",
            "example": 54321678
          },
          "dic": {
            "type": "number",
            "description": "DIČ (tax number) as a number.",
            "example": 2120123456
          },
          "icDph": {
            "type": "string",
            "description": "IČ DPH (VAT id) as a string, including the country prefix.",
            "example": "SK2120123456"
          },
          "court": {
            "type": "string",
            "description": "Commercial-register court note printed in the footer.",
            "example": "Okresný súd Košice I, oddiel Sro, vložka č. 12345/V"
          }
        },
        "required": [
          "name",
          "address",
          "email",
          "phone",
          "ico",
          "dic",
          "icDph"
        ]
      },
      "InvoicePeppolTaxReportingDto": {
        "type": "object",
        "properties": {
          "state": {
            "type": "string",
            "description": "Product-level outcome: `ok` = accepted with integrated result SUCCESS; `pending` = not reported yet / still in progress; `problem` = rejected, invalid, timed out, failed or an invoice/report mismatch.",
            "enum": [
              "ok",
              "pending",
              "problem"
            ],
            "example": "pending"
          },
          "status": {
            "type": "string",
            "nullable": true,
            "description": "Provider report status.",
            "example": "SENT"
          },
          "responseCode": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "integratedResult": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "respondedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        },
        "required": [
          "state",
          "status",
          "responseCode",
          "integratedResult",
          "respondedAt"
        ]
      },
      "InvoiceDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. **Omitted from list responses** — fetch the document by id to get them.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "totalPrice": {
            "type": "string",
            "description": "Computed grand total including VAT. A `decimal` column, therefore a **string** on the wire. `null` on a document with no priced lines.",
            "nullable": true,
            "example": "724.80"
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "dueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ],
            "nullable": true,
            "example": "banktransfer"
          },
          "customPM": {
            "type": "string",
            "description": "Label used when `paymentMethod` is `custom`.",
            "nullable": true,
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "description": "Delivery method. A free-form string is accepted beyond the listed values.",
            "nullable": true,
            "example": "email"
          },
          "IBAN": {
            "type": "string",
            "nullable": true,
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "nullable": true,
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string",
            "nullable": true,
            "example": "20260042"
          },
          "constantSymbol": {
            "type": "string",
            "nullable": true
          },
          "specificSymbol": {
            "type": "string",
            "nullable": true
          },
          "qrCode": {
            "type": "string",
            "description": "PAY-by-square payload string rendered as the payment QR code, not an image.",
            "nullable": true
          },
          "showQR": {
            "type": "boolean",
            "example": true
          },
          "paypalUser": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "status": {
            "type": "string",
            "description": "Lifecycle status. `processing` is the default on create; `overdue` is derived from `dueDate` by a scheduled job, so do not compute it client-side.",
            "enum": [
              "paid",
              "concept",
              "processing",
              "archived",
              "overdue",
              "cancelled"
            ],
            "nullable": true,
            "example": "processing"
          },
          "orderNumber": {
            "type": "string",
            "description": "Purchase-order number, always returned as a string; leading zeros are preserved (\"00005\" stays \"00005\").",
            "nullable": true
          },
          "deposit": {
            "type": "number",
            "description": "Deposit already paid, subtracted from the amount due. Integer minor-unit-free.",
            "nullable": true,
            "example": null
          },
          "discount": {
            "type": "number",
            "description": "Whole-document discount in percent.",
            "example": 0
          },
          "nonPay": {
            "type": "boolean",
            "description": "When `true` the document prints as a non-payment record (no amount due).",
            "example": false
          },
          "peppolStatus": {
            "type": "string",
            "description": "State of the outbound e-invoice (Peppol / eFaktúra) delivery. `NOT_SENT` until `POST …/{id}/peppol/send` is called or auto-send fires.",
            "enum": [
              "NOT_SENT",
              "QUEUED",
              "SENT",
              "DELIVERED",
              "FAILED"
            ],
            "example": "NOT_SENT"
          },
          "peppolAutoSend": {
            "type": "boolean",
            "description": "Whether this invoice is queued for eFaktúra delivery automatically on issue.",
            "example": false
          },
          "peppolSentAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "peppolDeliveredAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "peppolFailedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "peppolTaxReporting": {
            "description": "Tax-authority (TDD) report summary. Present on the single-invoice read for invoices sent over eFaktúra (Peppol); absent otherwise and on list rows.",
            "allOf": [
              {
                "$ref": "#/components/schemas/InvoicePeppolTaxReportingDto"
              }
            ]
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "fields",
          "sender",
          "recipient",
          "totalPrice",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "note",
          "color",
          "style",
          "stamp",
          "poster",
          "dueDate",
          "deliveryDate",
          "paymentMethod",
          "customPM",
          "deliveryMethod",
          "IBAN",
          "BIC",
          "variableSymbol",
          "constantSymbol",
          "specificSymbol",
          "qrCode",
          "showQR",
          "paypalUser",
          "status",
          "orderNumber",
          "deposit",
          "discount",
          "nonPay",
          "peppolStatus",
          "peppolAutoSend",
          "peppolSentAt",
          "peppolDeliveredAt",
          "peppolFailedAt"
        ]
      },
      "InvoiceCreateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. An empty array is accepted and renders a document with no lines.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "note": {
            "type": "string",
            "description": "Free-text note printed on the document."
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `processing` when omitted.",
            "enum": [
              "paid",
              "concept",
              "processing",
              "archived",
              "overdue",
              "cancelled"
            ],
            "default": "processing"
          },
          "dueDate": {
            "type": "string",
            "format": "date-time"
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time"
          },
          "orderNumber": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^\\d{1,10}$"
              },
              {
                "type": "integer"
              }
            ],
            "description": "Purchase-order number as a string of 1–10 digits; leading zeros are preserved (\"00005\" stays \"00005\"). A JSON number is still accepted for backward compatibility and is stored as a string.",
            "example": "00005"
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ]
          },
          "customPM": {
            "type": "string",
            "description": "Required when `paymentMethod` is `custom`.",
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "description": "One of the listed values, or any other string.",
            "enum": [
              "email",
              "post",
              "courier",
              "personal",
              "pickup"
            ]
          },
          "IBAN": {
            "type": "string",
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string",
            "description": "Payment reference. Left unset the server does not invent one — supply it if your bank reconciliation depends on it.",
            "example": "20260042"
          },
          "constantSymbol": {
            "type": "string"
          },
          "specificSymbol": {
            "type": "string"
          },
          "showQR": {
            "type": "boolean",
            "description": "Whether to render the PAY-by-square QR code.",
            "default": true
          },
          "deposit": {
            "type": "number",
            "description": "Deposit already received, subtracted from the amount due."
          },
          "discount": {
            "type": "number",
            "description": "Whole-document discount in percent.",
            "default": 0
          },
          "nonPay": {
            "type": "boolean",
            "description": "Print as a non-payment record.",
            "default": false
          },
          "peppolAutoSend": {
            "type": "boolean",
            "description": "Queue the invoice for eFaktúra (Peppol) delivery on issue.",
            "default": false
          }
        }
      },
      "InvoiceImportResultDto": {
        "type": "object",
        "properties": {
          "invoices": {
            "description": "Invoices created from the uploaded files.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InvoiceDto"
            }
          },
          "advanceInvoices": {
            "type": "array",
            "description": "Advance invoices recognised in the same upload. Shape matches the advance-invoice schema.",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "recommendCreditNotes": {
            "type": "array",
            "description": "Invoices the importer believes should get a credit note (a negative total, or a duplicate of an already-issued number). Advisory only — nothing is created.",
            "items": {
              "type": "object",
              "properties": {
                "invoiceId": {
                  "type": "number",
                  "example": 1042
                }
              }
            }
          }
        },
        "required": [
          "invoices"
        ]
      },
      "CreditNoteDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. **Omitted from list responses** — fetch the document by id to get them.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "totalPrice": {
            "type": "string",
            "description": "Computed grand total including VAT. A `decimal` column, therefore a **string** on the wire. `null` on a document with no priced lines.",
            "nullable": true,
            "example": "724.80"
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "dueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ],
            "nullable": true,
            "example": "banktransfer"
          },
          "customPM": {
            "type": "string",
            "description": "Label used when `paymentMethod` is `custom`.",
            "nullable": true,
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "description": "Delivery method. A free-form string is accepted beyond the listed values.",
            "nullable": true,
            "example": "email"
          },
          "IBAN": {
            "type": "string",
            "nullable": true,
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "nullable": true,
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string",
            "nullable": true,
            "example": "20260042"
          },
          "constantSymbol": {
            "type": "string",
            "nullable": true
          },
          "specificSymbol": {
            "type": "string",
            "nullable": true
          },
          "qrCode": {
            "type": "string",
            "description": "PAY-by-square payload string rendered as the payment QR code, not an image.",
            "nullable": true
          },
          "showQR": {
            "type": "boolean",
            "example": true
          },
          "paypalUser": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "status": {
            "type": "string",
            "enum": [
              "processing",
              "issued",
              "applied",
              "refunded",
              "cancelled",
              "archived"
            ],
            "nullable": true,
            "example": "processing"
          },
          "invoiceNumber": {
            "type": "string",
            "description": "Number of the invoice being credited, as printed. A `decimal` column, therefore a string on the wire. Independent of `invoiceId` — a credit note can reference an invoice issued outside Účtovisko.",
            "nullable": true,
            "example": "20260041"
          },
          "orderNumber": {
            "type": "string",
            "description": "Purchase-order number, always returned as a string; leading zeros are preserved (\"00005\" stays \"00005\").",
            "nullable": true
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "fields",
          "sender",
          "recipient",
          "totalPrice",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "note",
          "color",
          "style",
          "stamp",
          "poster",
          "dueDate",
          "deliveryDate",
          "paymentMethod",
          "customPM",
          "deliveryMethod",
          "IBAN",
          "BIC",
          "variableSymbol",
          "constantSymbol",
          "specificSymbol",
          "qrCode",
          "showQR",
          "paypalUser",
          "status",
          "invoiceNumber",
          "orderNumber"
        ]
      },
      "ApiListMeta": {
        "type": "object",
        "properties": {
          "total": {
            "type": "number",
            "description": "Total number of rows matching the filter, ignoring pagination.",
            "example": 128
          },
          "nextCursor": {
            "type": "string",
            "description": "Opaque token for the next page (base64 text; ids are 32-bit integers, the token is not an id). Pass it back unchanged as `?cursor=`; when `cursor` is supplied, `page` is ignored. It is omitted for an empty page, for `ids=` lookups and for computed-column sorts (use `page` there). It is **not** an end-of-list marker — a full last page still carries one; stop when `list` is shorter than `pageSize` or empty. Not returned by receipts.",
            "example": "eyJpZCI6MTA0Mn0="
          },
          "count": {
            "type": "object",
            "description": "Row count per status over the whole account, keyed by status value. Returned **only** when `?index=true`.",
            "additionalProperties": {
              "type": "number"
            },
            "example": {
              "issued": 12,
              "paid": 94
            }
          },
          "amount": {
            "type": "object",
            "description": "Summed `totalPrice` per status over the whole account, keyed by status value. Returned **only** when `?index=true`.",
            "additionalProperties": {
              "type": "number"
            },
            "example": {
              "issued": 1420.5,
              "paid": 18233.9
            }
          }
        },
        "required": [
          "total"
        ]
      },
      "InvoiceListItemDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "dueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ],
            "nullable": true,
            "example": "banktransfer"
          },
          "customPM": {
            "type": "string",
            "description": "Label used when `paymentMethod` is `custom`.",
            "nullable": true,
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "description": "Delivery method. A free-form string is accepted beyond the listed values.",
            "nullable": true,
            "example": "email"
          },
          "IBAN": {
            "type": "string",
            "nullable": true,
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "nullable": true,
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string",
            "nullable": true,
            "example": "20260042"
          },
          "constantSymbol": {
            "type": "string",
            "nullable": true
          },
          "specificSymbol": {
            "type": "string",
            "nullable": true
          },
          "qrCode": {
            "type": "string",
            "description": "PAY-by-square payload string rendered as the payment QR code, not an image.",
            "nullable": true
          },
          "showQR": {
            "type": "boolean",
            "example": true
          },
          "paypalUser": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "status": {
            "type": "string",
            "description": "Lifecycle status. `processing` is the default on create; `overdue` is derived from `dueDate` by a scheduled job, so do not compute it client-side.",
            "enum": [
              "paid",
              "concept",
              "processing",
              "archived",
              "overdue",
              "cancelled"
            ],
            "nullable": true,
            "example": "processing"
          },
          "orderNumber": {
            "type": "string",
            "description": "Purchase-order number, always returned as a string; leading zeros are preserved (\"00005\" stays \"00005\").",
            "nullable": true
          },
          "deposit": {
            "type": "number",
            "description": "Deposit already paid, subtracted from the amount due. Integer minor-unit-free.",
            "nullable": true,
            "example": null
          },
          "discount": {
            "type": "number",
            "description": "Whole-document discount in percent.",
            "example": 0
          },
          "nonPay": {
            "type": "boolean",
            "description": "When `true` the document prints as a non-payment record (no amount due).",
            "example": false
          },
          "peppolStatus": {
            "type": "string",
            "description": "State of the outbound e-invoice (Peppol / eFaktúra) delivery. `NOT_SENT` until `POST …/{id}/peppol/send` is called or auto-send fires.",
            "enum": [
              "NOT_SENT",
              "QUEUED",
              "SENT",
              "DELIVERED",
              "FAILED"
            ],
            "example": "NOT_SENT"
          },
          "peppolAutoSend": {
            "type": "boolean",
            "description": "Whether this invoice is queued for eFaktúra delivery automatically on issue.",
            "example": false
          },
          "peppolSentAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "peppolDeliveredAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "peppolFailedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "totalPrice": {
            "type": "number",
            "description": "Precomputed grand total including VAT, as a JSON **number** (list rows only; the single-document endpoint returns the same value as a decimal string).",
            "nullable": true,
            "example": 724.8
          },
          "remaining": {
            "type": "number",
            "description": "Unpaid amount: max(0, amount due - recorded payments). Same value as on the single invoice. Sortable and filterable as `remaining`.",
            "example": 724.8
          },
          "isOverdue": {
            "type": "boolean",
            "description": "True when the invoice is payable, has a positive `remaining` and its `dueDate` is before today (Europe/Bratislava calendar day). An invoice without a due date is never overdue.",
            "example": false
          },
          "correctedByCreditNote": {
            "type": "object",
            "description": "Credit notes issued against this invoice: how many and their summed amount. `null` when there are none.",
            "nullable": true,
            "properties": {
              "count": {
                "type": "number",
                "example": 1
              },
              "totalAmount": {
                "type": "number",
                "example": 50
              }
            }
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "sender",
          "recipient",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "note",
          "color",
          "style",
          "stamp",
          "poster",
          "dueDate",
          "deliveryDate",
          "paymentMethod",
          "customPM",
          "deliveryMethod",
          "IBAN",
          "BIC",
          "variableSymbol",
          "constantSymbol",
          "specificSymbol",
          "qrCode",
          "showQR",
          "paypalUser",
          "status",
          "orderNumber",
          "deposit",
          "discount",
          "nonPay",
          "peppolStatus",
          "peppolAutoSend",
          "peppolSentAt",
          "peppolDeliveredAt",
          "peppolFailedAt",
          "totalPrice",
          "remaining",
          "isOverdue",
          "correctedByCreditNote"
        ]
      },
      "InvoiceShortListItemDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "example": 1042
          },
          "number": {
            "type": "string",
            "nullable": true,
            "example": "20260042"
          },
          "sender": {
            "type": "string",
            "description": "Supplier **name only**, not the full company block.",
            "nullable": true,
            "example": "Ultra Labs s. r. o."
          },
          "recipient": {
            "type": "string",
            "description": "Customer **name only**.",
            "nullable": true,
            "example": "Odberateľ a. s."
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        },
        "required": [
          "id",
          "number",
          "sender",
          "recipient",
          "issueDate"
        ]
      },
      "SummaryBucketTotalsDto": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "number",
            "description": "Rounded to 2 decimals.",
            "example": 5180.92
          },
          "count": {
            "type": "number",
            "example": 5
          }
        },
        "required": [
          "amount",
          "count"
        ]
      },
      "SummaryOverdueTotalsDto": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "number",
            "description": "Rounded to 2 decimals.",
            "example": 5180.92
          },
          "count": {
            "type": "number",
            "example": 5
          },
          "maxDaysOverdue": {
            "type": "number",
            "description": "Largest whole-day age among the overdue rows. 0 when none.",
            "example": 8
          }
        },
        "required": [
          "amount",
          "count",
          "maxDaysOverdue"
        ]
      },
      "SummaryVatTotalsDto": {
        "type": "object",
        "properties": {
          "basic": {
            "type": "number",
            "example": 38.99
          },
          "reduced": {
            "type": "number",
            "example": 0
          },
          "total": {
            "type": "number",
            "example": 38.99
          }
        },
        "required": [
          "basic",
          "reduced",
          "total"
        ]
      },
      "DocumentSummaryCurrencyBucketDto": {
        "type": "object",
        "properties": {
          "currency": {
            "type": "string",
            "example": "EUR"
          },
          "total": {
            "$ref": "#/components/schemas/SummaryBucketTotalsDto"
          },
          "thisMonth": {
            "$ref": "#/components/schemas/SummaryBucketTotalsDto"
          },
          "unpaid": {
            "nullable": true,
            "description": "`null` for types with no payment state.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SummaryBucketTotalsDto"
              }
            ]
          },
          "overdue": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/SummaryOverdueTotalsDto"
              }
            ]
          },
          "accepted": {
            "nullable": true,
            "description": "Price offers only.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SummaryBucketTotalsDto"
              }
            ]
          },
          "processed": {
            "nullable": true,
            "description": "Uploaded invoices only.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SummaryBucketTotalsDto"
              }
            ]
          },
          "vat": {
            "nullable": true,
            "description": "Receipts only.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SummaryVatTotalsDto"
              }
            ]
          },
          "byStatus": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/SummaryBucketTotalsDto"
            },
            "description": "Per stored status, upper-cased. Zero buckets are present."
          },
          "extra": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/SummaryBucketTotalsDto"
            },
            "description": "UC-1328 — type-specific money tiles that have no generic slot. Travel fulfillments: `unsettled`, `settled`, `prepayment`, `documentsMissing`. Absent for other types."
          }
        },
        "required": [
          "currency",
          "total",
          "thisMonth",
          "unpaid",
          "overdue",
          "accepted",
          "processed",
          "vat",
          "byStatus"
        ]
      },
      "DocumentSummaryPeriodDto": {
        "type": "object",
        "properties": {
          "from": {
            "type": "string",
            "nullable": true,
            "example": "2026-10-01T00:00:00.000Z"
          },
          "to": {
            "type": "string",
            "nullable": true,
            "example": "2026-11-01T00:00:00.000Z"
          }
        },
        "required": [
          "from",
          "to"
        ]
      },
      "DocumentSummaryMonthDto": {
        "type": "object",
        "properties": {
          "from": {
            "type": "string",
            "example": "2026-10-01T00:00:00.000Z"
          },
          "to": {
            "type": "string",
            "example": "2026-11-01T00:00:00.000Z"
          }
        },
        "required": [
          "from",
          "to"
        ]
      },
      "SummaryOverdueCurrencyDto": {
        "type": "object",
        "properties": {
          "currency": {
            "type": "string",
            "example": "EUR"
          },
          "count": {
            "type": "number",
            "example": 2
          },
          "amount": {
            "type": "number",
            "example": 340.5,
            "description": "Invoices: outstanding balance (what is still owed). Advance invoices: document total."
          }
        },
        "required": [
          "currency",
          "count",
          "amount"
        ]
      },
      "SummaryOverdueAllTimeDto": {
        "type": "object",
        "properties": {
          "count": {
            "type": "number",
            "example": 3,
            "description": "Overdue rows across all currencies (counts may be added up)."
          },
          "byCurrency": {
            "description": "Money per currency — never summed across entries.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SummaryOverdueCurrencyDto"
            }
          }
        },
        "required": [
          "count",
          "byCurrency"
        ]
      },
      "InvoiceSummaryDto": {
        "type": "object",
        "properties": {
          "currencies": {
            "description": "One bucket per currency used in the period. Amounts are NEVER summed across buckets — pick one or render one strip per currency.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentSummaryCurrencyBucketDto"
            }
          },
          "statusCounts": {
            "type": "object",
            "additionalProperties": {
              "type": "number"
            },
            "description": "Currency-agnostic row counts keyed by upper-cased status, plus `ALL`.",
            "example": {
              "ALL": 5,
              "CONCEPT": 1,
              "PROCESSING": 2,
              "OVERDUE": 1,
              "PAID": 1
            }
          },
          "period": {
            "$ref": "#/components/schemas/DocumentSummaryPeriodDto"
          },
          "month": {
            "$ref": "#/components/schemas/DocumentSummaryMonthDto"
          },
          "truncated": {
            "type": "boolean",
            "description": "True when the row ceiling was reached, so the figures are partial and must be labelled as such in the UI.",
            "example": false
          },
          "generatedAt": {
            "type": "string",
            "example": "2026-10-08T09:30:00.000Z"
          },
          "tabCounts": {
            "type": "object",
            "additionalProperties": {
              "type": "number"
            },
            "description": "Invoices per derived tab (`all`, `concept`, `unpaid`, `overdue`, `paid`, `cancelled`, `archived`). Unlike the rest of the summary it ignores the `archived` filter and counts archived invoices too.",
            "example": {
              "all": 12,
              "concept": 1,
              "unpaid": 4,
              "overdue": 1,
              "paid": 5,
              "cancelled": 1,
              "archived": 0
            }
          },
          "overdueAllTime": {
            "description": "Overdue to date WITHOUT the period filter (invoices and advance invoices). Present only when `from`/`to` is set; `count` is >= the overdue figure of the period.",
            "allOf": [
              {
                "$ref": "#/components/schemas/SummaryOverdueAllTimeDto"
              }
            ]
          },
          "metrics": {
            "type": "object",
            "additionalProperties": {
              "type": "number"
            },
            "description": "UC-1328 — currency-agnostic figures (counts, kilometres) for types whose KPI tiles are not money. Same period/archived scope as the strip. Travel only; keys per type in list-summary-contract.md \"Travel\". Absent for document types.",
            "example": {
              "total": 12,
              "inProgressToday": 2,
              "completed": 7,
              "completedWithoutFulfillment": 1
            }
          }
        },
        "required": [
          "currencies",
          "statusCounts",
          "period",
          "month",
          "truncated",
          "generatedAt"
        ]
      },
      "InvoiceSendResultDto": {
        "type": "object",
        "properties": {
          "sent": {
            "type": "boolean",
            "example": true
          },
          "email": {
            "type": "string",
            "format": "email",
            "example": "odberatel@example.sk"
          }
        },
        "required": [
          "sent",
          "email"
        ]
      },
      "DocumentSendDto": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "description": "Recipient address. Required — a missing value answers 422 `email_missing`. The PDF is rendered server-side and attached.",
            "format": "email",
            "example": "odberatel@example.sk"
          }
        },
        "required": [
          "email"
        ]
      },
      "InvoiceUpdateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. An empty array is accepted and renders a document with no lines.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "note": {
            "type": "string",
            "description": "Free-text note printed on the document."
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `processing` when omitted.",
            "enum": [
              "paid",
              "concept",
              "processing",
              "archived",
              "overdue",
              "cancelled"
            ],
            "default": "processing"
          },
          "dueDate": {
            "type": "string",
            "format": "date-time"
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time"
          },
          "orderNumber": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^\\d{1,10}$"
              },
              {
                "type": "integer"
              }
            ],
            "description": "Purchase-order number as a string of 1–10 digits; leading zeros are preserved (\"00005\" stays \"00005\"). A JSON number is still accepted for backward compatibility and is stored as a string.",
            "example": "00005"
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ]
          },
          "customPM": {
            "type": "string",
            "description": "Required when `paymentMethod` is `custom`.",
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "description": "One of the listed values, or any other string.",
            "enum": [
              "email",
              "post",
              "courier",
              "personal",
              "pickup"
            ]
          },
          "IBAN": {
            "type": "string",
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string",
            "description": "Payment reference. Left unset the server does not invent one — supply it if your bank reconciliation depends on it.",
            "example": "20260042"
          },
          "constantSymbol": {
            "type": "string"
          },
          "specificSymbol": {
            "type": "string"
          },
          "showQR": {
            "type": "boolean",
            "description": "Whether to render the PAY-by-square QR code.",
            "default": true
          },
          "deposit": {
            "type": "number",
            "description": "Deposit already received, subtracted from the amount due."
          },
          "discount": {
            "type": "number",
            "description": "Whole-document discount in percent.",
            "default": 0
          },
          "nonPay": {
            "type": "boolean",
            "description": "Print as a non-payment record.",
            "default": false
          },
          "peppolAutoSend": {
            "type": "boolean",
            "description": "Queue the invoice for eFaktúra (Peppol) delivery on issue.",
            "default": false
          }
        }
      },
      "DocumentStatusUpdateDto": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "description": "New status. Accepted values are the status enum of the document type — see the `status` property of that type's response schema.",
            "example": "paid"
          }
        },
        "required": [
          "status"
        ]
      },
      "DocumentDeleteResultDto": {
        "type": "object",
        "properties": {
          "archived": {
            "description": "Ids that were soft-archived (the default). They disappear from every list but the rows and their PDFs are retained.",
            "example": [
              1041,
              1042
            ],
            "type": "array",
            "items": {
              "type": "number"
            }
          },
          "removed": {
            "description": "Ids that were hard-deleted. Non-empty only when `?purge=true` was sent.",
            "example": [],
            "type": "array",
            "items": {
              "type": "number"
            }
          }
        },
        "required": [
          "archived",
          "removed"
        ]
      },
      "CreditNoteCreateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. An empty array is accepted and renders a document with no lines.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "note": {
            "type": "string",
            "description": "Free-text note printed on the document."
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `processing`.",
            "enum": [
              "processing",
              "issued",
              "applied",
              "refunded",
              "cancelled",
              "archived"
            ],
            "default": "processing"
          },
          "invoiceId": {
            "type": "number",
            "description": "Id of the invoice this credit note corrects. Optional — omit it to credit an invoice that does not live in Účtovisko and set `invoiceNumber` instead.",
            "example": 1041
          },
          "invoiceNumber": {
            "type": "number",
            "description": "Printed number of the credited invoice.",
            "example": 20260041
          },
          "orderNumber": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^\\d{1,32}$"
              },
              {
                "type": "integer"
              }
            ],
            "description": "Purchase-order number as a string of 1–32 digits; leading zeros are preserved (\"00005\" stays \"00005\"). A JSON number is still accepted for backward compatibility and is stored as a string.",
            "example": "00005"
          },
          "dueDate": {
            "type": "string",
            "format": "date-time"
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time"
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ]
          },
          "customPM": {
            "type": "string",
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "enum": [
              "email",
              "post",
              "courier",
              "personal",
              "pickup"
            ]
          },
          "IBAN": {
            "type": "string",
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string"
          },
          "constantSymbol": {
            "type": "string"
          },
          "specificSymbol": {
            "type": "string"
          },
          "showQR": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "CreditNoteListItemDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "dueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ],
            "nullable": true,
            "example": "banktransfer"
          },
          "customPM": {
            "type": "string",
            "description": "Label used when `paymentMethod` is `custom`.",
            "nullable": true,
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "description": "Delivery method. A free-form string is accepted beyond the listed values.",
            "nullable": true,
            "example": "email"
          },
          "IBAN": {
            "type": "string",
            "nullable": true,
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "nullable": true,
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string",
            "nullable": true,
            "example": "20260042"
          },
          "constantSymbol": {
            "type": "string",
            "nullable": true
          },
          "specificSymbol": {
            "type": "string",
            "nullable": true
          },
          "qrCode": {
            "type": "string",
            "description": "PAY-by-square payload string rendered as the payment QR code, not an image.",
            "nullable": true
          },
          "showQR": {
            "type": "boolean",
            "example": true
          },
          "paypalUser": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "status": {
            "type": "string",
            "enum": [
              "processing",
              "issued",
              "applied",
              "refunded",
              "cancelled",
              "archived"
            ],
            "nullable": true,
            "example": "processing"
          },
          "invoiceNumber": {
            "type": "string",
            "description": "Number of the invoice being credited, as printed. A `decimal` column, therefore a string on the wire. Independent of `invoiceId` — a credit note can reference an invoice issued outside Účtovisko.",
            "nullable": true,
            "example": "20260041"
          },
          "orderNumber": {
            "type": "string",
            "description": "Purchase-order number, always returned as a string; leading zeros are preserved (\"00005\" stays \"00005\").",
            "nullable": true
          },
          "totalPrice": {
            "type": "number",
            "description": "Precomputed grand total including VAT, as a JSON **number** (list rows only; the single-document endpoint returns the same value as a decimal string).",
            "nullable": true,
            "example": 724.8
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "sender",
          "recipient",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "note",
          "color",
          "style",
          "stamp",
          "poster",
          "dueDate",
          "deliveryDate",
          "paymentMethod",
          "customPM",
          "deliveryMethod",
          "IBAN",
          "BIC",
          "variableSymbol",
          "constantSymbol",
          "specificSymbol",
          "qrCode",
          "showQR",
          "paypalUser",
          "status",
          "invoiceNumber",
          "orderNumber",
          "totalPrice"
        ]
      },
      "CreditNoteUpdateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. An empty array is accepted and renders a document with no lines.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "note": {
            "type": "string",
            "description": "Free-text note printed on the document."
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `processing`.",
            "enum": [
              "processing",
              "issued",
              "applied",
              "refunded",
              "cancelled",
              "archived"
            ],
            "default": "processing"
          },
          "invoiceId": {
            "type": "number",
            "description": "Id of the invoice this credit note corrects. Optional — omit it to credit an invoice that does not live in Účtovisko and set `invoiceNumber` instead.",
            "example": 1041
          },
          "invoiceNumber": {
            "type": "number",
            "description": "Printed number of the credited invoice.",
            "example": 20260041
          },
          "orderNumber": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^\\d{1,32}$"
              },
              {
                "type": "integer"
              }
            ],
            "description": "Purchase-order number as a string of 1–32 digits; leading zeros are preserved (\"00005\" stays \"00005\"). A JSON number is still accepted for backward compatibility and is stored as a string.",
            "example": "00005"
          },
          "dueDate": {
            "type": "string",
            "format": "date-time"
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time"
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ]
          },
          "customPM": {
            "type": "string",
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "enum": [
              "email",
              "post",
              "courier",
              "personal",
              "pickup"
            ]
          },
          "IBAN": {
            "type": "string",
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string"
          },
          "constantSymbol": {
            "type": "string"
          },
          "specificSymbol": {
            "type": "string"
          },
          "showQR": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "PriceOfferDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. **Omitted from list responses** — fetch the document by id to get them.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "totalPrice": {
            "type": "string",
            "description": "Computed grand total including VAT. A `decimal` column, therefore a **string** on the wire. `null` on a document with no priced lines.",
            "nullable": true,
            "example": "724.80"
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "description": "Defaults to `sent` on create — not `draft`. `expired` is derived from `validityDate`.",
            "enum": [
              "draft",
              "sent",
              "accepted",
              "rejected",
              "expired",
              "archived"
            ],
            "nullable": true,
            "example": "sent"
          },
          "validityDate": {
            "type": "string",
            "description": "Last day the offer is binding. There is no `dueDate` on a price offer.",
            "format": "date-time",
            "nullable": true
          },
          "discount": {
            "type": "number",
            "description": "Whole-document discount in percent.",
            "example": 0
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "fields",
          "sender",
          "recipient",
          "totalPrice",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "note",
          "color",
          "style",
          "stamp",
          "poster",
          "status",
          "validityDate",
          "discount"
        ]
      },
      "PriceOfferCreateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. An empty array is accepted and renders a document with no lines.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "note": {
            "type": "string",
            "description": "Free-text note printed on the document."
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `sent` when omitted.",
            "enum": [
              "draft",
              "sent",
              "accepted",
              "rejected",
              "expired",
              "archived"
            ],
            "default": "sent"
          },
          "validityDate": {
            "type": "string",
            "format": "date-time"
          },
          "discount": {
            "type": "number",
            "default": 0
          }
        }
      },
      "PriceOfferListItemDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "description": "Defaults to `sent` on create — not `draft`. `expired` is derived from `validityDate`.",
            "enum": [
              "draft",
              "sent",
              "accepted",
              "rejected",
              "expired",
              "archived"
            ],
            "nullable": true,
            "example": "sent"
          },
          "validityDate": {
            "type": "string",
            "description": "Last day the offer is binding. There is no `dueDate` on a price offer.",
            "format": "date-time",
            "nullable": true
          },
          "discount": {
            "type": "number",
            "description": "Whole-document discount in percent.",
            "example": 0
          },
          "totalPrice": {
            "type": "number",
            "description": "Precomputed grand total including VAT, as a JSON **number** (list rows only; the single-document endpoint returns the same value as a decimal string).",
            "nullable": true,
            "example": 724.8
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "sender",
          "recipient",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "note",
          "color",
          "style",
          "stamp",
          "poster",
          "status",
          "validityDate",
          "discount",
          "totalPrice"
        ]
      },
      "PriceOfferUpdateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. An empty array is accepted and renders a document with no lines.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "note": {
            "type": "string",
            "description": "Free-text note printed on the document."
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `sent` when omitted.",
            "enum": [
              "draft",
              "sent",
              "accepted",
              "rejected",
              "expired",
              "archived"
            ],
            "default": "sent"
          },
          "validityDate": {
            "type": "string",
            "format": "date-time"
          },
          "discount": {
            "type": "number",
            "default": 0
          }
        }
      },
      "IncomeDocumentDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "totalPrice": {
            "type": "string",
            "description": "Computed grand total including VAT. A `decimal` column, therefore a **string** on the wire. `null` on a document with no priced lines.",
            "nullable": true,
            "example": "724.80"
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "description": "Defaults to `draft` on create.",
            "enum": [
              "draft",
              "issued",
              "cancelled",
              "archived"
            ],
            "nullable": true,
            "example": "draft"
          },
          "invoiceId": {
            "type": "number",
            "description": "Id of the invoice this payment settles, when it is an Účtovisko invoice. `null` when the referenced invoice was deleted (the FK is `ON DELETE SET NULL`) or never existed here.",
            "nullable": true,
            "example": 1041
          },
          "invoiceNumber": {
            "type": "string",
            "description": "Printed number of the invoice being settled. `decimal` column → string.",
            "nullable": true,
            "example": "20260041"
          },
          "invoicePrice": {
            "type": "string",
            "description": "Total of the referenced invoice, for the \"paid X of Y\" line. `decimal` column → string. Not recomputed — it is a snapshot taken when the document was issued.",
            "nullable": true,
            "example": "724.80"
          },
          "paymentPurpose": {
            "type": "string",
            "description": "Printed payment purpose.",
            "nullable": true,
            "example": "Úhrada faktúry 20260041"
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "sender",
          "recipient",
          "totalPrice",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "color",
          "style",
          "stamp",
          "poster",
          "status",
          "invoiceId",
          "invoiceNumber",
          "invoicePrice",
          "paymentPurpose"
        ]
      },
      "IncomeDocumentCreateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `draft`.",
            "enum": [
              "draft",
              "issued",
              "cancelled",
              "archived"
            ],
            "default": "draft"
          },
          "invoiceId": {
            "type": "number",
            "description": "Id of the invoice being settled.",
            "example": 1041
          },
          "invoiceNumber": {
            "type": "number",
            "example": 20260041
          },
          "invoicePrice": {
            "type": "number",
            "description": "Total of the referenced invoice. Supply it when `invoiceId` is omitted; otherwise the server takes it from the invoice.",
            "example": 724.8
          },
          "totalPrice": {
            "type": "number",
            "description": "Amount actually received. Omit to record a full settlement of `invoicePrice`.",
            "example": 724.8
          },
          "paymentPurpose": {
            "type": "string",
            "example": "Úhrada faktúry 20260041"
          }
        }
      },
      "IncomeDocumentListItemDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "string",
            "description": "Defaults to `draft` on create.",
            "enum": [
              "draft",
              "issued",
              "cancelled",
              "archived"
            ],
            "nullable": true,
            "example": "draft"
          },
          "invoiceId": {
            "type": "number",
            "description": "Id of the invoice this payment settles, when it is an Účtovisko invoice. `null` when the referenced invoice was deleted (the FK is `ON DELETE SET NULL`) or never existed here.",
            "nullable": true,
            "example": 1041
          },
          "invoiceNumber": {
            "type": "string",
            "description": "Printed number of the invoice being settled. `decimal` column → string.",
            "nullable": true,
            "example": "20260041"
          },
          "invoicePrice": {
            "type": "string",
            "description": "Total of the referenced invoice, for the \"paid X of Y\" line. `decimal` column → string. Not recomputed — it is a snapshot taken when the document was issued.",
            "nullable": true,
            "example": "724.80"
          },
          "paymentPurpose": {
            "type": "string",
            "description": "Printed payment purpose.",
            "nullable": true,
            "example": "Úhrada faktúry 20260041"
          },
          "totalPrice": {
            "type": "number",
            "description": "Precomputed grand total including VAT, as a JSON **number** (list rows only; the single-document endpoint returns the same value as a decimal string).",
            "nullable": true,
            "example": 724.8
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "sender",
          "recipient",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "color",
          "style",
          "stamp",
          "poster",
          "status",
          "invoiceId",
          "invoiceNumber",
          "invoicePrice",
          "paymentPurpose",
          "totalPrice"
        ]
      },
      "IncomeDocumentUpdateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `draft`.",
            "enum": [
              "draft",
              "issued",
              "cancelled",
              "archived"
            ],
            "default": "draft"
          },
          "invoiceId": {
            "type": "number",
            "description": "Id of the invoice being settled.",
            "example": 1041
          },
          "invoiceNumber": {
            "type": "number",
            "example": 20260041
          },
          "invoicePrice": {
            "type": "number",
            "description": "Total of the referenced invoice. Supply it when `invoiceId` is omitted; otherwise the server takes it from the invoice.",
            "example": 724.8
          },
          "totalPrice": {
            "type": "number",
            "description": "Amount actually received. Omit to record a full settlement of `invoicePrice`.",
            "example": 724.8
          },
          "paymentPurpose": {
            "type": "string",
            "example": "Úhrada faktúry 20260041"
          }
        }
      },
      "AdvanceInvoiceDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. **Omitted from list responses** — fetch the document by id to get them.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "totalPrice": {
            "type": "string",
            "description": "Computed grand total including VAT. A `decimal` column, therefore a **string** on the wire. `null` on a document with no priced lines.",
            "nullable": true,
            "example": "724.80"
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "dueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ],
            "nullable": true,
            "example": "banktransfer"
          },
          "customPM": {
            "type": "string",
            "description": "Label used when `paymentMethod` is `custom`.",
            "nullable": true,
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "description": "Delivery method. A free-form string is accepted beyond the listed values.",
            "nullable": true,
            "example": "email"
          },
          "IBAN": {
            "type": "string",
            "nullable": true,
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "nullable": true,
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string",
            "nullable": true,
            "example": "20260042"
          },
          "constantSymbol": {
            "type": "string",
            "nullable": true
          },
          "specificSymbol": {
            "type": "string",
            "nullable": true
          },
          "qrCode": {
            "type": "string",
            "description": "PAY-by-square payload string rendered as the payment QR code, not an image.",
            "nullable": true
          },
          "showQR": {
            "type": "boolean",
            "example": true
          },
          "paypalUser": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "status": {
            "type": "string",
            "enum": [
              "paid",
              "draft",
              "processing",
              "archived",
              "overdue",
              "cancelled",
              "closed",
              "settled"
            ],
            "nullable": true,
            "example": "processing"
          },
          "orderNumber": {
            "type": "string",
            "description": "Purchase-order number, always returned as a string; leading zeros are preserved (\"00005\" stays \"00005\").",
            "nullable": true
          },
          "deposit": {
            "type": "number",
            "description": "Deposit amount, integer.",
            "nullable": true,
            "example": null
          },
          "discount": {
            "type": "number",
            "description": "Whole-document discount in percent.",
            "example": 0
          },
          "nonPay": {
            "type": "boolean",
            "description": "Print as a non-payment record.",
            "example": false
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "fields",
          "sender",
          "recipient",
          "totalPrice",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "note",
          "color",
          "style",
          "stamp",
          "poster",
          "dueDate",
          "deliveryDate",
          "paymentMethod",
          "customPM",
          "deliveryMethod",
          "IBAN",
          "BIC",
          "variableSymbol",
          "constantSymbol",
          "specificSymbol",
          "qrCode",
          "showQR",
          "paypalUser",
          "status",
          "orderNumber",
          "deposit",
          "discount",
          "nonPay"
        ]
      },
      "AdvanceInvoiceCreateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. An empty array is accepted and renders a document with no lines.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "note": {
            "type": "string",
            "description": "Free-text note printed on the document."
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `processing`.",
            "enum": [
              "paid",
              "draft",
              "processing",
              "archived",
              "overdue",
              "cancelled",
              "closed",
              "settled"
            ],
            "default": "processing"
          },
          "dueDate": {
            "type": "string",
            "format": "date-time"
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time"
          },
          "orderNumber": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^\\d{1,32}$"
              },
              {
                "type": "integer"
              }
            ],
            "description": "Purchase-order number as a string of 1–32 digits; leading zeros are preserved (\"00005\" stays \"00005\"). A JSON number is still accepted for backward compatibility and is stored as a string.",
            "example": "00005"
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ]
          },
          "customPM": {
            "type": "string",
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "enum": [
              "email",
              "post",
              "courier",
              "personal",
              "pickup"
            ]
          },
          "IBAN": {
            "type": "string",
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string"
          },
          "constantSymbol": {
            "type": "string"
          },
          "specificSymbol": {
            "type": "string"
          },
          "showQR": {
            "type": "boolean",
            "default": true
          },
          "deposit": {
            "type": "number"
          },
          "discount": {
            "type": "number",
            "default": 0
          },
          "nonPay": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "AdvanceInvoiceListItemDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "description": "Server-assigned id, unique per document type.",
            "example": 1042
          },
          "number": {
            "type": "string",
            "description": "Document number. A `decimal` column, therefore a **string** on the wire, e.g. `\"20260042\"`.",
            "nullable": true,
            "example": "20260042"
          },
          "issueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdBy": {
            "description": "Creator, reduced by `formatUser()`. `null` when the document was created by an API key rather than a signed-in user.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/DocumentUserDto"
              }
            ]
          },
          "sender": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "nullable": true,
            "example": "EUR"
          },
          "language": {
            "type": "string",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "example": "sk"
          },
          "useVat": {
            "type": "boolean",
            "example": true
          },
          "noVatReason": {
            "type": "string",
            "nullable": true
          },
          "rounding": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "color": {
            "type": "string",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "nullable": true,
            "example": "modern"
          },
          "stamp": {
            "type": "string",
            "enum": [
              "none",
              "default"
            ],
            "nullable": true,
            "example": "none"
          },
          "poster": {
            "type": "string",
            "nullable": true
          },
          "dueDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ],
            "nullable": true,
            "example": "banktransfer"
          },
          "customPM": {
            "type": "string",
            "description": "Label used when `paymentMethod` is `custom`.",
            "nullable": true,
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "description": "Delivery method. A free-form string is accepted beyond the listed values.",
            "nullable": true,
            "example": "email"
          },
          "IBAN": {
            "type": "string",
            "nullable": true,
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "nullable": true,
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string",
            "nullable": true,
            "example": "20260042"
          },
          "constantSymbol": {
            "type": "string",
            "nullable": true
          },
          "specificSymbol": {
            "type": "string",
            "nullable": true
          },
          "qrCode": {
            "type": "string",
            "description": "PAY-by-square payload string rendered as the payment QR code, not an image.",
            "nullable": true
          },
          "showQR": {
            "type": "boolean",
            "example": true
          },
          "paypalUser": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "status": {
            "type": "string",
            "enum": [
              "paid",
              "draft",
              "processing",
              "archived",
              "overdue",
              "cancelled",
              "closed",
              "settled"
            ],
            "nullable": true,
            "example": "processing"
          },
          "orderNumber": {
            "type": "string",
            "description": "Purchase-order number, always returned as a string; leading zeros are preserved (\"00005\" stays \"00005\").",
            "nullable": true
          },
          "deposit": {
            "type": "number",
            "description": "Deposit amount, integer.",
            "nullable": true,
            "example": null
          },
          "discount": {
            "type": "number",
            "description": "Whole-document discount in percent.",
            "example": 0
          },
          "nonPay": {
            "type": "boolean",
            "description": "Print as a non-payment record.",
            "example": false
          },
          "totalPrice": {
            "type": "number",
            "description": "Precomputed grand total including VAT, as a JSON **number** (list rows only; the single-document endpoint returns the same value as a decimal string).",
            "nullable": true,
            "example": 724.8
          }
        },
        "required": [
          "id",
          "number",
          "issueDate",
          "createdAt",
          "updatedAt",
          "createdBy",
          "sender",
          "recipient",
          "currency",
          "language",
          "useVat",
          "noVatReason",
          "rounding",
          "note",
          "color",
          "style",
          "stamp",
          "poster",
          "dueDate",
          "deliveryDate",
          "paymentMethod",
          "customPM",
          "deliveryMethod",
          "IBAN",
          "BIC",
          "variableSymbol",
          "constantSymbol",
          "specificSymbol",
          "qrCode",
          "showQR",
          "paypalUser",
          "status",
          "orderNumber",
          "deposit",
          "discount",
          "nonPay",
          "totalPrice"
        ]
      },
      "AdvanceInvoiceUpdateDto": {
        "type": "object",
        "properties": {
          "number": {
            "type": "number",
            "description": "Document number. Omit to let the server continue the account's series — call `…/latestNumber` to see where it currently stands. Stored as a numeric column, so it is returned as a **string** by the Postgres driver.",
            "example": 20260042
          },
          "issueDate": {
            "type": "string",
            "format": "date-time"
          },
          "sender": {
            "description": "Supplier snapshot. Defaults to the account's company profile when omitted.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "recipient": {
            "description": "Customer snapshot.",
            "allOf": [
              {
                "$ref": "#/components/schemas/CompanyDetailsDto"
              }
            ]
          },
          "fields": {
            "description": "Line items. An empty array is accepted and renders a document with no lines.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentFieldDto"
            }
          },
          "currency": {
            "type": "string",
            "enum": [
              "EUR",
              "CZK",
              "USD",
              "GBP",
              "CHF",
              "PLN",
              "HUF",
              "UAH",
              "RON"
            ],
            "default": "EUR"
          },
          "language": {
            "type": "string",
            "description": "Language the PDF renders in.",
            "enum": [
              "sk",
              "cz",
              "en",
              "de"
            ],
            "default": "sk"
          },
          "useVat": {
            "type": "boolean",
            "description": "Whether VAT is applied. Set `false` for a non-VAT-payer and supply `noVatReason`.",
            "default": true
          },
          "noVatReason": {
            "type": "string",
            "description": "Printed explanation when `useVat` is `false`.",
            "example": "Nie som platiteľ DPH."
          },
          "rounding": {
            "type": "string",
            "description": "Rounding mode as a free-form token, as stored. `null` means no rounding.",
            "example": "0.01"
          },
          "note": {
            "type": "string",
            "description": "Free-text note printed on the document."
          },
          "color": {
            "type": "string",
            "description": "Accent colour of the template, as a CSS hex string.",
            "default": "#FBF9FF",
            "example": "#FBF9FF"
          },
          "style": {
            "type": "string",
            "enum": [
              "modern",
              "simple"
            ],
            "default": "modern"
          },
          "stamp": {
            "type": "string",
            "description": "Whether a stamp graphic is printed.",
            "enum": [
              "none",
              "default"
            ],
            "default": "none"
          },
          "poster": {
            "type": "string",
            "description": "Header image reference, as stored. Also settable by uploading a `poster` part in a `multipart/form-data` request."
          },
          "status": {
            "type": "string",
            "description": "Defaults to `processing`.",
            "enum": [
              "paid",
              "draft",
              "processing",
              "archived",
              "overdue",
              "cancelled",
              "closed",
              "settled"
            ],
            "default": "processing"
          },
          "dueDate": {
            "type": "string",
            "format": "date-time"
          },
          "deliveryDate": {
            "type": "string",
            "format": "date-time"
          },
          "orderNumber": {
            "oneOf": [
              {
                "type": "string",
                "pattern": "^\\d{1,32}$"
              },
              {
                "type": "integer"
              }
            ],
            "description": "Purchase-order number as a string of 1–32 digits; leading zeros are preserved (\"00005\" stays \"00005\"). A JSON number is still accepted for backward compatibility and is stored as a string.",
            "example": "00005"
          },
          "paymentMethod": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ]
          },
          "customPM": {
            "type": "string",
            "maxLength": 64
          },
          "deliveryMethod": {
            "type": "string",
            "enum": [
              "email",
              "post",
              "courier",
              "personal",
              "pickup"
            ]
          },
          "IBAN": {
            "type": "string",
            "example": "SK3112000000198742637541"
          },
          "BIC": {
            "type": "string",
            "example": "GIBASKBX"
          },
          "variableSymbol": {
            "type": "string"
          },
          "constantSymbol": {
            "type": "string"
          },
          "specificSymbol": {
            "type": "string"
          },
          "showQR": {
            "type": "boolean",
            "default": true
          },
          "deposit": {
            "type": "number"
          },
          "discount": {
            "type": "number",
            "default": 0
          },
          "nonPay": {
            "type": "boolean",
            "default": false
          }
        }
      },
      "DocumentPaymentDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Payment id: a decimal Snowflake **string** (it does not fit a JS number).",
            "example": "7241889432101351425"
          },
          "amount": {
            "type": "number",
            "description": "Always positive, two decimals.",
            "example": 724.8
          },
          "currency": {
            "type": "string",
            "description": "ISO-4217 code.",
            "example": "EUR"
          },
          "paidAt": {
            "type": "string",
            "format": "date-time"
          },
          "method": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ],
            "nullable": true
          },
          "source": {
            "type": "string",
            "description": "`manual` = recorded through the app or the API; `openBanking` = matched from a bank transaction (its `amount` cannot be edited).",
            "enum": [
              "manual",
              "openBanking"
            ]
          },
          "obTransactionId": {
            "type": "string",
            "description": "Id of the bank transaction this payment came from; `null` for manual payments.",
            "nullable": true
          },
          "counterpartyName": {
            "type": "string",
            "nullable": true
          },
          "counterpartyIban": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          },
          "createdBy": {
            "type": "number",
            "description": "Internal user id of whoever recorded it; `null` for bank-matched payments.",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "amount",
          "currency",
          "paidAt",
          "method",
          "source",
          "obTransactionId",
          "counterpartyName",
          "counterpartyIban",
          "note",
          "createdBy",
          "createdAt"
        ]
      },
      "DocumentPaymentsResultDto": {
        "type": "object",
        "properties": {
          "documentType": {
            "type": "string",
            "enum": [
              "invoice",
              "advanceInvoice"
            ]
          },
          "documentId": {
            "type": "number",
            "example": 1042
          },
          "currency": {
            "type": "string",
            "example": "EUR"
          },
          "due": {
            "type": "number",
            "description": "Amount due on the document.",
            "example": 724.8
          },
          "paid": {
            "type": "number",
            "description": "Sum of the recorded payments.",
            "example": 100
          },
          "remaining": {
            "type": "number",
            "description": "max(0, due - paid).",
            "example": 624.8
          },
          "status": {
            "type": "string",
            "description": "The document's status after the change. A document's status is derived from its payments, so recording, editing or deleting one can move it (for example to `paid`).",
            "example": "processing"
          },
          "payments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentPaymentDto"
            }
          }
        },
        "required": [
          "documentType",
          "documentId",
          "currency",
          "due",
          "paid",
          "remaining",
          "status",
          "payments"
        ]
      },
      "DocumentPaymentCreateDto": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "number",
            "description": "Positive, at most two decimal places, at most 1 000 000 000.",
            "example": 100
          },
          "currency": {
            "type": "string",
            "description": "ISO-4217 code (three letters). Defaults to the document's currency.",
            "example": "EUR"
          },
          "paidAt": {
            "type": "string",
            "description": "ISO-8601 date-time. Defaults to now. Not before 2000-01-01 and not more than a day in the future (400 `invalid_body`).",
            "format": "date-time"
          },
          "method": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ]
          },
          "note": {
            "type": "string",
            "maxLength": 500
          }
        },
        "required": [
          "amount"
        ]
      },
      "DocumentPaymentUpdateDto": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "number",
            "description": "Positive, at most two decimal places. Refused with 409 `conflict` on a bank-confirmed payment (`source: \"openBanking\"`)."
          },
          "currency": {
            "type": "string",
            "example": "EUR"
          },
          "paidAt": {
            "type": "string",
            "format": "date-time"
          },
          "method": {
            "type": "string",
            "enum": [
              "banktransfer",
              "cash",
              "card",
              "crypto",
              "paypal",
              "custom"
            ]
          },
          "note": {
            "type": "string",
            "maxLength": 500
          }
        }
      },
      "ReceiptItemDto": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "example": "Káva 250 g"
          },
          "itemType": {
            "type": "string",
            "description": "eKasa item classification, as delivered by the register.",
            "example": "K"
          },
          "quantity": {
            "type": "number",
            "example": 2
          },
          "vatRate": {
            "type": "number",
            "description": "VAT rate as a percentage.",
            "example": 20
          },
          "price": {
            "type": "number",
            "description": "Line price **including** VAT, as printed on the receipt.",
            "example": 11.98
          },
          "sellerId": {
            "type": "string",
            "nullable": true
          },
          "sellerIdType": {
            "type": "string",
            "nullable": true
          },
          "specialRegulation": {
            "type": "string",
            "nullable": true
          },
          "voucherNumber": {
            "type": "string",
            "nullable": true
          }
        },
        "required": [
          "name",
          "itemType",
          "quantity",
          "vatRate",
          "price"
        ]
      },
      "ReceiptOrganizationDto": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "example": "Predajňa s. r. o."
          },
          "ico": {
            "type": "string",
            "example": "54321678"
          },
          "dic": {
            "type": "string",
            "example": "2120123456"
          },
          "icDph": {
            "type": "string",
            "nullable": true,
            "example": "SK2120123456"
          },
          "municipality": {
            "type": "string",
            "example": "Košice"
          },
          "streetName": {
            "type": "string",
            "example": "Hlavná"
          },
          "buildingNumber": {
            "type": "string",
            "example": "12"
          },
          "propertyRegistrationNumber": {
            "type": "string",
            "nullable": true
          },
          "postalCode": {
            "type": "string",
            "example": "04001"
          },
          "country": {
            "type": "string",
            "example": "SK"
          },
          "vatPayer": {
            "type": "boolean",
            "description": "VAT-payer flag as reported by eKasa.",
            "example": true
          },
          "manualVatPayer": {
            "type": "boolean",
            "description": "Set when a user overrode the reported flag by hand. The override, not eKasa, decides how the receipt is booked.",
            "example": false
          }
        },
        "required": [
          "name",
          "ico",
          "dic",
          "icDph",
          "municipality",
          "streetName",
          "buildingNumber",
          "propertyRegistrationNumber",
          "postalCode",
          "country",
          "vatPayer",
          "manualVatPayer"
        ]
      },
      "ReceiptUnitDto": {
        "type": "object",
        "properties": {
          "cashRegisterCode": {
            "type": "string",
            "description": "eKasa cash-register code of the issuing unit.",
            "example": "88812345678901234567"
          },
          "name": {
            "type": "string",
            "nullable": true
          },
          "unitType": {
            "type": "string",
            "nullable": true
          },
          "municipality": {
            "type": "string",
            "example": "Košice"
          },
          "streetName": {
            "type": "string",
            "example": "Hlavná"
          },
          "buildingNumber": {
            "type": "string",
            "example": "12"
          },
          "propertyRegistrationNumber": {
            "type": "string",
            "nullable": true
          },
          "postalCode": {
            "type": "string",
            "example": "04001"
          },
          "country": {
            "type": "string",
            "example": "SK"
          }
        },
        "required": [
          "cashRegisterCode",
          "name",
          "unitType",
          "municipality",
          "streetName",
          "buildingNumber",
          "propertyRegistrationNumber",
          "postalCode",
          "country"
        ]
      },
      "ReceiptAttachmentDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "example": 77
          },
          "filename": {
            "type": "string",
            "example": "IMG_4821.jpg"
          },
          "url": {
            "type": "string",
            "description": "Fetchable URL of the attachment.",
            "example": "https://api.uctovisko.sk/storage/receipts/4821/IMG_4821.jpg"
          },
          "mimetype": {
            "type": "string",
            "example": "image/jpeg"
          },
          "size": {
            "type": "number",
            "description": "Size in bytes.",
            "nullable": true,
            "example": 184320
          },
          "order": {
            "type": "number",
            "description": "Display order, ascending.",
            "example": 0
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "filename",
          "url",
          "mimetype",
          "size",
          "order",
          "createdAt"
        ]
      },
      "ReceiptDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "example": 4821
          },
          "receiptId": {
            "type": "string",
            "description": "eKasa receipt identifier (`O-…`) — the value printed on the receipt, not the `id`. Use `GET …/receipt/find/{receiptId}` to look one up in eKasa before importing it.",
            "example": "O-0A1B2C3D4E5F60718293A4B5C6D7E8F9"
          },
          "receiptNumber": {
            "type": "number",
            "description": "Sequence number within the cash register.",
            "example": 1734
          },
          "type": {
            "type": "string",
            "description": "eKasa receipt type as reported by the register.",
            "example": "UHRADA"
          },
          "cashRegisterCode": {
            "type": "string",
            "example": "88812345678901234567"
          },
          "ico": {
            "type": "string",
            "description": "Issuer IČO.",
            "example": "54321678"
          },
          "dic": {
            "type": "string",
            "description": "Issuer DIČ.",
            "example": "2120123456"
          },
          "icDph": {
            "type": "string",
            "description": "Issuer IČ DPH.",
            "example": "SK2120123456"
          },
          "issueDate": {
            "type": "string",
            "description": "Moment the receipt was issued at the register.",
            "format": "date-time",
            "nullable": true
          },
          "createDate": {
            "type": "string",
            "description": "Moment eKasa recorded it. Usually equal to `issueDate`.",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "description": "Moment the row was stored in Účtovisko.",
            "format": "date-time"
          },
          "source": {
            "type": "string",
            "description": "UC-829 — where the data came from, derived (not stored): `ekasa` when the row carries both the eKasa identifier and the register control code (`receiptId` + `okp`), `manual` otherwise. Read-only; writing it is ignored. Present on the READ endpoints (`GET …/receipt` and `GET …/receipt/{id}`) — the create/update acknowledgements and the webhook payloads keep their previous shape.",
            "enum": [
              "ekasa",
              "manual"
            ],
            "example": "ekasa"
          },
          "verified": {
            "type": "boolean",
            "description": "UC-829 — true only when the fiscal data is confirmed by eKasa (`source = ekasa`) and the receipt is not a paragón. Derived, read-only, same endpoints as `source`.",
            "example": true
          },
          "totalPrice": {
            "type": "number",
            "description": "Total **including** VAT. A `float` column → a JSON number, not a string.",
            "example": 11.98
          },
          "taxBaseBasic": {
            "type": "number",
            "nullable": true,
            "example": 9.98
          },
          "taxBaseReduced": {
            "type": "number",
            "nullable": true,
            "example": null
          },
          "vatAmountBasic": {
            "type": "number",
            "nullable": true,
            "example": 2
          },
          "vatAmountReduced": {
            "type": "number",
            "nullable": true,
            "example": null
          },
          "vatRateBasic": {
            "type": "number",
            "nullable": true,
            "example": 20
          },
          "vatRateReduced": {
            "type": "number",
            "nullable": true,
            "example": 10
          },
          "freeTaxAmount": {
            "type": "number",
            "description": "Amount outside the VAT system.",
            "nullable": true,
            "example": null
          },
          "exemption": {
            "type": "boolean",
            "description": "Whether the receipt is VAT-exempt.",
            "example": false
          },
          "okp": {
            "type": "string",
            "description": "eKasa OKP (unique receipt identifier code). A fiscal integrity code printed on the receipt — public, not a credential.",
            "nullable": true
          },
          "pkp": {
            "type": "string",
            "description": "eKasa PKP (taxpayer signature code), printed on offline receipts.",
            "nullable": true
          },
          "paragon": {
            "type": "boolean",
            "description": "True for a hand-written paper receipt entered without eKasa data.",
            "example": false
          },
          "paragonNumber": {
            "type": "string",
            "nullable": true
          },
          "invoiceNumber": {
            "type": "string",
            "description": "Related invoice number when the receipt settles one.",
            "nullable": true
          },
          "transactionId": {
            "type": "string",
            "description": "Register transaction id, when the register supplied one.",
            "nullable": true
          },
          "customerId": {
            "type": "string",
            "nullable": true
          },
          "note": {
            "type": "string",
            "description": "User note.",
            "nullable": true
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReceiptItemDto"
            }
          },
          "organization": {
            "$ref": "#/components/schemas/ReceiptOrganizationDto"
          },
          "unit": {
            "$ref": "#/components/schemas/ReceiptUnitDto"
          },
          "attachments": {
            "description": "Always loaded (the relation is eager).",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReceiptAttachmentDto"
            }
          },
          "tag": {
            "type": "object",
            "description": "Category tag, or `null`.",
            "nullable": true,
            "properties": {
              "id": {
                "type": "number",
                "example": 3
              },
              "name": {
                "type": "string",
                "example": "Kancelária"
              }
            }
          }
        },
        "required": [
          "id",
          "receiptId",
          "receiptNumber",
          "type",
          "cashRegisterCode",
          "ico",
          "dic",
          "icDph",
          "issueDate",
          "createDate",
          "createdAt",
          "totalPrice",
          "taxBaseBasic",
          "taxBaseReduced",
          "vatAmountBasic",
          "vatAmountReduced",
          "vatRateBasic",
          "vatRateReduced",
          "freeTaxAmount",
          "exemption",
          "okp",
          "pkp",
          "paragon",
          "paragonNumber",
          "invoiceNumber",
          "transactionId",
          "customerId",
          "note",
          "items",
          "organization",
          "unit",
          "attachments",
          "tag"
        ]
      },
      "ReceiptDeleteResultDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "number",
            "example": 4821
          },
          "purged": {
            "type": "boolean",
            "description": "Present and `true` when the row was hard-deleted (`?purge=true`).",
            "example": true
          },
          "archived": {
            "type": "boolean",
            "description": "Present and `true` when the row was soft-archived (the default).",
            "example": true
          }
        },
        "required": [
          "id"
        ]
      },
      "ReceiptStatsDto": {
        "type": "object",
        "properties": {
          "monthlyExpenses": {
            "type": "number",
            "description": "Sum of receipt totals in the current calendar month.",
            "example": 412.37
          },
          "monthOnMonthChange": {
            "type": "number",
            "description": "Change against the previous month, as a percentage. May be negative.",
            "example": -8.4
          },
          "totalReceipts": {
            "type": "number",
            "description": "Number of non-archived receipts in the account.",
            "example": 318
          },
          "vatToDeduct": {
            "type": "number",
            "description": "Deductible VAT total over the same period.",
            "example": 68.72
          }
        },
        "required": [
          "monthlyExpenses",
          "monthOnMonthChange",
          "totalReceipts",
          "vatToDeduct"
        ]
      },
      "ReceiptLookupResultDto": {
        "type": "object",
        "properties": {
          "receipt": {
            "type": "object",
            "description": "Receipt as returned by the eKasa service, passed through unchanged. Shape is defined by Finančná správa, not by Účtovisko, so it is documented as a free-form object.",
            "additionalProperties": true
          },
          "isDuplicate": {
            "type": "boolean",
            "description": "True when this `receiptId` is already stored in the account.",
            "example": false
          },
          "status": {
            "type": "string",
            "description": "UC-829 — normalized outcome of the lookup. `duplicate` outranks `found`: the receipt is in eKasa but this account already stored it. The three failure values are reported on the error envelope instead (`{ s: \"error\", d: \"<alias>\", status: \"<value>\" }`), so one client error path can branch on them: `not_found` → `receipt_not_found_in_ekasa`, `too_old` → `receipt_too_old_for_ekasa`, `ekasa_unavailable` → `ekasa_unavailable`.",
            "enum": [
              "found",
              "duplicate",
              "not_found",
              "ekasa_unavailable",
              "too_old"
            ],
            "example": "found"
          },
          "suggestedCategoryId": {
            "type": "string",
            "description": "Category (receipt tag) id to preselect, matched from the issuer by the account‘s auto-pair rules (`autoPairOrganizations`, IČO or normalized name). `null` when no rule matches.",
            "nullable": true,
            "example": "7b2f3c1e-6c5a-4a1b-9f02-6c2f8a1d44e1"
          },
          "duplicates": {
            "description": "Up to three receipts of THIS account that already carry the same `receiptId`, newest first. Empty unless `isDuplicate` is true.",
            "additionalProperties": true,
            "example": [
              {
                "id": 4821,
                "receiptId": "O-0A1B2C3D4E5F60718293A4B5C6D7E8F9",
                "issueDate": "2026-10-16T05:42:00.000Z",
                "totalPrice": 64.2,
                "organizationName": "Slovnaft, a.s.",
                "tagId": "7b2f3c1e-6c5a-4a1b-9f02-6c2f8a1d44e1"
              }
            ],
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        },
        "required": [
          "receipt",
          "isDuplicate",
          "status",
          "suggestedCategoryId",
          "duplicates"
        ]
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ]
}
