> For the complete index of the 402pay docs, see [llms.txt](https://developer.402pay.co/llms.txt).

# Metadata

Attach your own key-value data to payments and filter by it.

Attach your own data to a payment with `metadata`: up to 20 keys of up to 40 characters, with string values up to 500 characters. Keys use only letters, digits, `_`, `.` and `-`.

- [`PATCH /payments/{id}`](https://developer.402pay.co/api/payments/update.md) merges by key. Set a key to an empty string or `null` to remove it, or send `"metadata": null` to clear them all.
- Filter lists by it, such as `GET /payments?metadata[order_id]=1042`.
- It comes back on the payment and in every event about it, so your webhook handler has what it needs.

Update metadata, cURL:

```bash
curl -X PATCH "https://dash.402pay.co/api/v1/payments/pmt_QI02vLdJGd48hBbg" \
  -H "Authorization: Bearer $PAY402_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "metadata": {
      "plan": "pro",
      "seats": "5",
      "coupon": ""
    }
  }'
```

Update metadata, Node.js:

```js
const response = await fetch("https://dash.402pay.co/api/v1/payments/pmt_QI02vLdJGd48hBbg", {
  method: "PATCH",
  headers: {
    Authorization: `Bearer ${process.env.PAY402_SECRET_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    metadata: {
      plan: "pro",
      seats: "5",
      coupon: ""
    }
  }),
});
const { data } = await response.json();
```

Update metadata, Python:

```python
import os

import requests

response = requests.patch(
    "https://dash.402pay.co/api/v1/payments/pmt_QI02vLdJGd48hBbg",
    headers={
        "Authorization": f"Bearer {os.environ['PAY402_SECRET_KEY']}",
    },
    json={
        "metadata": {
            "plan": "pro",
            "seats": "5",
            "coupon": ""
        }
    },
)
data = response.json()["data"]
```
