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

# Cancel an invoice

> [!TIP]
>
> Documentation for invoices: [Overview](https://docs.ca.cryptoprocessing.com/invoices), [Fees](https://docs.ca.cryptoprocessing.com/invoices/fees), [Create invoice](https://docs.ca.cryptoprocessing.com/api-reference/endpoints/invoices-create), [Cancel invoice](https://docs.ca.cryptoprocessing.com/api-reference/endpoints/invoices-cancel), [Callbacks](https://docs.ca.cryptoprocessing.com/api-reference/callbacks/invoice-payment-callbacks).
>
> For new integrations, **consider [migrating to payment requests](https://docs.ca.cryptoprocessing.com/payment-requests/migration-guide.md) instead**.

Use this endpoint to cancel an invoice. You can only cancel invoices while they are still at the `created`, `pending` or `processing` stage. Invoices that have the `confirmed` or `failed` statuses cannot be cancelled.

> [accordion] Errors
>
> **400 Bad Request**
>
> | Error message | What it means |
> | - | - |
> | `foreign_id: Invoice not found.` | None of your invoices has this `foreign_id`. |
> | `Invoice cannot be failed in its current state.` (code `invalid_invoice_state`) | The invoice is already `confirmed` or `failed` (a cancelled invoice is `failed` too), so it can't be cancelled. Only `created`, `pending` and `processing` invoices can be cancelled. |
> | `Required features [invoices_enabled] not enabled.` | Invoices aren't enabled for your merchant account. |


## OpenAPI

````yaml POST /v2/invoices/{foreign_id}/cancel
openapi: 3.1.0
info:
  title: Merchant Backend V2
  version: '1.0'
  description: Documentation for merchant backend processing endpoints
servers:
  - url: https://app.ca.cryptoprocessing.com/api
security:
  - xProcessingKey: []
tags:
  - name: Status
  - name: Balance
  - name: Currencies
  - name: Deposit addresses
  - name: Withdrawal
  - name: Exchange
  - name: Invoices
  - name: Transactions
paths:
  /v2/invoices/{foreign_id}/cancel:
    post:
      tags:
        - Invoices
      summary: Cancel an invoice
      operationId: cancel-an-invoice
      parameters:
        - $ref: '#/components/parameters/XProcessingSignatureHeader'
        - name: foreign_id
          in: path
          required: true
          description: >-
            The `foreign_id` of the invoice you need to cancel, URL-encoded.
            Case-insensitive.
          schema:
            type: string
            example: invoice_123
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: >
                This endpoint does not accept any request parameters; any fields
                in the body are ignored. Both an empty JSON object (`{}`) and a
                completely empty (zero-byte) body are accepted. `Content-Type:
                application/json` is still required if you send `{}` — but if
                the body is truly empty (zero bytes), `Content-Type` isn't
                checked at all (it can be omitted or set to any value).
            examples:
              Empty JSON object:
                value: {}
      responses:
        '200':
          description: OK
          content:
            application/json:
              examples:
                Invoice cancelled:
                  value: []
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationOrMalformedJson'
              examples:
                Invoice not found:
                  value:
                    errors:
                      foreign_id: Invoice not found.
                Invoice already confirmed or failed:
                  value:
                    error: Invoice cannot be failed in its current state.
                    code: invalid_invoice_state
                Invoices not enabled:
                  value:
                    message: Required features [invoices_enabled] not enabled.
                Malformed JSON:
                  value:
                    error: Bad content format
                    code: bad_content_format
        '403':
          $ref: '#/components/responses/HeaderAuthorization'
        '429':
          $ref: '#/components/responses/TooManyRequests'
components:
  parameters:
    XProcessingSignatureHeader:
      name: X-Processing-Signature
      in: header
      required: true
      description: >-
        Hex-encoded HMAC-SHA512 signature of the request body, [generated using
        your secret key](/api-reference/authentication).
      schema:
        type: string
  schemas:
    ValidationOrMalformedJson:
      oneOf:
        - type: object
          title: ValidationError
          description: One or more request parameters failed validation.
          properties:
            errors:
              type: object
              description: >
                A map of request field names to a human-readable validation
                error message for that field. The exact set of possible keys and
                messages is endpoint-specific — see [API
                errors](/api-reference/errors#errors-by-endpoint) for the full
                reference.
              additionalProperties:
                type: string
                description: Human-readable validation error message for this field.
        - type: object
          title: MalformedJson
          description: >-
            The request body is not valid JSON or the Content-Type header is not
            set to `application/json`.
          properties:
            error:
              type: string
            code:
              type: string
  responses:
    HeaderAuthorization:
      description: |
        Forbidden
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: string
                description: Human-readable error message.
              code:
                type: string
                description: Error code.
            description: >-
              Invalid or missing headers, or the API key does not have access to
              the endpoint. Refer to
              [Errors](/api-reference/errors#general-errors) for troubleshooting
              steps.
          examples:
            Bad signature header:
              value:
                error: Bad signature header
                code: bad_header_signature
            API key does not have the required ability:
              value:
                error: The API key does not have access to this endpoint.
                code: api_key_ability_required
            No signature header:
              value:
                error: No signature header
                code: required_header_signature
            No key header:
              value:
                error: No key header
                code: required_header_key
    TooManyRequests:
      description: >
        Too Many Requests


        You sent too many requests in a short time. The limit is counted per API
        key, so requests from all your servers that use the same key count
        together. Wait before you send the request again, increasing the delay
        if you get `429` again, and handle this error by its status code, not by
        a particular response body. See [Too many
        requests](/api-reference/errors#too-many-requests-429-too-many-requests).
  securitySchemes:
    xProcessingKey:
      type: apiKey
      description: Your [API key](/merchant-administration/generate-and-activate-api-keys).
      in: header
      name: X-Processing-Key

````

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