*REST API › Endpoint reference › Finance › Treasury*

# Link a payment to a document

> Ties an already recorded payment to the invoice, credit note, quote, proforma or purchase order it settles.

It is a plural sub-resource because a payment can end up tied to several documents. Returns the full payment, with `linkedDocuments` as they now stand, the same projection as its GET.

`POST /api/v1/treasury/payments/{paymentId}/links` — scope `treasury:write`

Scope: `treasury:write` · 120/min · Idempotency-Key · If-Match · MCP: `filmo_treasury_payments_link`

## Authorizations

Bearer API key with the scope below. `treasury:write`

## Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string | No | Unique identifier of the request, chosen by the client (a UUID works). Between 1 and 255 characters: an empty header is rejected with 400 `validation_error`, because the client would believe itself protected. Repeating the same key with the SAME body within 24 h returns the stored response without executing again, with the `Idempotent-Replay: true` header. With a DIFFERENT body it returns 422. It is the safe way to retry after a network timeout. |
| `If-Match` | string | No | Optimistic locking: the `ETag` you read from the resource (or `*`). If the resource changed since, the write is rejected with `412 precondition_failed` before doing anything; read it again and retry. Without the header the write always proceeds. |

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `paymentId` | string | Yes | Treasury payment identifier. |

## Body

Body schema: `PaymentLinkBody`

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `linkedDocumentType` | string | Yes | Type of the document the payment is linked to. `invoice`, `creditNote`, `supplierInvoice`, `quote`, `proforma`, `salesReceipt`, `simpleCreditNote`, `purchaseOrder` |
| `linkedDocumentId` | string | Yes | Document the payment is linked to. |

## Request examples

*Link a payment to a document*

**cURL**

```bash
curl https://app.filmo.io/api/v1/treasury/payments/paym_8f2a1c/links \
  --request POST \
  --header "Authorization: Bearer $FILMO_API_KEY" \
  --header "Idempotency-Key: $(uuidgen 2>/dev/null || cat /proc/sys/kernel/random/uuid)" \
  --header 'Content-Type: application/json' \
  --data '{
  "linkedDocumentType": "supplierInvoice",
  "linkedDocumentId": "sin_00904"
}'
```

**Node.js**

```javascript
fetch('https://app.filmo.io/api/v1/treasury/payments/paym_8f2a1c/links', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR_FILMO_API_KEY',
    'Idempotency-Key': crypto.randomUUID(),
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    linkedDocumentType: 'supplierInvoice',
    linkedDocumentId: 'sin_00904'
  })
})
```

**Python**

```python
import uuid
import requests

requests.post(
    "https://app.filmo.io/api/v1/treasury/payments/paym_8f2a1c/links",
    headers={
      "Authorization": "Bearer YOUR_FILMO_API_KEY",
      "Idempotency-Key": str(uuid.uuid4()),
      "Content-Type": "application/json"
    },
    json={
      "linkedDocumentType": "supplierInvoice",
      "linkedDocumentId": "sin_00904"
    }
)
```

## Response

Response schema: `PaymentDto`

| Status | Description |
| --- | --- |
| 201 | Successful response. |
| 400 | Invalid request (validation_error): malformed query or body. `errors[]` lists every offending field with its stable code. |
| 401 | Authentication failed (unauthorized, api_key_invalid, api_key_revoked, api_key_expired, api_key_owner_inactive, api_key_owner_not_admin). |
| 403 | Not allowed (insufficient_scope: the API key does not have the required scope, named in `requiredScope`; forbidden: the owner of the key lacks the permission the operation requires). `insufficient_scope` is answered before the request counts against the rate limit, so it carries no `RateLimit-*` headers; `forbidden` does. |
| 404 | Resource not found (not_found): it does not exist or is outside the scope of the API key. |
| 409 | Conflict (conflict): the current state of the resource prevents the operation, a request with that Idempotency-Key is already in progress, or another conditional write (`If-Match`) held the resource for more than five seconds. `errors[0].code` says which: `in_progress` and `lock_timeout` are solved by retrying; `invalid_state` is not, because the state of the resource forbids the operation. |
| 412 | Precondition failed (precondition_failed): the `If-Match` entity tag does not match the current representation. Read the resource again and retry. |
| 422 | Idempotency-Key reused (idempotency_key_reused): the same key was used before with a different body. Change the key. |
| 429 | Rate limit exceeded (rate_limited): retry after `Retry-After` seconds; `RateLimit-*` says which quota ran out. |
| 500 | Internal error (internal_error). |

**201**

| Name | Type | Description |
| --- | --- | --- |
| `data` | object | A collection or a payment recorded in treasury. |
| `data.id` | string | Payment identifier. |
| `data.direction` | string | in when money comes in (a collection) and out when it goes out (a payment). |
| `data.amount` | string | Payment amount as a decimal string, in the indicated currency. |
| `data.currency` | string | Payment currency, as an ISO 4217 code. |
| `data.date` | string<date-time> | Payment date in ISO 8601 UTC. |
| `data.type` | string | normal, or deposit when it is an advance payment. |
| `data.treasuryAccountId` | string | Treasury account the payment goes through. |
| `data.contactId` | string | Customer or supplier of the payment; null if not declared. |
| `data.reference` | string | External reference of the payment; null if it has none. |
| `data.linkedDocuments` | object[] | Documents the payment is assigned to; empty if it is not linked to any. |
| `data.linkedDocuments.type` | string | Kind of the linked document. `invoice`, `creditNote`, `supplierInvoice`, `quote`, `proforma`, `salesReceipt`, `simpleCreditNote`, `purchaseOrder` |
| `data.linkedDocuments.id` | string | Identifier of the linked document. |
| `data.linkedDocuments.amount` | string | Amount of this payment assigned to the document, as a decimal string. |
| `data.createdAt` | string<date-time> | Creation date in ISO 8601 UTC. |
| `data.updatedAt` | string<date-time> | Last modification date in ISO 8601 UTC. |
| `meta` | object | Additional information about the response. |
| `meta.warnings` | object[] | Lifecycle warnings; present only when the operation is deprecated. |
| `meta.warnings.code` | string | Stable warning code. `deprecated` |
| `meta.warnings.message` | string | For people: what is deprecated, until when, and what to use. |
| `meta.warnings.sunset` | string | Day (YYYY-MM-DD) the operation stops being served. |
| `meta.warnings.replacement` | string | `operationId` of the operation to use instead, or null if there is none. |
| `meta.warnings.link` | string | Where the deprecation is documented (the changelog). |

*Example response · 201*

```json
{
  "data": {
    "id": "payment_9f3a2b",
    "direction": "Example direction",
    "amount": "120.00",
    "currency": "EUR",
    "date": "2026-09-01T08:00:00.000Z",
    "type": "Example type",
    "treasuryAccountId": "treasury_account_9f3a2b",
    "contactId": "contact_9f3a2b",
    "reference": "2026-0001",
    "linkedDocuments": [
      {
        "type": "invoice",
        "id": "linked_document_9f3a2b",
        "amount": "120.00"
      }
    ],
    "createdAt": "2026-09-01T08:00:00.000Z",
    "updatedAt": "2026-09-01T08:00:00.000Z"
  }
}
```

## Errors

| Status | Codes | Meaning |
| --- | --- | --- |
| 400 | `validation_error` | Malformed query or body. `errors[]` lists every offending field with its stable code. |
| 404 | `not_found` | It does not exist or is outside the scope of the API key. |
| 409 | `conflict` | The current state of the resource prevents the operation, a request with that Idempotency-Key is already in progress, or another conditional write (`If-Match`) held the resource for more than five seconds. `errors[0].code` says which: `in_progress` and `lock_timeout` are solved by retrying; `invalid_state` is not, because the state of the resource forbids the operation. |
| 412 | `precondition_failed` | The `If-Match` entity tag does not match the current representation. Read the resource again and retry. |
| 422 | `idempotency_key_reused` | The same key was used before with a different body. Change the key. |

## Deprecation

This operation is not deprecated. Deprecations are announced with a Deprecation header and a sunset date.

---

Canonical URL: https://docs.filmo.io/rest-api/endpoint-reference/treasury/link-a-payment-to-a-document  
Last updated: 2026-10-25