# Recover missed payments

If your server was offline, read the list of settlements to find payments your webhook handler missed.

## Read payments credited to your wallet

The settlements list gives you the same payment records Cadmos sends by webhook. Start with no query parameters to read from the beginning. Each page holds up to 100 payments, oldest first.

```bash
curl --fail-with-body 'https://api.cadmospay.com/machine/v1/gateway/settlements' \
  -H "Authorization: Bearer ${CADMOS_ACCESS_TOKEN:?Set CADMOS_ACCESS_TOKEN}"
```

```javascript
const { CADMOS_ACCESS_TOKEN } = process.env;
if (!CADMOS_ACCESS_TOKEN) {
  throw new Error("Set CADMOS_ACCESS_TOKEN");
}

const url = new URL("https://api.cadmospay.com/machine/v1/gateway/settlements");
const response = await fetch(url, {
  method: "GET",
  redirect: "error",
  headers: {
    Authorization: "Bearer " + CADMOS_ACCESS_TOKEN,
  },
});
console.log(response.status, await response.json());
```

```python
from http.client import HTTPSConnection
import os

conn = HTTPSConnection("api.cadmospay.com", timeout=30)
path = "/machine/v1/gateway/settlements"
headers = {
    "Authorization": "Bearer " + os.environ["CADMOS_ACCESS_TOKEN"],
}
conn.request("GET", path, headers=headers)
response = conn.getresponse()
print(response.status, response.read().decode())
conn.close()
```

## Save each payment once

Match `linkUuid` to the link stored with your order. Use the settlement `id` to skip any payment you already recorded. Links created in the app can appear here with `externalReference: null`.

When `next` has a value, pass it as `cursor` to get the next page. Stop when `next` is `null`.

### Show the next-page request

```bash
curl --fail-with-body 'https://api.cadmospay.com/machine/v1/gateway/settlements' \
  -H "Authorization: Bearer ${CADMOS_ACCESS_TOKEN:?Set CADMOS_ACCESS_TOKEN}" \
  --get \
  --data-urlencode "cursor=${CURSOR:?Set CURSOR}"
```

```javascript
const { CADMOS_ACCESS_TOKEN, CURSOR } = process.env;
if (!CADMOS_ACCESS_TOKEN || !CURSOR) {
  throw new Error("Set CADMOS_ACCESS_TOKEN and CURSOR");
}

const url = new URL("https://api.cadmospay.com/machine/v1/gateway/settlements");
url.searchParams.set("cursor", CURSOR);
const response = await fetch(url, {
  method: "GET",
  redirect: "error",
  headers: {
    Authorization: "Bearer " + CADMOS_ACCESS_TOKEN,
  },
});
console.log(response.status, await response.json());
```

```python
from http.client import HTTPSConnection
from urllib.parse import urlencode
import os

conn = HTTPSConnection("api.cadmospay.com", timeout=30)
path = "/machine/v1/gateway/settlements"
path += "?" + urlencode({"cursor": os.environ["CURSOR"]})
headers = {
    "Authorization": "Bearer " + os.environ["CADMOS_ACCESS_TOKEN"],
}
conn.request("GET", path, headers=headers)
response = conn.getresponse()
print(response.status, response.read().decode())
conn.close()
```

## Resume a later sync

Set `since` to a UTC timestamp a few minutes before your previous sync, ending in `Z`. This overlap picks up late records. Use only `cursor` on subsequent pages.
