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

# Cancel an invoice

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.


## OpenAPI

````yaml POST /invoices/{foreign_id}/cancel/
openapi: 3.0.0
info:
  title: Merchant Backend V2
  version: '1.0'
  description: Documentation for merchant backend processing endpoints
servers:
  - url: https://app.cryptoprocessing.com/api/v2
security:
  - xProcessingKey: []
tags:
  - name: Status
  - name: Balance
  - name: Currencies
  - name: Deposit addresses
  - name: Withdrawal
  - name: Exchange
  - name: Invoices
  - name: Transactions
paths:
  /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 unique identifier of the invoice you need to cancel.
          schema:
            type: string
            example: test_foreign_id_0344
      requestBody:
        required: true
        description: >
          The `Content-Type: application/json` header must be specified even
          though the

          request body has no fields.
        content:
          application/json:
            schema:
              type: object
              description: >
                This endpoint does not accept any request parameters, but you
                must still send

                an empty JSON object (`{}`) in the request body.
              additionalProperties: false
            examples:
              Basic example:
                value: {}
      responses:
        '200':
          description: OK
          content:
            application/json:
              examples:
                Basic example:
                  value: []
        '400':
          description: Bad Request
          content:
            text/html:
              schema:
                $ref: '#/components/schemas/ValidationOrMalformedJson'
              examples:
                Invoice not found:
                  summary: Invoice with given foreign_id not found
                  value:
                    errors:
                      foreign_id: Invoice not found.
                Invalid state:
                  summary: Invoice cannot be cancelled in current state
                  value:
                    error: Invoice cannot be failed in its current state.
                    code: invalid_invoice_state
                Feature not enabled:
                  summary: Invoice feature is disabled
                  value:
                    message: Required features [invoices_enabled] not enabled.
                Malformed JSON:
                  summary: Invalid JSON body
                  value:
                    error: Bad content format
                    code: bad_content_format
        '403':
          $ref: '#/components/responses/HeaderAuthorization'
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
              additionalProperties:
                type: string
        - 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. Refer to
              [Errors](/api-reference/errors#403) for troubleshooting steps.
          examples:
            Bad signature header:
              value:
                error: Bad signature header
                code: bad_header_signature
            No signature header:
              value:
                error: No signature header
                code: required_header_signature
            Bad key header:
              value:
                error: Bad key header
                code: bad_header_key
            No key header:
              value:
                error: No key header
                code: required_header_key
  securitySchemes:
    xProcessingKey:
      type: apiKey
      description: Your [API key](/integration-guide/get-your-api-key).
      in: header
      name: X-Processing-Key

````