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

# Credit note metadata

> Store external references on a credit note.

Add metadata to link a credit note to records in your other systems, such as an ERP document ID. Each entry has a key and a value.

## Limits

* At most 50 keys per credit note.
* Keys up to 100 characters.
* Values up to 255 characters. Values must be strings or `null`.
* The credit note must be finalized.

## Add or update metadata

Add new keys or update existing values. Keys you do not include stay unchanged. In the example below, `synced_to_erp` stores the string `"true"`, not a boolean.

> [tab] Dashboard
>
> 1. Open the credit note detail page.
> 2. Click **Add metadata** or **Edit metadata**.
> 3. Enter your key-value pairs.
> 4. Click **Save**.

> [tab] API
>
> ```bash Merge metadata keys theme={"dark"}
> LAGO_URL="https://api.getlago.com"
> API_KEY="__YOUR_API_KEY__"
> CREDIT_NOTE_ID="__YOUR_CREDIT_NOTE_ID__"
>
> curl --location --request PUT "$LAGO_URL/api/v2/credit_notes/$CREDIT_NOTE_ID/metadata" \
>   --header "Authorization: Bearer $API_KEY" \
>   --header 'Content-Type: application/json' \
>   --data-raw '{
>     "metadata": {
>       "erp_reference": "CN-0001",
>       "synced_to_erp": "true"
>     }
>   }'
> ```

## Replace all metadata

Replacing metadata removes keys you do not include. `POST` replaces the whole set. Sending an empty object or omitting `metadata` clears all existing keys. With `PUT`, either leaves the existing metadata unchanged. The top-level `metadata` value cannot be `null`; individual values can be.

```bash Replace all metadata theme={"dark"}
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
CREDIT_NOTE_ID="__YOUR_CREDIT_NOTE_ID__"

curl --location --request POST "$LAGO_URL/api/v2/credit_notes/$CREDIT_NOTE_ID/metadata" \
  --header "Authorization: Bearer $API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "metadata": {
      "erp_reference": "CN-0001"
    }
  }'
```

## Delete metadata

Delete one key to remove a single reference, or delete all metadata to clear the credit note’s metadata.

> [tab] Dashboard
>
> 1. Open the credit note detail page.
> 2. Click **Edit metadata**.
> 3. Click the trash icon next to the key.
> 4. Click **Save**.

> [tab] API
>
> ```bash Delete one key theme={"dark"}
> LAGO_URL="https://api.getlago.com"
> API_KEY="__YOUR_API_KEY__"
> CREDIT_NOTE_ID="__YOUR_CREDIT_NOTE_ID__"
>
> curl --location --request DELETE "$LAGO_URL/api/v2/credit_notes/$CREDIT_NOTE_ID/metadata/synced_to_erp" \
>   --header "Authorization: Bearer $API_KEY"
> ```
>
> ```bash Delete all metadata theme={"dark"}
> LAGO_URL="https://api.getlago.com"
> API_KEY="__YOUR_API_KEY__"
> CREDIT_NOTE_ID="__YOUR_CREDIT_NOTE_ID__"
>
> curl --location --request DELETE "$LAGO_URL/api/v2/credit_notes/$CREDIT_NOTE_ID/metadata" \
>   --header "Authorization: Bearer $API_KEY"
> ```

## Retrieve metadata

[Retrieve the credit note](https://getlago.com/docs/v2/api-reference/credit-notes/retrieve.md) with `expands[]=metadata` to include its metadata.

> [accordion] Metadata API operations
>
> | Method and path | Effect |
> | - | - |
> | `POST /credit_notes` with `metadata` | Sets metadata at creation. |
> | `POST /credit_notes/{credit_note_id}/metadata` | Replaces all metadata. |
> | `PUT` or `PATCH /credit_notes/{credit_note_id}/metadata` | Merges keys into existing metadata. |
> | `PUT` or `PATCH /credit_notes/{lago_id}` with `metadata` | Merges keys. |
> | `DELETE /credit_notes/{credit_note_id}/metadata` | Clears all metadata. |
> | `DELETE /credit_notes/{credit_note_id}/metadata/{key}` | Deletes one key and returns the remaining metadata. |
>
> The metadata endpoints return only the metadata object, or `null`. To read metadata with the credit note, retrieve it with `expands[]=metadata`.

## Next steps

> [card] [Credit notes](https://getlago.com/docs/v2/guide/invoicing/credit-notes/overview.md)
>
> Issue, estimate and void credit notes.

> [card] [Merge metadata (API)](https://getlago.com/docs/v2/api-reference/credit-notes/metadata/merge.md)
>
> Request and response schema.

> [card] [Replace metadata (API)](https://getlago.com/docs/v2/api-reference/credit-notes/metadata/replace.md)
>
> Request and response schema.

> [card] [Delete a metadata key (API)](https://getlago.com/docs/v2/api-reference/credit-notes/metadata/delete-key.md)
>
> Request and response schema.


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