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

# Cancel Invoice

> Cancel a pending invoice

# Cancel Invoice

Cancels a pending invoice. Only invoices in `pending` status can be cancelled. Once cancelled, the invoice status is set to `expired` and no further payments can be made against it.

## Path Parameters

<ParamField path="id" type="string" required>
  UUID of the invoice to cancel.
</ParamField>

## Response

Returns the updated invoice object with `status: "expired"`.

<ResponseField name="data" type="object">
  Updated invoice object. Same shape as [Get Invoice](/api-reference/invoices/get) response (without `addresses`).
</ResponseField>

<Note>
  You can only cancel invoices with status `pending`. Attempting to cancel a `confirmed`, `settled`, or already `expired` invoice will return a `400` error.
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.settlx.io/api/v1/invoices/a1b2c3d4-e5f6-7890-abcd-ef1234567890/cancel \
    -H "Authorization: Bearer pk_live_your_api_key"
  ```

  ```javascript Node.js theme={null}
  const invoiceId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
  const response = await fetch(
    `https://api.settlx.io/api/v1/invoices/${invoiceId}/cancel`,
    {
      method: 'POST',
      headers: { 'Authorization': 'Bearer pk_live_your_api_key' }
    }
  );
  const { data } = await response.json();
  console.log(data.status); // "expired"
  ```

  ```python Python theme={null}
  import httpx

  client = httpx.Client(headers={"Authorization": "Bearer pk_live_your_api_key"})
  invoice_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
  response = client.post(f"https://api.settlx.io/api/v1/invoices/{invoice_id}/cancel")
  invoice = response.json()["data"]
  print(invoice["status"])  # "expired"
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "data": {
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "merchantId": "f9e8d7c6-b5a4-3210-9876-543210fedcba",
      "amount": "99.99",
      "currency": "USD",
      "status": "expired",
      "description": "Order #1234",
      "expiresAt": "2024-01-15T10:30:00.000Z",
      "webhookUrl": "https://yoursite.com/webhooks/settlx",
      "paymentUrl": "https://api.settlx.io/checkout/a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "createdAt": "2024-01-15T10:00:00.000Z",
      "updatedAt": "2024-01-15T10:02:00.000Z"
    }
  }
  ```

  ```json 400 theme={null}
  {
    "error": "Bad Request",
    "message": "Invoice cannot be cancelled in its current status: confirmed"
  }
  ```

  ```json 404 theme={null}
  {
    "error": "Not Found",
    "message": "Invoice not found"
  }
  ```
</ResponseExample>
