> ## 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.

# Attach a receipt to a ledger entry

> Attaches a previously uploaded receipt to a ledger entry, and files it to the `receipts` location. A receipt that is already attached to another ledger entry is moved to the given one.

## Attaching an uploaded receipt

If you [uploaded a receipt](/api/receipts/upload) without a `ledgerEntryId`, it lands in the document inbox. Use this endpoint to attach it to a ledger entry later, for example once the corresponding entry has been posted:

```bash theme={null}
curl -X POST https://api.infinity.swiss/v1/receipts/686f1b2ce9500b3ffe4bbc71/attach \
  -H "x-api-token: your-api-token" \
  -H "Content-Type: application/json" \
  -d '{ "ledgerEntryId": "682338d9e9500b3ffe4baa5a" }'
```

The receipt is filed to the `receipts` location and the response reflects the ledger entry it is now attached to. A receipt that is already attached to another ledger entry is moved to the given one.

<Note>
  Ledger entries with VAT are booked as two transactions internally. Only the id
  of the ledger entry itself, as returned by [find ledger
  entries](/api/accounting/find), is accepted here — the id of the VAT
  transaction results in a `404 Not Found` response with the error code
  `transactions/not-found`.
</Note>


## OpenAPI

````yaml POST /v1/receipts/{receiptId}/attach
openapi: 3.1.0
info:
  title: infinity.swiss Open API
  version: '1.0'
  summary: ''
servers:
  - url: https://api.infinity.swiss
security:
  - apiKey: []
paths:
  /v1/receipts/{receiptId}/attach:
    parameters:
      - schema:
          type: string
        name: receiptId
        in: path
        description: The id of the receipt, as returned when it was uploaded
        required: true
    post:
      tags: []
      summary: Attach a receipt to a ledger entry
      description: >-
        Attaches a previously uploaded receipt to a ledger entry, and files it
        to the `receipts` location. A receipt that is already attached to
        another ledger entry is moved to the given one.
      operationId: attach-receipt-v1
      requestBody:
        description: The ledger entry to attach the receipt to.
        content:
          application/json:
            schema:
              type: object
              required:
                - ledgerEntryId
              properties:
                ledgerEntryId:
                  type: string
                  description: The id of the ledger entry to attach the receipt to.
                  example: 682338d9e9500b3ffe4baa5a
      responses:
        '200':
          description: The receipt was attached to the ledger entry.
          content:
            application/json:
              schema:
                type: object
                required:
                  - receipt
                properties:
                  receipt:
                    $ref: '#/components/schemas/Receipt'
        '400':
          description: >-
            A bad request is thrown if the request payload is malformed, for
            example if `ledgerEntryId` is missing or is not a 24-character hex
            id.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                properties:
                  code:
                    type: string
                    description: >-
                      The specific error code for this request.

                      May be:

                      - `general/missing-fields`, with `invalidFields` set to
                      `["ledgerEntryId"]` when the id is missing or malformed

                      - `general/malformed-request`
                  invalidFields:
                    type: array
                    description: A list of the fields which were invalid, if applicable.
                    items:
                      type: string
                      example: ledgerEntryId
        '401':
          $ref: '#/components/responses/Unauthorised'
        '403':
          description: >-
            The ledger entry cannot be changed because it lies in a closed
            fiscal year.
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: |-
                      The specific error code for this request.
                      Can be:
                      - `fiscal-year/closed`
        '404':
          description: >-
            No receipt with this id exists in the organisation, or no ledger
            entry with the id given in `ledgerEntryId` exists. The latter is
            also returned when the id refers to the VAT transaction that
            Infinity booked alongside an entry.
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                    description: |-
                      The specific error code for this request.
                      May be:
                      - `documents/not-found`
                      - `transactions/not-found`
components:
  schemas:
    Receipt:
      title: Receipt
      type: object
      description: A receipt document that was uploaded to the organisation.
      required:
        - id
        - title
        - location
        - uploadedAt
      properties:
        id:
          type: string
          description: A unique hex identifier for the document.
          example: 686f1b2ce9500b3ffe4bbc71
        title:
          type: string
          description: The title of the document.
          example: Coffee receipt 2025-01-30
        note:
          type: string
          description: The note stored with the document, if one was provided.
        location:
          type: string
          enum:
            - inbox
            - receipts
          description: >-
            The location of the document. Documents attached to a ledger entry
            are filed to `receipts`, all others land in the `inbox`.
        ledgerEntryId:
          type: string
          description: >-
            The id of the ledger entry the document was attached to, if
            attachment was requested.
          example: 682338d9e9500b3ffe4baa5a
        analysisStatus:
          type: string
          description: >-
            The status of the Live Capture document analysis, if one was
            started.
        uploadedAt:
          type: string
          format: date-time
          description: The time at which the document was uploaded.
          example: '2025-01-30T12:00:00.000Z'
  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
  securitySchemes:
    apiKey:
      name: x-api-token
      type: apiKey
      in: header
      description: >-
        API token for authentication. Obtain from your Infinity account
        settings.

````

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