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

# Delete an account

> Deletes the account with the given account number from every open fiscal year, unless transactions have been posted to it or it is a protected account.

## Deleting an account

Deleting an account removes it from every open fiscal year. An account can only be deleted if nothing depends on it:

* No transactions may have been posted to the account. Otherwise the request fails with `400 Bad Request` and error code `ledger/cannot-delete-account-with-transactions`.
* System accounts that Infinity relies on, such as VAT accounts, cannot be deleted (`403 Forbidden`, `ledger/system-account`).
* Accounts connected to a bank through Live Accounting cannot be deleted (`403 Forbidden`, `accounts/cannot-delete-live-account`).


## OpenAPI

````yaml DELETE /v1/accounts/{accountNumber}
openapi: 3.1.0
info:
  title: infinity.swiss Open API
  version: '1.0'
  summary: ''
servers:
  - url: https://api.infinity.swiss
security:
  - apiKey: []
paths:
  /v1/accounts/{accountNumber}:
    parameters:
      - schema:
          type: integer
          minimum: 1000
          maximum: 9999
        name: accountNumber
        in: path
        description: The account number of the account
        required: true
    delete:
      tags: []
      summary: Delete an account
      description: >-
        Deletes the account with the given account number from every open fiscal
        year, unless transactions have been posted to it or it is a protected
        account.
      operationId: delete-account-v1
      responses:
        '200':
          description: The account was deleted successfully.
        '400':
          description: >-
            The account cannot be deleted because transactions have been posted
            to it.
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: |-
                      The specific error code for this request.
                      Can be:
                      - `ledger/cannot-delete-account-with-transactions`
        '401':
          $ref: '#/components/responses/Unauthorised'
        '403':
          description: The account is protected and can never be deleted.
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: >-
                      The specific error code for this request.

                      May be:

                      - `ledger/system-account` for system accounts that
                      Infinity relies on, such as VAT accounts

                      - `accounts/cannot-delete-live-account` for accounts
                      connected to a bank through Live Accounting
        '404':
          $ref: '#/components/responses/AccountNotFound'
components:
  responses:
    Unauthorised:
      description: >-
        An unauthorised request was submitted. You may be using an incorrect or
        expired API token, or are attempting to access a document outside of the
        scope of the token.
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                x-stoplight:
                  id: 08hkw8ukmi2lp
                description: Specific error code
          examples:
            Unauthorised request:
              value:
                code: general/unauthorised
    AccountNotFound:
      description: >-
        No account with this account number exists in an open fiscal year of the
        organisation.
      content:
        application/json:
          schema:
            type: object
            properties:
              code:
                type: string
                description: Specific error code.
          examples:
            Not found:
              value:
                code: ledger/account-not-found
  securitySchemes:
    apiKey:
      name: x-api-token
      type: apiKey
      in: header
      description: >-
        API token for authentication. Obtain from your Infinity account
        settings.

````