{
  "openapi": "3.1.0",
  "info": {
    "title": "ReconSmith API",
    "version": "1.0.0",
    "description": "Accounting ledger with explainable settlement. Every write takes an Idempotency-Key; every list is cursor-paged; there is no daily call cap."
  },
  "servers": [
    {
      "url": "https://api.reconsmith.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key issued per client."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "maxLength": 255
        },
        "description": "Required on this call. Retrying with the same key returns the original response instead of doing it twice. Reusing a key with a different body is a 422."
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Liveness and database reachability",
        "security": [],
        "responses": {
          "200": {
            "description": "ok"
          }
        },
        "tags": [
          "Service"
        ]
      }
    },
    "/v1/parties": {
      "post": {
        "summary": "Create or update parties in bulk",
        "description": "Keyed on (source_system, external_ref). Safe to replay: an existing party is returned, not duplicated. A changed name is recorded as a rename, so history is preserved. For every optional detail field, null means LEAVE THE STORED VALUE ALONE and the empty string means clear it — so re-upserting a customer whose VAT number is blank on your side will not wipe one somebody entered here.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "items": {
                  "type": "object",
                  "required": [
                    "external_ref",
                    "name"
                  ],
                  "properties": {
                    "external_ref": {
                      "type": "string"
                    },
                    "name": {
                      "type": "string"
                    },
                    "source_system": {
                      "type": "string",
                      "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                    },
                    "party_type": {
                      "type": "string",
                      "enum": [
                        "ORGANISATION",
                        "PERSON"
                      ]
                    },
                    "role": {
                      "type": "string",
                      "enum": [
                        "CUSTOMER",
                        "SUPPLIER",
                        "EMPLOYEE"
                      ]
                    },
                    "email": {
                      "type": "string",
                      "description": "Required when party_type is PERSON."
                    },
                    "ccy": {
                      "type": "string",
                      "default": "ZAR",
                      "description": "Currency of the account provisioned for this party. One account per currency."
                    },
                    "parent_external_ref": {
                      "type": "string",
                      "description": "Your reference for the HEAD account, when this one is a branch of it. The VAT number belongs to the legal entity, not to the account, so two accounts of one group may share one — but only when the relationship is declared here. Two levels only: a branch of a branch is refused. The parent must already exist, so send parents before branches; earlier in the same array is fine."
                    },
                    "vat_number": {
                      "type": "string",
                      "description": "null leaves the stored value alone. The empty string clears it. A VAT number already held by a DIFFERENT legal entity is refused, and the error names who holds it — the usual cause is the same customer entered twice. Two accounts of one legal entity may share one: declare the relationship with parent_external_ref."
                    },
                    "company_reg": {
                      "type": "string",
                      "description": "Same rules as vat_number."
                    },
                    "phone": {
                      "type": "string",
                      "description": "Same rules as vat_number."
                    },
                    "address": {
                      "type": "object",
                      "description": "The invoice address, structured. Sent as a whole or not at all: it replaces the current one rather than merging line by line, because an address half old and half new was never real. Omit it to leave the stored address alone.",
                      "properties": {
                        "unit": {
                          "type": "string"
                        },
                        "building": {
                          "type": "string"
                        },
                        "street_no": {
                          "type": "string"
                        },
                        "street": {
                          "type": "string"
                        },
                        "suburb": {
                          "type": "string"
                        },
                        "city": {
                          "type": "string"
                        },
                        "province": {
                          "type": "string"
                        },
                        "postal_code": {
                          "type": "string"
                        },
                        "country_code": {
                          "type": "string",
                          "maxLength": 2
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Parties upserted. Each result carries the account_code the party is invoiced against — provisioned here, by ReconSmith, because the caller has no way to keep a code unique within a ledger. Replaying returns the same code; no second account is created.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "parties": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "party_id",
                          "external_ref",
                          "created",
                          "account_code",
                          "sub_account_id",
                          "account_created"
                        ],
                        "properties": {
                          "party_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "external_ref": {
                            "type": "string"
                          },
                          "created": {
                            "type": "boolean",
                            "description": "The party was created by this call."
                          },
                          "account_code": {
                            "type": "string",
                            "description": "Pass this as account_code on /v1/invoices and /v1/payments."
                          },
                          "sub_account_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "account_created": {
                            "type": "boolean",
                            "description": "The account was provisioned by this call."
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Validation or idempotency conflict"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/parties/incomplete": {
      "get": {
        "summary": "Customers whose VAT number or address is missing",
        "description": "The list worth asking about. A South African tax invoice over R5,000 must carry the customer's VAT number and address, and a prompt sent to every customer is a prompt most of them ignore — so this is who is actually missing something. Ordered by what they have been invoiced, because the customer you bill most is the one whose missing VAT number costs you soonest. Each row carries your own external_ref, so the list can be acted on without mapping names.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 500,
              "maximum": 2000
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "missing_vat and missing_address are counted separately because they are different asks: a customer with no address cannot be sent a compliant invoice at all, while one with no VAT number can, below R5,000.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "missing_vat": {
                      "type": "integer"
                    },
                    "missing_address": {
                      "type": "integer"
                    },
                    "customers": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "party_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "account_code": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "has_vat": {
                            "type": "boolean"
                          },
                          "has_address": {
                            "type": "boolean"
                          },
                          "invoiced_total": {
                            "type": "number"
                          },
                          "external_ref": {
                            "type": "string",
                            "nullable": true
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "This API key has no default entity."
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/parties/search": {
      "get": {
        "summary": "Smart customer lookup",
        "description": "Searches names, FORMER names, VAT and company numbers, external refs, account codes, branch numbers, e-mail and address text. Every hit carries matched_via so the caller can show why it appeared.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked matches"
          }
        },
        "tags": [
          "Customers"
        ]
      }
    },
    "/v1/purchase-invoices": {
      "post": {
        "summary": "Post supplier bills in bulk",
        "description": "Calls rs.post_purchase_invoice: one balanced journal, an open-period check, and the payable account resolved from the party.\n\nUnlike /v1/invoices, supplier_doc_no IS required. A supplier's invoice number is theirs, not ours — we neither mint it nor control it, and it is what goes on the remittance so they can find the payment. Where a slip has no number of its own, send your external_ref.\n\nIdempotent on (source_system, external_ref): a repeat returns the existing document with created = false and posts nothing.\n\nTax: leave tax_code off a line and the posting function defaults to SRI, standard rated inputs, VAT201 box 14. For a purchase that carries no VAT — fuel in South Africa being the usual case — a zero-tax line is stamped with the entity's zero-rated input code instead (ZRI in South Africa, VOOR0 in the Netherlands). Send tax_code explicitly to override.\n\nDimensions are validated on BOTH the key and the value, and keys are case-sensitive. An unknown dimension or an unregistered value is refused and the whole bill fails. Create them with POST /v1/dimensions first.\n\nattachments (135): the supplier's own invoice can ride along on the bill. On a repeat (created = false) the attachments are still kept, so a file sent with a retry is not lost.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "items": {
                  "type": "object",
                  "required": [
                    "external_ref",
                    "supplier_doc_no",
                    "doc_date",
                    "lines"
                  ],
                  "properties": {
                    "external_ref": {
                      "type": "string",
                      "description": "Your identifier, e.g. APP-FUEL-1234. The idempotency key for this document."
                    },
                    "supplier_doc_no": {
                      "type": "string",
                      "description": "The supplier's own invoice or slip number. Send external_ref where there is none."
                    },
                    "supplier_external_ref": {
                      "type": "string",
                      "description": "Your supplier id, as pushed to /v1/parties with role = SUPPLIER."
                    },
                    "account_code": {
                      "type": "string",
                      "description": "Alternative: the account_code returned by /v1/parties."
                    },
                    "doc_date": {
                      "type": "string",
                      "format": "date"
                    },
                    "due_date": {
                      "type": "string",
                      "format": "date",
                      "description": "Omit to let the supplier's terms derive it."
                    },
                    "ccy": {
                      "type": "string",
                      "default": "ZAR"
                    },
                    "reference": {
                      "type": "string",
                      "description": "Printed on the bill and shown on the supplier statement. For fuel, the vehicle registration."
                    },
                    "notes": {
                      "type": "string"
                    },
                    "source_system": {
                      "type": "string",
                      "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                    },
                    "lines": {
                      "type": "array",
                      "minItems": 1,
                      "items": {
                        "type": "object",
                        "required": [
                          "description",
                          "amount_excl_tax"
                        ],
                        "properties": {
                          "description": {
                            "type": "string"
                          },
                          "amount_excl_tax": {
                            "type": "number",
                            "description": "The net amount, as it appears on the supplier's document."
                          },
                          "tax_amount": {
                            "type": "number",
                            "default": 0
                          },
                          "account_code": {
                            "type": "string",
                            "description": "The expense account, e.g. 6070 for fuel."
                          },
                          "tax_code": {
                            "type": "string",
                            "description": "Optional. Defaults to SRI, or to the zero-rated input code when tax_amount is 0."
                          },
                          "dimensions": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "string"
                            },
                            "description": "e.g. {\"VEHICLE\": \"JF 24 PV GP\"}. Keys are case-sensitive and both key and value must already exist."
                          }
                        }
                      }
                    },
                    "attachments": {
                      "type": "array",
                      "description": "The supplier's own document as it arrived. PDF, PNG, JPEG or WebP; the type is read from the bytes. Up to 8 MB per file, and keep the whole request under 12 MB; send larger files one at a time to /v1/purchase-invoices/{external_ref}/attachments. The same file sent again is kept once.",
                      "items": {
                        "type": "object",
                        "required": [
                          "file_name",
                          "content_base64"
                        ],
                        "properties": {
                          "file_name": {
                            "type": "string"
                          },
                          "content_type": {
                            "type": "string",
                            "description": "Optional; not trusted."
                          },
                          "content_base64": {
                            "type": "string",
                            "description": "The file, base64. A data: URL prefix is accepted."
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Posted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "purchase_invoices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "document_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "external_ref": {
                            "type": "string"
                          },
                          "created": {
                            "type": "boolean",
                            "description": "false when this external_ref was already posted."
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Unknown supplier, a party with no SUPPLIER account, or an unknown dimension key or value."
          }
        },
        "tags": [
          "Purchases"
        ]
      }
    },
    "/v1/dimensions": {
      "get": {
        "summary": "List the dimensions and values this entity accepts",
        "description": "What a line may be tagged with. Worth reading before posting: a line carrying an unknown key or value is refused and the whole document fails.",
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "tags": [
          "Purchases"
        ]
      },
      "post": {
        "summary": "Create dimensions and their values",
        "description": "Needed because dimensions are validated on both the key and the value. A new vehicle registration must exist here before a fuel bill carrying it will post.\n\nCodes are upper-cased: VEHICLE and vehicle are not the same dimension, and only the first exists.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "code",
                    "name",
                    "values"
                  ],
                  "properties": {
                    "code": {
                      "type": "string",
                      "example": "VEHICLE"
                    },
                    "name": {
                      "type": "string",
                      "example": "Vehicle"
                    },
                    "required": {
                      "type": "boolean",
                      "default": false,
                      "description": "true refuses any line of the applicable type that does not carry it."
                    },
                    "applies_to": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "default": [
                        "INCOME",
                        "EXPENSE"
                      ]
                    },
                    "values": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "code"
                        ],
                        "properties": {
                          "code": {
                            "type": "string",
                            "example": "JF 24 PV GP"
                          },
                          "name": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        },
        "tags": [
          "Purchases"
        ]
      }
    },
    "/v1/invoices": {
      "post": {
        "summary": "Post sales invoices in bulk",
        "description": "Calls the ledger's own posting function: one balanced journal, an open-period check, terms taken from the billing party, and the receivable account resolved from the party.\n\ndoc_no is NOT accepted. ReconSmith mints the tax invoice number from its own sequence, and takes the number inside the posting transaction, so a failed invoice returns it instead of burning it — the sequence has no gaps. A sales order number legitimately HAS gaps, because orders get cancelled, so passing one through as the invoice number would import those gaps into a sequence an auditor expects to be unbroken. Put the order number in external_ref, and in reference if it should print on the invoice.\n\nNo settlement flag is returned: status is derived from allocations and never stored. Read it from GET /v1/documents.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "items": {
                  "type": "object",
                  "required": [
                    "external_ref",
                    "doc_date",
                    "lines"
                  ],
                  "properties": {
                    "external_ref": {
                      "type": "string",
                      "description": "Your identifier — typically the sales order number. The idempotency key for this document."
                    },
                    "customer_external_ref": {
                      "type": "string",
                      "description": "Your customer id, as pushed to /v1/parties. Preferred: you never learn our codes."
                    },
                    "account_code": {
                      "type": "string",
                      "description": "Alternative: the account_code returned by /v1/parties."
                    },
                    "doc_date": {
                      "type": "string",
                      "format": "date"
                    },
                    "due_date": {
                      "type": "string",
                      "format": "date",
                      "description": "Omit to let the billing party's terms derive it."
                    },
                    "ccy": {
                      "type": "string",
                      "default": "ZAR"
                    },
                    "reference": {
                      "type": "string",
                      "description": "Printed on the invoice. The order number belongs here."
                    },
                    "notes": {
                      "type": "string"
                    },
                    "source_system": {
                      "type": "string",
                      "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                    },
                    "lines": {
                      "type": "array",
                      "minItems": 1,
                      "items": {
                        "type": "object",
                        "required": [
                          "description",
                          "amount_excl_tax",
                          "tax_amount"
                        ],
                        "properties": {
                          "description": {
                            "type": "string"
                          },
                          "amount_excl_tax": {
                            "type": "number"
                          },
                          "tax_amount": {
                            "type": "number"
                          },
                          "account_code": {
                            "type": "string",
                            "description": "Revenue account, e.g. \"4010\". Friendlier than carrying our UUIDs in your config."
                          },
                          "ledger_account_id": {
                            "type": "string",
                            "format": "uuid",
                            "description": "Alternative to account_code."
                          },
                          "quantity": {
                            "type": "number",
                            "default": 1
                          },
                          "unit_price": {
                            "type": "number",
                            "description": "Omit and it is derived from amount_excl_tax / quantity."
                          },
                          "branch_id": {
                            "type": "string",
                            "format": "uuid",
                            "description": "Chain customers: the branch that incurred the charge. Its branch_number prints on the statement line."
                          },
                          "site_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "dimensions": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "string"
                            },
                            "description": "Analytic tags. Keys and values must already be registered or the line is refused."
                          },
                          "tax_code": {
                            "type": "string",
                            "description": "Optional. SR (standard rate) by default; send ZR for zero-rated or EX for exempt supplies."
                          },
                          "item_code": {
                            "type": "string",
                            "description": "Optional. The product, by its code in the product list (GET /v1/items)."
                          }
                        }
                      }
                    },
                    "billing_address": {
                      "type": "object",
                      "description": "Optional. The address this order was billed to, kept on the invoice so it prints that address whatever the customer's address becomes later. Left out, the invoice prints the customer's current invoice address.",
                      "properties": {
                        "unit": {
                          "type": "string"
                        },
                        "building": {
                          "type": "string"
                        },
                        "street_no": {
                          "type": "string"
                        },
                        "street": {
                          "type": "string"
                        },
                        "suburb": {
                          "type": "string"
                        },
                        "city": {
                          "type": "string"
                        },
                        "province": {
                          "type": "string"
                        },
                        "postal_code": {
                          "type": "string"
                        },
                        "country_code": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Posted. Each result carries document_id and the external_ref you sent; created:false means it was already posted under that ref."
          },
          "422": {
            "description": "Rejected by the ledger — unknown customer, closed period, unregistered dimension, unbalanced journal. The detail carries the database's own message."
          }
        },
        "tags": [
          "Invoices and credit notes"
        ]
      }
    },
    "/v1/payments": {
      "post": {
        "summary": "Post receipts in bulk",
        "description": "Posts through the ledger's receipt function: Dr bank, Cr receivables control, one balanced journal. The receipt number is minted here. A receipt with nothing allocated to it is a legitimate state — push it when the money arrives and allocate when you know what it paid.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "items": {
                  "type": "object",
                  "required": [
                    "external_ref",
                    "doc_date",
                    "amount"
                  ],
                  "properties": {
                    "external_ref": {
                      "type": "string"
                    },
                    "customer_external_ref": {
                      "type": "string"
                    },
                    "account_code": {
                      "type": "string"
                    },
                    "doc_date": {
                      "type": "string",
                      "format": "date"
                    },
                    "amount": {
                      "type": "number",
                      "description": "Positive. A refund is a credit note plus a payment out, never a negative receipt."
                    },
                    "bank_account_id": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Omit and the entity's active bank account is used."
                    },
                    "reference": {
                      "type": "string"
                    },
                    "source_system": {
                      "type": "string",
                      "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "422": {
            "description": "Rejected by the ledger"
          }
        },
        "tags": [
          "Payments and allocations"
        ]
      }
    },
    "/v1/allocations": {
      "post": {
        "summary": "Allocate payments to invoices",
        "description": "Line-granular settlement. One R20 000 receipt clearing four invoices is four allocations, and the statement shows all four under the receipt. Over-allocating is refused by the database, not by the caller's discipline.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": [
                    "payment_external_ref",
                    "invoice_external_ref",
                    "amount"
                  ],
                  "properties": {
                    "payment_external_ref": {
                      "type": "string"
                    },
                    "invoice_external_ref": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Allocated"
          },
          "422": {
            "description": "Over-allocation or wrong direction"
          }
        },
        "tags": [
          "Payments and allocations"
        ]
      }
    },
    "/v1/accounts/{code}/statement": {
      "get": {
        "summary": "Statement with settlement trace",
        "description": "Each payment line carries settlement_trace: which invoices it settled, for how much, and the branch number for chain customers.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Statement lines"
          },
          "404": {
            "description": "Unknown account"
          }
        },
        "tags": [
          "Reading the books"
        ]
      }
    },
    "/v1/accounts/{code}/aged": {
      "get": {
        "summary": "Aged analysis",
        "description": "Ages off due_date, which honours the billing party's terms basis. Statement-terms customers age as one block.",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "asOf",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Buckets"
          }
        },
        "tags": [
          "Reading the books"
        ]
      }
    },
    "/v1/accounts/{code}/open-items": {
      "get": {
        "summary": "Unsettled documents",
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Open items"
          }
        },
        "tags": [
          "Reading the books"
        ]
      }
    },
    "/v1/changes": {
      "get": {
        "summary": "Change feed",
        "description": "Everything that moved since a cursor. One call instead of polling six endpoints. Cursor-paged, because offsets shift under concurrent writes and a syncing client silently skips rows.",
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int64",
              "default": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 500,
              "maximum": 1000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Changes plus next_cursor"
          }
        },
        "tags": [
          "Reading the books"
        ]
      }
    },
    "/v1/bank-transactions/{id}/suggestions": {
      "get": {
        "summary": "Reconciliation suggestions",
        "description": "Ranked candidates with the features that produced each score. Layers: exact reference, exact amount, learned memory, fuzzy name. Nothing here posts anything.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Suggestions with confidence bands"
          }
        },
        "tags": [
          "Reconciliation"
        ]
      }
    },
    "/v1/recon/queue": {
      "get": {
        "summary": "Bank lines awaiting review",
        "responses": {
          "200": {
            "description": "Queue"
          }
        },
        "tags": [
          "Reconciliation"
        ]
      }
    },
    "/v1/match-candidates/{id}/accept": {
      "post": {
        "summary": "Accept a suggestion",
        "description": "Writes the match and teaches the matcher. Every other candidate on that line is recorded as rejected — the negative training signal.",
        "responses": {
          "200": {
            "description": "Accepted"
          }
        },
        "tags": [
          "Reconciliation"
        ]
      }
    },
    "/v1/match-candidates/{id}/reject": {
      "post": {
        "summary": "Reject a suggestion",
        "responses": {
          "200": {
            "description": "Rejected"
          }
        },
        "tags": [
          "Reconciliation"
        ]
      }
    },
    "/v1/credit-notes": {
      "post": {
        "summary": "Credit a customer — against an invoice, or on the account",
        "description": "Three shapes, because all three happen:\n\n1. invoice_external_ref, no lines — credit the whole invoice. The ordinary cancelled-order case.\n2. invoice_external_ref with lines — credit part of that invoice.\n3. customer_external_ref with lines, no invoice — a credit note tied to no invoice at all: goodwill, a pricing correction, a deposit refund, a settlement. It is posted against the customer's account and sits there as money owed, and POST /v1/allocations applies it to any later invoice when they spend it.\n\nAn invoice is never deleted and never renumbered. It keeps its number and a credit note cancels it out: that is what keeps the invoice sequence unbroken when an order falls away, and the audit trail append-only. Credit notes have their own gapless sequence (CRN-).\n\napplied: false means nothing was set against an invoice — either the invoice was already paid, or the credit note was never tied to one. Either way the value is credit the customer holds, and it shows in GET /v1/credits and GET /v1/customers/{ref}/credit.\n\nmark_for_refund records that the customer wants the money back rather than a credit against their next order. The credit note is raised either way; this only records which they chose.\n\nreason is never optional. It is the first thing anyone asks about a credit note, and the ledger refuses one without it.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "items": {
                  "type": "object",
                  "required": [
                    "reason",
                    "external_ref"
                  ],
                  "properties": {
                    "invoice_external_ref": {
                      "type": "string",
                      "description": "The invoice being credited. Omit for a credit note on the account, and then lines are required."
                    },
                    "reason": {
                      "type": "string",
                      "description": "Stored on the credit note. Say why — an auditor reads this."
                    },
                    "external_ref": {
                      "type": "string",
                      "description": "Your identifier for the credit note itself."
                    },
                    "doc_date": {
                      "type": "string",
                      "format": "date"
                    },
                    "lines": {
                      "type": "array",
                      "description": "Required when no invoice is named; omit to credit a whole invoice.",
                      "items": {
                        "type": "object",
                        "required": [
                          "description",
                          "amount_excl_tax",
                          "tax_amount"
                        ],
                        "properties": {
                          "description": {
                            "type": "string"
                          },
                          "amount_excl_tax": {
                            "type": "number"
                          },
                          "tax_amount": {
                            "type": "number"
                          },
                          "account_code": {
                            "type": "string",
                            "description": "Revenue account, e.g. \"4010\". Friendlier than carrying our UUIDs in your config."
                          },
                          "ledger_account_id": {
                            "type": "string",
                            "format": "uuid",
                            "description": "Alternative to account_code."
                          },
                          "quantity": {
                            "type": "number",
                            "default": 1
                          },
                          "unit_price": {
                            "type": "number",
                            "description": "Omit and it is derived from amount_excl_tax / quantity."
                          },
                          "branch_id": {
                            "type": "string",
                            "format": "uuid",
                            "description": "Chain customers: the branch that incurred the charge. Its branch_number prints on the statement line."
                          },
                          "site_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "dimensions": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "string"
                            },
                            "description": "Analytic tags. Keys and values must already be registered or the line is refused."
                          }
                        }
                      }
                    },
                    "source_system": {
                      "type": "string",
                      "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                    },
                    "mark_for_refund": {
                      "type": "boolean",
                      "default": false,
                      "description": "The customer opted for a refund rather than keeping the credit on account."
                    },
                    "customer_external_ref": {
                      "type": "string",
                      "description": "The customer, for a credit note not tied to an invoice. Your own id, as pushed to /v1/parties."
                    },
                    "account_code": {
                      "type": "string",
                      "description": "Alternative to customer_external_ref."
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Credited"
          },
          "422": {
            "description": "Neither an invoice nor a customer with lines; unknown invoice or customer; no reason; or nothing left to credit on an invoice already settled."
          }
        },
        "tags": [
          "Invoices and credit notes"
        ]
      }
    },
    "/v1/documents": {
      "get": {
        "summary": "Bulk settlement status by your own identifiers",
        "description": "Which of the invoices you pushed are still open. Derived from allocations and never stored, so it is always current — do not cache it as a boolean, it is wrong the moment a receipt is allocated. Refs that match nothing come back under not_found, so a syncing caller sees what never landed instead of inferring it from a short list.\n\nEach row splits the settling side, because 'settled' is not one fact: paid_amount is receipts, credited_amount is credit notes, and state is derived from the two — OPEN, PART_PAID, PAID, PART_CREDITED, CREDITED, PAID_AND_CREDITED or VOIDED. An invoice paid and an invoice cancelled-and-credited both show settlement_status SETTLED, and an app that renders them the same way is lying to the customer. credit_note_nos lists the credit notes against the document, marked_for_refund says the customer asked for the money back, and last_movement_at is when an allocation last touched it. Everything is derived from the allocation rows, so it cannot disagree with the ledger — learn that something moved from GET /v1/changes (ALLOCATED) and re-read rather than caching a flag.",
        "parameters": [
          {
            "name": "externalRefs",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated, up to 1000."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "document_id, doc_no, doc_type, total_incl_tax, allocated, outstanding, settlement_status, status, reference — plus not_found"
          }
        },
        "tags": [
          "Documents"
        ]
      }
    },
    "/v1/sales-orders": {
      "post": {
        "summary": "Push sales orders in",
        "description": "An order is PRE-LEDGER: no journal, no control account, no number an auditor will ask about. That is why it can be deleted outright, and why its numbering may gap freely.\n\norder_no is optional. Supply your own and ReconSmith keeps it; omit it and ReconSmith mints one (SO-000001). Both are correct — a system with its own order numbering should keep it, and a company with no upstream system needs ReconSmith to number its own. The same freedom is deliberately NOT given to invoice numbers.\n\nAn order raises no invoice. That happens on exactly two events: payment confirmed, or fulfilment.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "items": {
                  "type": "object",
                  "required": [
                    "external_ref",
                    "lines"
                  ],
                  "properties": {
                    "external_ref": {
                      "type": "string",
                      "description": "Your identifier for the order."
                    },
                    "customer_external_ref": {
                      "type": "string",
                      "description": "Your customer id. Preferred."
                    },
                    "account_code": {
                      "type": "string"
                    },
                    "order_no": {
                      "type": "string",
                      "description": "Yours, or omit it and one is minted."
                    },
                    "order_date": {
                      "type": "string",
                      "format": "date"
                    },
                    "origin": {
                      "type": "string",
                      "enum": [
                        "MANUAL",
                        "TELEMETRY",
                        "ACO",
                        "API",
                        "PORTAL"
                      ],
                      "default": "API",
                      "description": "How the order arrived, so a human can see which were raised by a device."
                    },
                    "reference": {
                      "type": "string"
                    },
                    "notes": {
                      "type": "string"
                    },
                    "source_system": {
                      "type": "string",
                      "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                    },
                    "lines": {
                      "type": "array",
                      "minItems": 1,
                      "items": {
                        "type": "object",
                        "required": [
                          "description"
                        ],
                        "properties": {
                          "description": {
                            "type": "string"
                          },
                          "quantity": {
                            "type": "number",
                            "default": 1
                          },
                          "unit_price": {
                            "type": "number"
                          },
                          "tax_amount": {
                            "type": "number"
                          },
                          "account_code": {
                            "type": "string"
                          },
                          "branch_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "site_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "dimensions": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created; each result carries sales_order_id and order_no"
          }
        },
        "tags": [
          "Sales orders"
        ]
      },
      "get": {
        "summary": "Pull sales orders out",
        "description": "Orders with their lines, in one call. Filter by status, origin, payment status, or what changed since a moment.\n\nEach order says whether it is paid: payment_status (UNPAID, PART_PAID, PAID), amount_paid, outstanding, paid_at (the date of the bank line that paid it), bank_reference, invoice_no and invoice_external_ref. A bank line carrying the order number and its total to the cent invoices the order (invoiced_on_event PAYMENT) and pays it with no person; anything less certain waits on the reconcile screen.\n\nPolling: send the reply's as_of back as since. Orders changed or paid after it come back, oldest change first.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "DRAFT",
                "OPEN",
                "FULFILLED",
                "CANCELLED",
                "INVOICED"
              ]
            }
          },
          {
            "name": "origin",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "MANUAL",
                "TELEMETRY",
                "ACO",
                "API",
                "PORTAL"
              ]
            }
          },
          {
            "name": "paymentStatus",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "UNPAID",
                "PART_PAID",
                "PAID"
              ]
            }
          },
          {
            "name": "since",
            "in": "query",
            "description": "Orders changed or paid after this moment (ISO 8601). A plain date means its midnight.",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 200,
              "maximum": 1000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "count, as_of, and sales_orders: each with its lines, invoice_no and invoice_external_ref when invoiced, invoiced_on_event, total_incl_tax, amount_paid, outstanding, payment_status, paid_at, bank_reference, updated_at"
          }
        },
        "tags": [
          "Sales orders"
        ]
      }
    },
    "/v1/sales-orders/{externalRef}/fulfil": {
      "post": {
        "summary": "Fulfilment — event two of the two that raise an invoice",
        "description": "Your system says the order was fulfilled; ReconSmith raises the invoice from the order's own lines and takes the next tax invoice number. Idempotent: an order already invoiced (because it was paid up front) returns the invoice it has rather than a second one.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "doc_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "due_date": {
                    "type": "string",
                    "format": "date"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "invoice_id, invoice_no, invoiced_on_event"
          },
          "404": {
            "description": "Unknown order"
          }
        },
        "tags": [
          "Sales orders"
        ]
      }
    },
    "/v1/sales-orders/{externalRef}/payment-confirmation": {
      "post": {
        "summary": "Gateway says paid — event one of the two",
        "description": "The gateway's word, NOT the bank's. Raises the invoice if the order has none, posts the receipt into that gateway's CLEARING account, and allocates it. The bank is untouched: no cash is claimed until the settlement actually lands, so the bank reconciliation is never out by money in transit.\n\nIdempotent on (gateway, gateway_ref): a retried webhook returns the same invoice and receipt rather than paying twice. A later fulfilment of the same order raises nothing new.\n\nThe clearing balance is 'money the gateway owes us'. Anything past the gateway's settlement window shows as overdue in GET /v1/gateway-payments, and that total ties to the clearing account on the trial balance — so the exceptions list cannot quietly disagree with the books.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "gateway_code",
                  "amount",
                  "gateway_ref"
                ],
                "properties": {
                  "gateway_code": {
                    "type": "string",
                    "description": "e.g. LESAKA"
                  },
                  "paid_with": {
                    "type": "string",
                    "description": "The gateway's payment type: Visa, Mastercard, MasterPass, EFT_OZOW. Ozow and Masterpass are paid out one payment at a time, so such a payment waits for its own bank line."
                  },
                  "amount": {
                    "type": "number",
                    "description": "Gross, as the customer paid it. Fees are handled at settlement."
                  },
                  "gateway_ref": {
                    "type": "string",
                    "description": "The gateway's own transaction id. The idempotency key for this payment."
                  },
                  "confirmed_at": {
                    "type": "string",
                    "format": "date-time"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "invoice_no, receipt_id, status IN_TRANSIT"
          },
          "404": {
            "description": "Unknown order"
          },
          "422": {
            "description": "Unknown or inactive gateway"
          }
        },
        "tags": [
          "Sales orders"
        ]
      }
    },
    "/v1/sales-orders/{externalRef}": {
      "get": {
        "summary": "One sales order, and whether it is paid",
        "description": "The same shape as one entry of GET /v1/sales-orders.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "The order"
          },
          "404": {
            "description": "Unknown order"
          }
        },
        "tags": [
          "Sales orders"
        ]
      },
      "delete": {
        "summary": "Delete or cancel an un-invoiced order",
        "description": "An order with no invoice simply goes — lines cascade with it. Nothing downstream ever saw it.\n\nPass cancelOnly=true to keep the row with status CANCELLED instead.\n\nOnce the order has an invoice this refuses: at that point it is part of a document trail, and a credit note is the only correct answer. POST /v1/credit-notes.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          },
          {
            "name": "cancelOnly",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "reason",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted or cancelled"
          },
          "404": {
            "description": "Unknown order"
          },
          "422": {
            "description": "The order was invoiced; credit it instead"
          }
        },
        "tags": [
          "Sales orders"
        ]
      }
    },
    "/v1/gateway-settlements": {
      "post": {
        "summary": "The money landed in the bank, net of the gateway's cut",
        "description": "Dr bank what landed, Dr merchant fees the difference, Cr clearing the gross that was confirmed. Batched, because gateways settle in batches: name the gateway refs in the payout.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "gateway_code",
                  "gateway_refs",
                  "amount_received"
                ],
                "properties": {
                  "gateway_code": {
                    "type": "string"
                  },
                  "gateway_refs": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "amount_received": {
                    "type": "number",
                    "description": "Net, as it appears on the bank statement. The difference from the gross becomes the fee."
                  },
                  "bank_account_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "settled_on": {
                    "type": "string",
                    "format": "date"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "journal_id, gross, fee, payments_settled"
          },
          "422": {
            "description": "Refs not in transit, or a settlement larger than the gross confirmed"
          }
        },
        "tags": [
          "Card payments"
        ]
      }
    },
    "/v1/gateway-payments": {
      "get": {
        "summary": "In transit — the list that needs handling",
        "description": "Confirmed by a gateway, not yet in the bank. overdue is anything past that gateway's own settlement window (7 days by default). The total ties to the clearing account on the trial balance.",
        "parameters": [
          {
            "name": "overdueOnly",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "total_in_transit, overdue_count, and the payments with days_in_transit"
          }
        },
        "tags": [
          "Card payments"
        ]
      }
    },
    "/v1/customers/{externalRef}/credit": {
      "get": {
        "summary": "Customer credit — what the app shows",
        "description": "Credit the customer can spend on the next order, how much of it they asked to have refunded instead, and the documents behind the number so the app can say where each credit came from. Use it to apply a credit to the next order rather than refunding it.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "credit_available, marked_for_refund, spendable_on_next_order, documents"
          },
          "404": {
            "description": "Unknown customer"
          }
        },
        "tags": [
          "Payments and allocations"
        ]
      }
    },
    "/v1/documents/{externalRef}/pdf": {
      "get": {
        "summary": "The issued document as a PDF",
        "description": "The tax invoice or credit note on the ReconSmith letterhead, exactly as posted: our invoice number, the date and due date, our company details and VAT number as the letterhead stood on that date, the customer's name, address and VAT number, every line, the totals, and the reference (your order or work-order number).\n\nFetch it once when the invoice is posted and store it; fetch again if a credit note is raised against it. Your app then serves its stored copy, so a customer can still get their invoice when ReconSmith is slow or unreachable.\n\nDrawn by one renderer from the template's render_spec, and reissued on the branding of the document's own date — a copy fetched next year matches the one that was sent. The service does not draw PDFs itself: a second implementation would mean two versions of the same tax invoice, with no way to say which one the customer received.\n\nOnly a POSTED document has an issued PDF; anything else is a 409.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your identifier for the document — the order number you invoiced under."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "application/pdf, named for our document number, e.g. \"Tax invoice INV-00041.pdf\"",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "404": {
            "description": "Unknown document"
          },
          "409": {
            "description": "The document is not POSTED, so no PDF was ever issued"
          },
          "502": {
            "description": "The renderer is unreachable or refused"
          },
          "503": {
            "description": "No renderer is configured"
          }
        },
        "tags": [
          "Documents"
        ]
      }
    },
    "/v1/documents/{externalRef}/content": {
      "get": {
        "summary": "The issued document as JSON or XML",
        "description": "The same document as data: our invoice number, date and due date; our company details and VAT number from the letterhead for that date; the customer's name, address and VAT number; every line with description, quantity, unit price, amount excluding VAT and VAT; the totals, a tax summary by rate, and the reference.\n\nBuilt from the ledger rather than from what the caller pushed, so if your copy and ours ever disagree, ours is right by construction. Not needed when you store the PDF, but it is what you want to render the invoice natively in an app or to keep an archival XML copy. Bank account number is masked to the last four: the full number belongs on the PDF the supplier issues, not in a payload that gets cached.\n\nformat=xml, or an Accept header asking for XML, returns the XML rendering of the same facts.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "xml"
              ],
              "default": "json"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              },
              "application/xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Unknown document"
          }
        },
        "tags": [
          "Documents"
        ]
      }
    },
    "/v1/credits": {
      "get": {
        "summary": "Unused customer credit",
        "description": "Every credit still unused, for customers the caller knows. Scoped by the CUSTOMER's external reference, not the document's: a credit note a bookkeeper typed into the office for one of your customers is that customer's credit, and your app should show it alongside the ones you pushed. raised_via says which screen it came from (OFFICE, or your system, …).\\n\\nA credit note that was applied to an invoice has done its job and does not appear.\\n\\nEach row carries document_id and doc_no as well as external_ref, so an office-raised credit with no external_ref can still be addressed by the refund endpoints.\\n\\nPer customer, use GET /v1/customers/{ref}/credit instead.",
        "parameters": [
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          },
          {
            "name": "refundOnly",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Only credits the customer has asked to have refunded."
          },
          {
            "name": "knownOnly",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            },
            "description": "Default true: only customers that have an external reference in this source system. false returns every open credit, including customers you have never pushed."
          }
        ],
        "responses": {
          "200": {
            "description": "total_unused, total_refund_requested, and the credits with unused, refund_requested, refund_requested_at, refund_note and raised_via"
          }
        },
        "tags": [
          "Payments and allocations"
        ]
      }
    },
    "/v1/credit-notes/{externalRef}/refund-request": {
      "post": {
        "summary": "The customer asks for the money back",
        "description": "Flags an existing credit note as refund-requested. It is a flag, not a payment: nothing moves in the ledger and the customer can change their mind right up until the money leaves. Refused if the credit has already been used up.\\n\\nThe flag shows as refund_requested in GET /v1/credits, and refundOnly=true filters to these.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own external_ref, our document number (CRN-00004) or our document id. GET /v1/credits returns all three, so an office-raised credit with no external_ref is still addressable."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "note": {
                    "type": "string",
                    "description": "Why, or how they asked. Shown beside the credit."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "doc_no, unused, requested_at"
          },
          "404": {
            "description": "No such credit note"
          },
          "422": {
            "description": "Not a posted credit note, or nothing left to refund"
          }
        },
        "tags": [
          "Invoices and credit notes"
        ]
      },
      "delete": {
        "summary": "They changed their mind",
        "description": "Clears the flag. The credit itself is untouched and stays on the account.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own external_ref, our document number (CRN-00004) or our document id. GET /v1/credits returns all three, so an office-raised credit with no external_ref is still addressable."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "refund_requested is now false"
          },
          "404": {
            "description": "No such credit note"
          }
        },
        "tags": [
          "Invoices and credit notes"
        ]
      }
    },
    "/v1/credit-notes/{externalRef}/refund": {
      "post": {
        "summary": "Pay a credit back in money",
        "description": "The money leaves: Dr trade receivables, Cr bank. The refund is a settleable document (CUSTOMER_REFUND, its own REF- sequence) and the credit note is allocated to it, exactly as a receipt settles an invoice — so over-refunding is refused by the allocation rather than by trusting the caller.\\n\\nOmit amount to refund whatever is unused. A partial refund leaves the rest on the customer's account, which is a thing customers ask for. Omit bank_account_id and the entity's primary bank account is used.\\n\\nTakes an Idempotency-Key like every write: a retried refund must not pay the customer twice. Once credit_left reaches zero the credit drops off GET /v1/credits.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own external_ref, our document number (CRN-00004) or our document id. GET /v1/credits returns all three, so an office-raised credit with no external_ref is still addressable."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount": {
                    "type": "number",
                    "description": "Omit to refund the full unused balance."
                  },
                  "bank_account_id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "doc_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "reference": {
                    "type": "string",
                    "description": "Yours — the EFT reference, say."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "refund_no, amount, credit_left"
          },
          "404": {
            "description": "No such credit note"
          },
          "422": {
            "description": "Nothing left to refund, more than is unused, or a closed period"
          }
        },
        "tags": [
          "Invoices and credit notes"
        ]
      }
    },
    "/v1/items": {
      "get": {
        "summary": "Products and services",
        "responses": {
          "200": {
            "description": "{ items: [...] }"
          }
        },
        "tags": [
          "Items"
        ]
      },
      "post": {
        "summary": "Create or update products",
        "description": "A list. Matched by external_ref (your id) when sent, else by code. Keys: code, name, description, unit, sells, sales_price, sales_account_code, sales_tax_code, buys, purchase_price, purchase_account_code, purchase_tax_code, is_active, external_ref. A key not sent leaves the field alone. An invoice line names a product with item_code.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "{ items: [{ id, code }] }"
          },
          "422": {
            "description": "Refused, with the reason"
          }
        },
        "tags": [
          "Items"
        ]
      }
    },
    "/v1/employees/{externalRef}": {
      "put": {
        "summary": "Create or update an employee",
        "description": "PUT, not POST: you name the person, so the same call repeated is the same person and no Idempotency-Key is needed. null leaves a field alone — a caller that does not hold salaries sends a null gross on every sync, and a null that overwrote would zero the payroll.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own id for this person, e.g. TM-4471."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Required on first push. A later change is recorded as a dated rename, so a payslip already issued keeps the name it was issued in."
                  },
                  "email": {
                    "type": "string"
                  },
                  "employeeNo": {
                    "type": "string",
                    "description": "A label, printed on the payslip. Not the key: companies renumber staff."
                  },
                  "startedOn": {
                    "type": "string",
                    "format": "date",
                    "description": "Leave cycles run from this date, not from January."
                  },
                  "endedOn": {
                    "type": "string",
                    "format": "date"
                  },
                  "gross": {
                    "type": "number",
                    "description": "Per period. Omit if you do not hold salaries."
                  },
                  "periods": {
                    "type": "integer",
                    "enum": [
                      12,
                      13,
                      26,
                      52
                    ],
                    "default": 12
                  },
                  "employmentType": {
                    "type": "string",
                    "enum": [
                      "EMPLOYEE",
                      "DIRECTOR",
                      "CONTRACTOR"
                    ]
                  },
                  "sourceSystem": {
                    "type": "string",
                    "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "employeeId, partyId, accountCode, created"
          },
          "409": {
            "description": "This API key has no default company"
          },
          "422": {
            "description": "Refused, with the reason in words"
          }
        },
        "tags": [
          "Staff and payroll"
        ]
      }
    },
    "/v1/leave-types": {
      "get": {
        "summary": "The kinds of leave this company has",
        "description": "ReconSmith's codes, not yours. Seeded from the company's country — for South Africa, the BCEA minimums — and editable, because a contract may give more and never less.",
        "responses": {
          "200": {
            "description": "leaveTypes: [{ code, name, unit, daysPerCycle, cycleMonths, accrues, minServiceMonths, tracksBalance, isPaid, basis }]"
          }
        },
        "tags": [
          "Staff and payroll"
        ]
      }
    },
    "/v1/employees/{externalRef}/leave": {
      "get": {
        "summary": "What this person has left",
        "description": "Worked out every time from accrual, adjustments and leave taken. Never a stored number. Cycles run from the person's start date: somebody who started in March has an annual cycle ending in February.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "asAt",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Defaults to today in the company's own time zone."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "employeeRef, asAt, balances: [{ code, name, unit, cycleStart, cycleEnd, entitlement, accrued, adjustments, taken, balance, availableFrom, basis }]. balance is null where the type tracks none, such as unpaid leave."
          },
          "404": {
            "description": "Nobody here is known by that reference"
          }
        },
        "tags": [
          "Staff and payroll"
        ]
      },
      "post": {
        "summary": "Record approved leave",
        "description": "You own the request and the approval; this records what was taken. Idempotent on externalRef, so a retry after a timeout cannot deduct the same week twice — the second post returns the same leaveId with created = false. days is sent, never derived: ReconSmith does not know your working week, shift patterns or public holidays.\n\nunpaid_days (136): with code ANNUAL, days - unpaid_days come off the annual balance and unpaid_days are recorded as unpaid leave (external_ref + '-UNPAID'). The answer carries annual_days, unpaid_days, recounted and recount_note.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "externalRef",
                  "code",
                  "firstDay",
                  "lastDay",
                  "days"
                ],
                "properties": {
                  "externalRef": {
                    "type": "string",
                    "description": "Your id for the leave request, e.g. APP-LR-9912. The idempotency key."
                  },
                  "code": {
                    "type": "string",
                    "description": "From GET /v1/leave-types."
                  },
                  "firstDay": {
                    "type": "string",
                    "format": "date"
                  },
                  "lastDay": {
                    "type": "string",
                    "format": "date"
                  },
                  "days": {
                    "type": "number",
                    "description": "Working days, as you count them."
                  },
                  "halfDay": {
                    "type": "boolean",
                    "default": false
                  },
                  "note": {
                    "type": "string"
                  },
                  "sourceSystem": {
                    "type": "string",
                    "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                  },
                  "unpaid_days": {
                    "type": "number",
                    "description": "Annual leave only (136). How many of days went over the annual balance when the person applied; recorded as unpaid leave and taken off the pay. The balance is counted again when the leave is posted, and if it allows a different split the answer says so (recounted, recount_note)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "leaveId, created, balanceAfter"
          },
          "404": {
            "description": "Nobody here is known by that reference"
          },
          "422": {
            "description": "Refused: no such leave type, service not yet served, or the balance would go negative"
          }
        },
        "tags": [
          "Staff and payroll"
        ]
      }
    },
    "/v1/employees/{externalRef}/leave/{leaveRef}/reverse": {
      "post": {
        "summary": "An approval that was withdrawn",
        "description": "Reversed, never deleted. The person asked, it was approved, and then it was cancelled — all three happened and all three stay on the record. Safe to repeat.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "leaveRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The externalRef you posted the leave under."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string"
                  },
                  "sourceSystem": {
                    "type": "string",
                    "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "leaveId, reversed, balanceAfter. reversed is false if it was already reversed."
          },
          "422": {
            "description": "No reason given, or no leave recorded under that reference"
          }
        },
        "tags": [
          "Staff and payroll"
        ]
      }
    },
    "/v1/employees/{externalRef}/payslips": {
      "get": {
        "summary": "Which payslips this person has",
        "description": "Only issued ones. A draft pay run has no payslip, deliberately: it would put a figure in somebody's hands that the ledger has never seen.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 24
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "employeeRef, payslips: [{ id, periodStart, periodEnd, payDate, period, ccy, gross, deductions, net }]"
          },
          "404": {
            "description": "Nobody here is known by that reference"
          }
        },
        "tags": [
          "Staff and payroll"
        ]
      }
    },
    "/v1/outbox": {
      "get": {
        "summary": "What is waiting for you to send",
        "description": "For a company whose sending mode is HANDBACK: its invoices are raised in your system, so they go out from your domain, which is the one its customers already know. ReconSmith picks the template, writes the subject and body in the customer's own language and renders the PDF; you send it. Poll this.",
        "parameters": [
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          },
          {
            "name": "includeCollected",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Also return ones you have already marked collected but not yet sent."
          }
        ],
        "responses": {
          "200": {
            "description": "count, messages: [{ messageId, kind, to, cc, bcc, subject, body, language, attachmentName, documentRef, customerRef, customer, status, createdAt, attachment }]. attachment is the path to fetch the PDF from; it is not inlined, because it is often several hundred KB and you may already hold it."
          },
          "409": {
            "description": "This API key has no default company"
          }
        },
        "tags": [
          "Outbox"
        ]
      }
    },
    "/v1/outbox/{id}/collected": {
      "post": {
        "summary": "You have taken it",
        "description": "Separate from sent, deliberately: marking it sent at the moment it was collected would record an outcome nobody knows yet. Safe to repeat.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "collected: true, or false if it was already taken"
          }
        },
        "tags": [
          "Outbox"
        ]
      }
    },
    "/v1/outbox/{id}/sent": {
      "post": {
        "summary": "You sent it",
        "description": "This is what makes Sent mail true. \"Was that invoice sent, to whom, and when\" is a question the books have to answer whoever pressed the button; one that went out through your system and is invisible here is one nobody can prove was sent.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "providerId": {
                    "type": "string",
                    "description": "Your mail provider's message id, if you have one. It is what a later bounce is matched on."
                  },
                  "sentAt": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Defaults to now."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "recorded: true"
          }
        },
        "tags": [
          "Outbox"
        ]
      }
    },
    "/v1/outbox/{id}/failed": {
      "post": {
        "summary": "You could not send it",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "description": "Somebody will read this when they ask why the customer never got their invoice."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "recorded: true"
          },
          "400": {
            "description": "No reason given"
          }
        },
        "tags": [
          "Outbox"
        ]
      }
    },
    "/v1/payslips/{id}/file": {
      "get": {
        "summary": "The payslip as a PDF",
        "description": "The official one, on the company's letterhead, carrying the leave balances as they stood at the end of that period. Proxied to the single renderer for the same reason the tax invoice is: a payslip somebody may have to show a bank or a landlord must not have two appearances.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The id from GET /v1/employees/{externalRef}/payslips."
          }
        ],
        "responses": {
          "200": {
            "description": "application/pdf"
          },
          "404": {
            "description": "Not an issued payslip here"
          },
          "502": {
            "description": "The renderer is unreachable or refused"
          },
          "503": {
            "description": "No renderer configured"
          }
        },
        "tags": [
          "Staff and payroll"
        ]
      }
    },
    "/v1/purchase-credit-notes": {
      "post": {
        "summary": "Post supplier credit notes in bulk",
        "description": "A supplier's credit note: the same line shape as a purchase invoice (net amount and tax as the supplier printed them). The expense and input VAT are credited back and the supplier's payable is reduced.\n\nName the bill it credits with purchase_invoice_external_ref (your external_ref for that bill, same source_system, same supplier). It is applied to what is still open on that bill; anything over stays on the supplier's account as credit. Leave it out for a credit that is not against one bill.\n\nIdempotent on (source_system, external_ref): a repeat returns the existing credit note with created = false and posts nothing.\n\nsupplier_doc_no is required: the supplier's own credit-note number.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "items": {
                  "type": "object",
                  "required": [
                    "external_ref",
                    "supplier_doc_no",
                    "doc_date",
                    "lines"
                  ],
                  "properties": {
                    "external_ref": {
                      "type": "string",
                      "description": "Your identifier, e.g. APP-SUPCRN-17. The idempotency key for this document."
                    },
                    "supplier_doc_no": {
                      "type": "string",
                      "description": "The supplier's own credit-note number."
                    },
                    "supplier_external_ref": {
                      "type": "string",
                      "description": "Your supplier id, as pushed to /v1/parties with role = SUPPLIER."
                    },
                    "account_code": {
                      "type": "string",
                      "description": "Alternative: the account_code returned by /v1/parties."
                    },
                    "doc_date": {
                      "type": "string",
                      "format": "date"
                    },
                    "ccy": {
                      "type": "string",
                      "default": "ZAR"
                    },
                    "reference": {
                      "type": "string",
                      "description": "Printed on the bill and shown on the supplier statement. For fuel, the vehicle registration."
                    },
                    "notes": {
                      "type": "string"
                    },
                    "source_system": {
                      "type": "string",
                      "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                    },
                    "lines": {
                      "type": "array",
                      "minItems": 1,
                      "items": {
                        "type": "object",
                        "required": [
                          "description",
                          "amount_excl_tax"
                        ],
                        "properties": {
                          "description": {
                            "type": "string"
                          },
                          "amount_excl_tax": {
                            "type": "number",
                            "description": "The net amount, as it appears on the supplier's document."
                          },
                          "tax_amount": {
                            "type": "number",
                            "default": 0
                          },
                          "account_code": {
                            "type": "string",
                            "description": "The expense account, e.g. 6070 for fuel."
                          },
                          "tax_code": {
                            "type": "string",
                            "description": "Optional. Defaults to SRI, or to the zero-rated input code when tax_amount is 0."
                          },
                          "dimensions": {
                            "type": "object",
                            "additionalProperties": {
                              "type": "string"
                            },
                            "description": "e.g. {\"VEHICLE\": \"JF 24 PV GP\"}. Keys are case-sensitive and both key and value must already exist."
                          }
                        }
                      }
                    },
                    "attachments": {
                      "type": "array",
                      "description": "The supplier's own document as it arrived. PDF, PNG, JPEG or WebP; the type is read from the bytes. Up to 8 MB per file, and keep the whole request under 12 MB; send larger files one at a time to /v1/purchase-invoices/{external_ref}/attachments. The same file sent again is kept once.",
                      "items": {
                        "type": "object",
                        "required": [
                          "file_name",
                          "content_base64"
                        ],
                        "properties": {
                          "file_name": {
                            "type": "string"
                          },
                          "content_type": {
                            "type": "string",
                            "description": "Optional; not trusted."
                          },
                          "content_base64": {
                            "type": "string",
                            "description": "The file, base64. A data: URL prefix is accepted."
                          }
                        }
                      }
                    },
                    "purchase_invoice_external_ref": {
                      "type": "string",
                      "description": "Optional. Your external_ref of the bill this credits, e.g. APP-SUPBILL-42."
                    },
                    "reason": {
                      "type": "string",
                      "description": "Why the supplier credited us, e.g. 'Empties returned on GRN-12'. Defaults to notes, then to 'Supplier credit note <number>'."
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Posted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "purchase_credit_notes": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "document_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "external_ref": {
                            "type": "string"
                          },
                          "created": {
                            "type": "boolean",
                            "description": "false when this external_ref was already posted."
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Unknown supplier, a party with no SUPPLIER account, or an unknown dimension key or value."
          }
        },
        "tags": [
          "Purchases"
        ]
      }
    },
    "/v1/employees/{externalRef}/hours/{periodRef}": {
      "put": {
        "summary": "One person's hours for one pay period",
        "description": "PUT, so idempotent: the same period sent again replaces it (an office correction). Once a posted pay run covers any of its dates, it is refused with 409.\n\nHow the pay run uses the days (South Africa, BCEA): the standing pay covers the ordinary hours of rostered days. On top of it: hours over the ordinary day (9) on a rostered day at 1.5x, or the day's multiplier if higher; the ordinary hours of a rostered Sunday or public holiday carry the extra (multiplier - 1); every hour of a rest day worked (rostered = false or rest_day_worked = true) at 1.5x or the multiplier if higher. Hourly rate = standing pay x periods a year / 52 / 45.\n\nUnknown fields on a day are kept, not refused.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "TM-{team member id}"
          },
          {
            "name": "periodRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "APP-HOURS-{from}-{to}"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "period_from",
                  "period_to",
                  "days"
                ],
                "properties": {
                  "period_from": {
                    "type": "string",
                    "format": "date"
                  },
                  "period_to": {
                    "type": "string",
                    "format": "date"
                  },
                  "total_hours": {
                    "type": "number"
                  },
                  "on_truck_hours": {
                    "type": "number"
                  },
                  "off_truck_hours": {
                    "type": "number"
                  },
                  "source_system": {
                    "type": "string",
                    "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                  },
                  "days": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "date",
                        "hours"
                      ],
                      "properties": {
                        "date": {
                          "type": "string",
                          "format": "date"
                        },
                        "hours": {
                          "type": "number",
                          "description": "Decimal hours, 0 to 16."
                        },
                        "on_truck_hours": {
                          "type": "number"
                        },
                        "off_truck_hours": {
                          "type": "number"
                        },
                        "corrected": {
                          "type": "boolean",
                          "default": false
                        },
                        "day_type": {
                          "type": "string",
                          "enum": [
                            "ORDINARY",
                            "SATURDAY",
                            "SUNDAY",
                            "PUBLIC_HOLIDAY"
                          ],
                          "default": "ORDINARY"
                        },
                        "rate_multiplier": {
                          "type": "number",
                          "default": 1.0,
                          "description": "1.0 to 3.0. Sunday 1.5, public holiday 2.0."
                        },
                        "rostered": {
                          "type": "boolean",
                          "default": true
                        },
                        "rest_day_worked": {
                          "type": "boolean",
                          "default": false,
                          "description": "Not rostered and worked anyway: every hour is overtime."
                        }
                      },
                      "additionalProperties": true
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stored for the first time"
          },
          "200": {
            "description": "Replaced"
          },
          "404": {
            "description": "Employee not known: PUT /v1/employees/{externalRef} first"
          },
          "409": {
            "description": "A posted pay run covers this period"
          },
          "422": {
            "description": "A day outside the period, hours over 16, or an unknown day_type"
          }
        },
        "tags": [
          "Staff and payroll"
        ]
      }
    },
    "/v1/customers/{externalRef}/statement": {
      "get": {
        "tags": [
          "Statements"
        ],
        "summary": "Customer statement as data",
        "description": "The customer's statement for a period: opening balance, every line, closing balance and ageing. A payment appears once for the full amount received, with the invoices it was applied to nested beneath it and any unused balance shown. The office screen, the PDF and the e-mailed statement are built from the same data, so they always agree.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own reference for the customer, as pushed to /v1/parties."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "First day of the period. Omit for the statement's default period."
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Last day of the period. Omit for today."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "The statement",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "Unknown customer"
          },
          "409": {
            "description": "No company is set on this key"
          }
        }
      }
    },
    "/v1/customers/{externalRef}/statement/file": {
      "get": {
        "tags": [
          "Statements"
        ],
        "summary": "Customer statement as a PDF",
        "description": "The same statement drawn as a PDF on the company letterhead, ready to show or attach. The file is named for the period's end date, e.g. \"Statement 2026-11-30.pdf\".",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own reference for the customer, as pushed to /v1/parties."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "First day of the period. Omit for the statement's default period."
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Last day of the period. Omit for today."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "application/pdf",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "404": {
            "description": "Unknown customer"
          },
          "409": {
            "description": "No company is set on this key"
          },
          "502": {
            "description": "The renderer is unreachable or refused"
          },
          "503": {
            "description": "No renderer is configured"
          }
        }
      }
    },
    "/v1/customers/{externalRef}/statement/send": {
      "post": {
        "tags": [
          "Statements"
        ],
        "summary": "E-mail a statement now",
        "description": "Queues the customer's statement for the period to be e-mailed. It is queued, not sent inside the request: the sender retries on failure, and the message shows in the outbox and in sent mail. Omit to_address to send to the customer's own e-mail address.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own reference for the customer, as pushed to /v1/parties."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "from": {
                    "type": "string",
                    "format": "date"
                  },
                  "to": {
                    "type": "string",
                    "format": "date"
                  },
                  "to_address": {
                    "type": "string",
                    "description": "Send here instead of the customer's own address."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "queued: the message id"
          },
          "403": {
            "description": "The key is read-only"
          },
          "404": {
            "description": "Unknown customer"
          },
          "409": {
            "description": "No company is set on this key"
          },
          "422": {
            "description": "Refused, e.g. no address to send to"
          }
        }
      }
    },
    "/v1/customers/{externalRef}/statement-delivery": {
      "get": {
        "tags": [
          "Statements"
        ],
        "summary": "The customer's automatic statement setting",
        "description": "Whether the customer receives statements automatically, how often, to which address, and when the next one goes. A customer who has never chosen is OFF.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own reference for the customer, as pushed to /v1/parties."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "The setting",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "mode": {
                      "type": "string",
                      "enum": [
                        "OFF",
                        "MONTHLY",
                        "WEEKLY"
                      ]
                    },
                    "send_on": {
                      "type": "integer",
                      "description": "Monthly: day of the month, 31 = month-end. Weekly: 1 Monday to 7 Sunday."
                    },
                    "to_address": {
                      "type": "string",
                      "description": "Where it is sent. Absent means the customer's own e-mail address."
                    },
                    "send_when_nil": {
                      "type": "boolean",
                      "description": "Send even when nothing is owed."
                    },
                    "next_send": {
                      "type": "string",
                      "format": "date"
                    },
                    "set_by_source": {
                      "type": "string",
                      "description": "Who made the choice: office, or the source system that set it."
                    },
                    "last_sent_on": {
                      "type": "string",
                      "format": "date"
                    },
                    "rule_id": {
                      "type": "string",
                      "format": "uuid",
                      "description": "The company statement rule the customer is on, if any."
                    },
                    "rule_name": {
                      "type": "string"
                    },
                    "schedule": {
                      "type": "string",
                      "description": "The schedule in words, e.g. 'Monthly on the last day'."
                    }
                  },
                  "description": "Fields with no value are left out."
                }
              }
            }
          },
          "404": {
            "description": "Unknown customer"
          },
          "409": {
            "description": "No company is set on this key"
          }
        }
      },
      "put": {
        "tags": [
          "Statements"
        ],
        "summary": "Turn automatic statements on or off",
        "description": "Sets how the customer receives statements: OFF, MONTHLY or WEEKLY, on which day, to which address, and whether to send when nothing is owed. Lets a customer switch automatic statements on for themselves from your app. The choice is recorded with the source system that made it, so it can be told apart from one made in the office.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own reference for the customer, as pushed to /v1/parties."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "mode"
                ],
                "properties": {
                  "mode": {
                    "type": "string",
                    "enum": [
                      "OFF",
                      "MONTHLY",
                      "WEEKLY"
                    ]
                  },
                  "send_on": {
                    "type": "integer",
                    "description": "Monthly: day of the month, 31 = month-end. Weekly: 1 Monday to 7 Sunday."
                  },
                  "to_address": {
                    "type": "string",
                    "description": "Omit to leave it unchanged; an empty string clears it back to the customer's own address."
                  },
                  "send_when_nil": {
                    "type": "boolean",
                    "description": "Send even when nothing is owed."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "mode, send_on, to_address, send_when_nil, next_send"
          },
          "403": {
            "description": "The key is read-only"
          },
          "404": {
            "description": "Unknown customer"
          },
          "409": {
            "description": "No company is set on this key"
          },
          "422": {
            "description": "Refused, e.g. an unknown mode or a day out of range"
          }
        }
      }
    },
    "/v1/customers/{externalRef}/statement-rule": {
      "put": {
        "tags": [
          "Statements"
        ],
        "summary": "Put the customer on a statement rule",
        "description": "Puts the customer on one of the company's named statement schedules from GET /v1/statement-rules, exactly as ticking them onto it in the office does. rule_id null takes them off. The choice is recorded with the source system that made it.",
        "parameters": [
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own reference for the customer, as pushed to /v1/parties."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "rule_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid",
                    "description": "The rule's id; null takes the customer off any rule."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The customer's statement setting after the change",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "mode": {
                      "type": "string",
                      "enum": [
                        "OFF",
                        "MONTHLY",
                        "WEEKLY"
                      ]
                    },
                    "send_on": {
                      "type": "integer",
                      "description": "Monthly: day of the month, 31 = month-end. Weekly: 1 Monday to 7 Sunday."
                    },
                    "to_address": {
                      "type": "string",
                      "description": "Where it is sent. Absent means the customer's own e-mail address."
                    },
                    "send_when_nil": {
                      "type": "boolean",
                      "description": "Send even when nothing is owed."
                    },
                    "next_send": {
                      "type": "string",
                      "format": "date"
                    },
                    "set_by_source": {
                      "type": "string",
                      "description": "Who made the choice: office, or the source system that set it."
                    },
                    "last_sent_on": {
                      "type": "string",
                      "format": "date"
                    },
                    "rule_id": {
                      "type": "string",
                      "format": "uuid",
                      "description": "The company statement rule the customer is on, if any."
                    },
                    "rule_name": {
                      "type": "string"
                    },
                    "schedule": {
                      "type": "string",
                      "description": "The schedule in words, e.g. 'Monthly on the last day'."
                    }
                  },
                  "description": "Fields with no value are left out."
                }
              }
            }
          },
          "403": {
            "description": "The key is read-only"
          },
          "404": {
            "description": "Unknown customer"
          },
          "409": {
            "description": "No company is set on this key"
          },
          "422": {
            "description": "Refused, e.g. an unknown rule"
          }
        }
      }
    },
    "/v1/statement-rules": {
      "get": {
        "tags": [
          "Statements"
        ],
        "summary": "The company's statement rules",
        "description": "The named statement schedules the company has set up, for a customer to choose from. Put a customer on one with PUT /v1/customers/{externalRef}/statement-rule.",
        "responses": {
          "200": {
            "description": "rules",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "rules": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "name": {
                            "type": "string"
                          },
                          "schedule": {
                            "type": "string",
                            "description": "The schedule in words."
                          },
                          "next_send": {
                            "type": "string",
                            "format": "date"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "409": {
            "description": "No company is set on this key"
          }
        }
      }
    },
    "/v1/outbox/{id}/pdf": {
      "get": {
        "tags": [
          "Outbox"
        ],
        "summary": "The PDF attached to an outbox message",
        "description": "The message's own attachment, drawn exactly as the built-in sender would attach it. Works for every kind of message, including ones with no document or customer reference, such as a remittance advice. GET /v1/outbox gives this path in a message's attachment field when it is the way to fetch the file.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The message_id from GET /v1/outbox."
          }
        ],
        "responses": {
          "200": {
            "description": "application/pdf, named as the message's attachment",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "404": {
            "description": "Unknown message"
          },
          "409": {
            "description": "No company is set on this key"
          },
          "502": {
            "description": "The renderer is unreachable or refused"
          },
          "503": {
            "description": "No renderer is configured"
          }
        }
      }
    },
    "/v1/remittances": {
      "post": {
        "tags": [
          "Remittances"
        ],
        "summary": "Record remittances: one payment for several invoices",
        "description": "Records a payment the customer is about to make for several invoices under one remittance number of yours. That number is what the payer uses as the card payment's merchant reference or the EFT reference, so when the bank line or the gateway confirmation arrives it finds the remittance waiting and settles every invoice in it. An EFT needs no further call. The lines must add up to the total; with on_account the lines may add up to less (or be none), and the rest settles the customer's open invoices oldest due first. Recording a remittance number that already exists returns it with created false.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "items": {
                  "type": "object",
                  "required": [
                    "remittance_no",
                    "total",
                    "lines"
                  ],
                  "properties": {
                    "remittance_no": {
                      "type": "string"
                    },
                    "total": {
                      "type": "number",
                      "description": "What the payer was asked to pay. Positive."
                    },
                    "lines": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "invoice_external_ref",
                          "amount"
                        ],
                        "properties": {
                          "invoice_external_ref": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "number",
                            "description": "Positive."
                          }
                        }
                      }
                    },
                    "customer_external_ref": {
                      "type": "string"
                    },
                    "account_code": {
                      "type": "string",
                      "description": "Our account code, when customer_external_ref is not sent."
                    },
                    "method": {
                      "type": "string",
                      "enum": [
                        "EFT",
                        "CARD",
                        "OZOW",
                        "GOOGLE_PAY",
                        "APPLE_PAY",
                        "OTHER"
                      ],
                      "default": "EFT",
                      "description": "How the payer said they would pay. Either route still settles it."
                    },
                    "on_account": {
                      "type": "boolean",
                      "default": false,
                      "description": "What the lines do not take is a payment on account."
                    },
                    "source_system": {
                      "type": "string",
                      "description": "Your system's name, the same on every call (for example shop). Identifies your references."
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "count, and remittances with remittance_id, remittance_no and created"
          },
          "400": {
            "description": "Idempotency-Key header missing, or an empty list"
          },
          "409": {
            "description": "A request with this Idempotency-Key is already in flight"
          },
          "413": {
            "description": "More than 1000 remittances in one request"
          },
          "422": {
            "description": "Incomplete remittance, lines that do not add up to the total, an unknown customer or account, or Idempotency-Key reused with a different body"
          }
        }
      }
    },
    "/v1/remittances/{remittanceNo}": {
      "get": {
        "tags": [
          "Remittances"
        ],
        "summary": "Where a remittance stands",
        "description": "The remittance's status (OPEN, PAID or CANCELLED), method, total, when it was paid, and how many of its invoices are settled and how many are still waiting.",
        "parameters": [
          {
            "name": "remittanceNo",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your remittance number, as sent when it was recorded."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "responses": {
          "200": {
            "description": "remittance_no, status, method, total, paid_at, invoices_settled, invoices_waiting"
          },
          "404": {
            "description": "Unknown remittance"
          }
        }
      }
    },
    "/v1/remittances/{remittanceNo}/cancel": {
      "post": {
        "tags": [
          "Remittances"
        ],
        "summary": "Cancel an open remittance",
        "description": "The payer gave up. Marks an OPEN remittance CANCELLED with the reason, so a payment that later arrives under its number is not matched to it. A remittance already paid or cancelled cannot be cancelled.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "remittanceNo",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your remittance number, as sent when it was recorded."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "remittance_no, status CANCELLED, reason"
          },
          "400": {
            "description": "Idempotency-Key header missing"
          },
          "409": {
            "description": "Unknown, already paid or already cancelled; or a request with this Idempotency-Key is already in flight"
          },
          "422": {
            "description": "No reason given, or Idempotency-Key reused with a different body"
          }
        }
      }
    },
    "/v1/remittances/{remittanceNo}/payment-confirmation": {
      "post": {
        "tags": [
          "Remittances",
          "Card payments"
        ],
        "summary": "Gateway says the remittance is paid",
        "description": "The gateway's word, not the bank's. Posts the receipt into that gateway's clearing account and spreads it across the remittance's invoices; the bank is untouched until the settlement arrives under the same reference. Idempotent on the gateway reference, so a retried webhook pays nothing twice. Needs a key with the money scope.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "remittanceNo",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your remittance number, as sent when it was recorded."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "gateway_code",
                  "amount"
                ],
                "properties": {
                  "gateway_code": {
                    "type": "string",
                    "description": "The payment gateway, as set up for the company."
                  },
                  "amount": {
                    "type": "number",
                    "description": "Gross, as the customer paid it. Fees are handled at settlement."
                  },
                  "gateway_ref": {
                    "type": "string",
                    "description": "The gateway's reference for the payment. Omit and the remittance number is used."
                  },
                  "method": {
                    "type": "string",
                    "default": "CARD"
                  },
                  "paid_with": {
                    "type": "string",
                    "description": "The gateway's payment type, e.g. Visa, Mastercard, MasterPass, EFT_OZOW. Payments the gateway pays out one at a time wait for their own bank line."
                  },
                  "confirmed_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Omit for now."
                  },
                  "merchant_reference": {
                    "type": "string",
                    "description": "The gateway's merchant reference, kept on the payment for matching the settlement report."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "remittance_no, gateway_payment_id, status, invoices_settled, invoices_waiting"
          },
          "400": {
            "description": "Idempotency-Key header missing"
          },
          "403": {
            "description": "The key may not move money"
          },
          "404": {
            "description": "Unknown remittance"
          },
          "409": {
            "description": "A request with this Idempotency-Key is already in flight"
          },
          "422": {
            "description": "Not confirmed (e.g. unknown gateway, wrong amount, remittance cancelled), or Idempotency-Key reused with a different body"
          }
        }
      }
    },
    "/v1/credit-notes/{externalRef}/void": {
      "post": {
        "tags": [
          "Invoices and credit notes"
        ],
        "summary": "Void a credit note",
        "description": "For a credit note raised in error. Posts the mirror journal, keeps the number and marks it VOIDED with the reason. A credit note that has already been used or refunded is refused. Voiding one already voided answers again with already_voided true, so a retry is harmless.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own external_ref, our document number or our document id."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "description": "Kept on the document's notes."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "credit_note_external_ref, document_id, doc_no, voided, already_voided"
          },
          "400": {
            "description": "Idempotency-Key header missing"
          },
          "404": {
            "description": "No such document"
          },
          "409": {
            "description": "A request with this Idempotency-Key is already in flight"
          },
          "422": {
            "description": "No reason given, not a customer credit note, already used or refunded, or Idempotency-Key reused with a different body"
          }
        }
      }
    },
    "/v1/invoices/{externalRef}/void": {
      "post": {
        "tags": [
          "Invoices and credit notes"
        ],
        "summary": "Void an invoice",
        "description": "For an invoice billed wrong: void it, then issue the correct one under a new external_ref. Posts the mirror journal, keeps the number and marks it VOIDED with the reason. An invoice with a receipt or credit note allocated against it is refused, naming them, because un-allocating money is a decision for a person; un-allocate first, then void. Voiding one already voided answers again with already_voided true.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own external_ref, our document number or our document id."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "description": "Kept on the document's notes."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "invoice_external_ref, document_id, doc_no, voided, already_voided"
          },
          "400": {
            "description": "Idempotency-Key header missing"
          },
          "404": {
            "description": "No such document"
          },
          "409": {
            "description": "A request with this Idempotency-Key is already in flight"
          },
          "422": {
            "description": "No reason given, not a sales invoice, paid or credited, or Idempotency-Key reused with a different body"
          }
        }
      }
    },
    "/v1/invoices/{externalRef}/notes": {
      "put": {
        "tags": [
          "Invoices and credit notes"
        ],
        "summary": "Change an invoice's notes",
        "description": "Replaces the notes line on an invoice and nothing else: same number, same amounts. Works on a draft, posted or paid invoice; a voided one is refused. The PDF is drawn from the document, so fetch it again afterwards to get the new notes. The audit log keeps the old and new notes and the API client that changed them.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Your own external_ref, our document number or our document id."
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "notes": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "The new notes; null clears them."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "invoice_external_ref, document_id, doc_no, status, notes, changed"
          },
          "400": {
            "description": "No body, or Idempotency-Key header missing"
          },
          "404": {
            "description": "Unknown invoice"
          },
          "409": {
            "description": "A request with this Idempotency-Key is already in flight"
          },
          "422": {
            "description": "Notes not changed (e.g. the invoice is voided), or Idempotency-Key reused with a different body"
          }
        }
      }
    },
    "/v1/purchase-invoices/{externalRef}/attachments": {
      "post": {
        "tags": [
          "Purchases"
        ],
        "summary": "Add the supplier's own document to a bill already sent",
        "description": "For a file that arrives after the bill, e.g. a photo taken later. Names the bill (or supplier credit note) by your external_ref. Same rules as inline attachments: PDF, PNG, JPEG or WebP, 8 MB per file, the same file kept once.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          },
          {
            "name": "externalRef",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sourceSystem",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Your system's name, the same on every call (for example shop). Identifies your references."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "maxItems": 1000,
                "description": "The supplier's own document as it arrived. PDF, PNG, JPEG or WebP; the type is read from the bytes. Up to 8 MB per file, and keep the whole request under 12 MB; send larger files one at a time. The same file sent again is kept once.",
                "items": {
                  "type": "object",
                  "required": [
                    "file_name",
                    "content_base64"
                  ],
                  "properties": {
                    "file_name": {
                      "type": "string"
                    },
                    "content_type": {
                      "type": "string",
                      "description": "Optional; not trusted."
                    },
                    "content_base64": {
                      "type": "string",
                      "description": "The file, base64. A data: URL prefix is accepted."
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Kept",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "document_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "external_ref": {
                      "type": "string"
                    },
                    "attachments": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "attachment_id": {
                            "type": "string",
                            "format": "uuid"
                          },
                          "file_name": {
                            "type": "string"
                          },
                          "created": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Idempotency-Key header missing, or an empty list"
          },
          "404": {
            "description": "Nothing was posted under that external_ref"
          },
          "409": {
            "description": "A request with this Idempotency-Key is already in flight"
          },
          "413": {
            "description": "A file over 8 MB, or more than 1000 files"
          },
          "422": {
            "description": "Not a PDF, PNG, JPEG or WebP, not valid base64, or Idempotency-Key reused with a different body"
          }
        }
      }
    },
    "/v1/openapi.json": {
      "get": {
        "tags": [
          "Service"
        ],
        "summary": "This API description",
        "description": "The OpenAPI document for this API. Needs no key, so an integrator can read it before being issued one.",
        "security": [],
        "responses": {
          "200": {
            "description": "The OpenAPI 3.1 document",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Customers",
      "description": "Who you sell to: create, update and find customers."
    },
    {
      "name": "Invoices and credit notes",
      "description": "Issue tax invoices and credit notes, change notes, void."
    },
    {
      "name": "Payments and allocations",
      "description": "Money received, and which invoices it paid."
    },
    {
      "name": "Sales orders",
      "description": "Orders before they are invoiced, and the two events that invoice them."
    },
    {
      "name": "Card payments",
      "description": "Card and online payments: confirmed, in transit, settled."
    },
    {
      "name": "Documents",
      "description": "The issued documents: status, PDF and data."
    },
    {
      "name": "Statements",
      "description": "Customer statements and how they are delivered."
    },
    {
      "name": "Outbox",
      "description": "Documents ReconSmiths prepared for your system to send."
    },
    {
      "name": "Purchases",
      "description": "Supplier bills, supplier credit notes and dimensions."
    },
    {
      "name": "Remittances",
      "description": "One customer payment for several invoices, under one number."
    },
    {
      "name": "Items",
      "description": "Products and services."
    },
    {
      "name": "Staff and payroll",
      "description": "Employees, hours, leave and payslips."
    },
    {
      "name": "Reconciliation",
      "description": "Bank lines and the matches suggested for them."
    },
    {
      "name": "Reading the books",
      "description": "Statements, ageing, open items and the change feed."
    },
    {
      "name": "Service",
      "description": "Health and the contract itself."
    }
  ]
}