> ## 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 `transactionId`, it lands in the document inbox. Use this endpoint to attach it to a ledger entry later, for example once the corresponding transaction 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 '{ "transactionId": "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 consist of a net transaction and a VAT transaction.
  Attach receipts to the net transaction, i.e. the transaction whose
  `isVatTransaction` is `false`.
</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:
                - transactionId
              properties:
                transactionId:
                  type: string
                  description: >-
                    The id of the ledger entry transaction 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':
          $ref: '#/components/responses/BadRequest'
        '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 the ledger
            entry referenced by `transactionId` does not exist.
          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`.
        transactionId:
          type: string
          description: >-
            The id of the ledger entry transaction 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:
    BadRequest:
      description: >-
        A bad request is thrown if the request payload is malformed or fails
        validation.
      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`
                  - `general/malformed-request`
                  - `general/invalid-date`
                  - `general/input-too-long`
                  - `general/zero-or-negative-amount-not-allowed`
              invalidFields:
                type: array
                description: A list of the fields which were invalid, if applicable.
                items:
                  type: string
    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.

````