# Invoices and credit notes

Issue tax invoices and credit notes, change notes, void.

## POST /v1/invoices

**Post sales invoices in bulk**

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.

doc_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.

No settlement flag is returned: status is derived from allocations and never stored. Read it from GET /v1/documents.

Parameters:

- `Idempotency-Key` (header, required): 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.

Body (a JSON array of these):

- `external_ref` string, required: Your identifier — typically the sales order number. The idempotency key for this document.
- `customer_external_ref` string: Your customer id, as pushed to /v1/parties. Preferred: you never learn our codes.
- `account_code` string: Alternative: the account_code returned by /v1/parties.
- `doc_date` string (date), required
- `due_date` string (date): Omit to let the billing party's terms derive it.
- `ccy` string: Default "ZAR".
- `reference` string: Printed on the invoice. The order number belongs here.
- `notes` string
- `source_system` string: Your system's name, the same on every call (for example shop). Identifies your references.
- `lines` array of object, required
- `lines[].description` string, required
- `lines[].amount_excl_tax` number, required
- `lines[].tax_amount` number, required
- `lines[].account_code` string: Revenue account, e.g. "4010". Friendlier than carrying our UUIDs in your config.
- `lines[].ledger_account_id` string (uuid): Alternative to account_code.
- `lines[].quantity` number: Default 1.
- `lines[].unit_price` number: Omit and it is derived from amount_excl_tax / quantity.
- `lines[].branch_id` string (uuid): Chain customers: the branch that incurred the charge. Its branch_number prints on the statement line.
- `lines[].site_id` string (uuid)
- `lines[].dimensions` object: Analytic tags. Keys and values must already be registered or the line is refused.
- `lines[].tax_code` string: Optional. SR (standard rate) by default; send ZR for zero-rated or EX for exempt supplies.
- `lines[].item_code` string: Optional. The product, by its code in the product list (GET /v1/items).
- `billing_address` object: 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.
- `billing_address.unit` string
- `billing_address.building` string
- `billing_address.street_no` string
- `billing_address.street` string
- `billing_address.suburb` string
- `billing_address.city` string
- `billing_address.province` string
- `billing_address.postal_code` string
- `billing_address.country_code` string

```json
[
  {
    "external_ref": "string",
    "doc_date": "2026-12-01",
    "lines": [
      {
        "description": "string",
        "amount_excl_tax": 100,
        "tax_amount": 100
      }
    ]
  }
]
```

Answers:

- `201` Posted. Each result carries document_id and the external_ref you sent; created:false means it was already posted under that ref.
- `422` Rejected by the ledger — unknown customer, closed period, unregistered dimension, unbalanced journal. The detail carries the database's own message.

## POST /v1/credit-notes

**Credit a customer — against an invoice, or on the account**

Three shapes, because all three happen:

1. invoice_external_ref, no lines — credit the whole invoice. The ordinary cancelled-order case.
2. invoice_external_ref with lines — credit part of that invoice.
3. 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.

An 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-).

applied: 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.

mark_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.

reason is never optional. It is the first thing anyone asks about a credit note, and the ledger refuses one without it.

Parameters:

- `Idempotency-Key` (header, required): 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.

Body (a JSON array of these):

- `invoice_external_ref` string: The invoice being credited. Omit for a credit note on the account, and then lines are required.
- `reason` string, required: Stored on the credit note. Say why — an auditor reads this.
- `external_ref` string, required: Your identifier for the credit note itself.
- `doc_date` string (date)
- `lines` array of object: Required when no invoice is named; omit to credit a whole invoice.
- `lines[].description` string, required
- `lines[].amount_excl_tax` number, required
- `lines[].tax_amount` number, required
- `lines[].account_code` string: Revenue account, e.g. "4010". Friendlier than carrying our UUIDs in your config.
- `lines[].ledger_account_id` string (uuid): Alternative to account_code.
- `lines[].quantity` number: Default 1.
- `lines[].unit_price` number: Omit and it is derived from amount_excl_tax / quantity.
- `lines[].branch_id` string (uuid): Chain customers: the branch that incurred the charge. Its branch_number prints on the statement line.
- `lines[].site_id` string (uuid)
- `lines[].dimensions` object: Analytic tags. Keys and values must already be registered or the line is refused.
- `source_system` string: Your system's name, the same on every call (for example shop). Identifies your references.
- `mark_for_refund` boolean: The customer opted for a refund rather than keeping the credit on account. Default false.
- `customer_external_ref` string: The customer, for a credit note not tied to an invoice. Your own id, as pushed to /v1/parties.
- `account_code` string: Alternative to customer_external_ref.

```json
[
  {
    "reason": "string",
    "external_ref": "string"
  }
]
```

Answers:

- `201` Credited
- `422` Neither an invoice nor a customer with lines; unknown invoice or customer; no reason; or nothing left to credit on an invoice already settled.

## POST /v1/credit-notes/{externalRef}/refund-request

**The customer asks for the money back**

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.

The flag shows as refund_requested in GET /v1/credits, and refundOnly=true filters to these.

Parameters:

- `externalRef` (path, required): 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.
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Body:

- `note` string: Why, or how they asked. Shown beside the credit.

```json
{
  "note": "string"
}
```

Answers:

- `200` doc_no, unused, requested_at
- `404` No such credit note
- `422` Not a posted credit note, or nothing left to refund

## DELETE /v1/credit-notes/{externalRef}/refund-request

**They changed their mind**

Clears the flag. The credit itself is untouched and stays on the account.

Parameters:

- `externalRef` (path, required): 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.
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Answers:

- `200` refund_requested is now false
- `404` No such credit note

## POST /v1/credit-notes/{externalRef}/refund

**Pay a credit back in money**

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.

Omit 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.

Takes 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:

- `Idempotency-Key` (header, required): 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.
- `externalRef` (path, required): 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.
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Body:

- `amount` number: Omit to refund the full unused balance.
- `bank_account_id` string (uuid)
- `doc_date` string (date)
- `reference` string: Yours — the EFT reference, say.

```json
{
  "amount": 100,
  "bank_account_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "doc_date": "2026-12-01",
  "reference": "string"
}
```

Answers:

- `201` refund_no, amount, credit_left
- `404` No such credit note
- `422` Nothing left to refund, more than is unused, or a closed period

## POST /v1/credit-notes/{externalRef}/void

**Void a credit note**

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:

- `Idempotency-Key` (header, required): 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.
- `externalRef` (path, required): Your own external_ref, our document number or our document id.
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Body:

- `reason` string, required: Kept on the document's notes.

```json
{
  "reason": "string"
}
```

Answers:

- `201` credit_note_external_ref, document_id, doc_no, voided, already_voided
- `400` Idempotency-Key header missing
- `404` No such document
- `409` A request with this Idempotency-Key is already in flight
- `422` No reason given, not a customer credit note, already used or refunded, or Idempotency-Key reused with a different body

## POST /v1/invoices/{externalRef}/void

**Void an invoice**

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:

- `Idempotency-Key` (header, required): 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.
- `externalRef` (path, required): Your own external_ref, our document number or our document id.
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Body:

- `reason` string, required: Kept on the document's notes.

```json
{
  "reason": "string"
}
```

Answers:

- `201` invoice_external_ref, document_id, doc_no, voided, already_voided
- `400` Idempotency-Key header missing
- `404` No such document
- `409` A request with this Idempotency-Key is already in flight
- `422` No reason given, not a sales invoice, paid or credited, or Idempotency-Key reused with a different body

## PUT /v1/invoices/{externalRef}/notes

**Change an invoice's notes**

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:

- `Idempotency-Key` (header, required): 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.
- `externalRef` (path, required): Your own external_ref, our document number or our document id.
- `sourceSystem` (query): Your system's name, the same on every call (for example shop). Identifies your references.

Body:

- `notes` string or null: The new notes; null clears them.

```json
{
  "notes": "string"
}
```

Answers:

- `200` invoice_external_ref, document_id, doc_no, status, notes, changed
- `400` No body, or Idempotency-Key header missing
- `404` Unknown invoice
- `409` A request with this Idempotency-Key is already in flight
- `422` Notes not changed (e.g. the invoice is voided), or Idempotency-Key reused with a different body
