> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nocotax.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Refunds and cancellations

> Correct finalized invoices with credit notes or cancellation while keeping order references and periods.

A finalized invoice cannot be edited. Corrections are made with credit notes, which are negative documents linked to the invoice.

## Which one to use

| Situation | Use |
| - | - |
| The whole invoice is void | [Cancel the invoice](#cancel-an-invoice) |
| Part of the invoice is refunded or adjusted | [Create a credit note](#partial-correction) |
| The invoice is still a `draft` | Nothing to cancel: the draft has no number and no effect on balances. Create a new one if needed. |

Apply the same rules to the sales invoice and to the matching purchase invoice lines of an order, so both sides stay consistent.

## Cancel an invoice

```bash theme={null}
curl https://api.nocotax.app/invoices/inv_123/cancel \
  -X POST \
  -u ${ACCOUNT_ID}:${YOUR_API_KEY}
```

Only a `finalized` invoice can be cancelled. Nocotax sets its status to `cancelled` and creates a credit note with the same items. `order_reference` and `period` are copied from the invoice and its lines to the credit note.

## Partial correction

Create a credit note that references the invoice, and repeat the `order_reference` and `period` of the line you correct:

```bash theme={null}
curl https://api.nocotax.app/credit_notes \
  -X POST \
  -u ${ACCOUNT_ID}:${YOUR_API_KEY} \
  -H "Content-Type: application/json" \
  -d '{
    "flow": "sales",
    "customer_id": "org_customer_123",
    "currency": "EUR",
    "invoice_id": "inv_123",
    "items": [
      {
        "title": "Partial refund - order ORD-12345",
        "order_reference": "ORD-12345",
        "period": { "start": "2025-12-15T00:00:00Z", "end": "2025-12-15T00:00:00Z" },
        "extratax_amount": 2500,
        "product": { "tax_code": "S10000000" }
      }
    ]
  }'

# Then finalize it
curl https://api.nocotax.app/credit_notes/cn_123/finalize \
  -X POST \
  -u ${ACCOUNT_ID}:${YOUR_API_KEY}
```

For a purchase invoice, use `"flow": "purchases"` and `supplier_id`. Amounts are positive: the document type gives the sign, and exports show credit notes as negative.

## Why the references matter

* The credit note has its own invoice date (the day you finalize it). If it only carried that date, a December correction finalized in January would be attributed to January.
* `order_reference` ties the correction to the original order, so margin per order is net of refunds.
* `period` tells which service period the correction relates to. See [Accounting periods](https://docs.nocotax.app/undisclosed-agents/accounting-periods.md).

## Refunding the money

Once a credit note is finalized, attach the money movement to it:

```bash theme={null}
curl https://api.nocotax.app/credit_notes/cn_123/attach_credit \
  -X POST \
  -u ${ACCOUNT_ID}:${YOUR_API_KEY} \
  -H "Content-Type: application/json" \
  -d '{
    "transaction_data": {
      "amount": 2500,
      "currency": "EUR",
      "transaction_type": "refund",
      "reference": "re_abc123"
    }
  }'
```

`transaction_type` is `refund`, `transfer_reversal` or `balance_adjustment`. Without `transaction_data`, the full remaining amount is credited.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.