Concepts
Pagination
Walk through lists with a cursor.
Every list endpoint returns objects newest first, in this envelope:
{
"object": "list",
"url": "/v1/collections",
"data": [ { "id": "9e2d4a7b-…", "object": "collection" } ],
"has_more": true
}| Parameter | Description |
|---|---|
limit |
Objects per page, 1 to 100. Default 20. |
starting_after |
ID of the last object you received. Returns the objects that come after it. |
To read everything, repeat the call with starting_after set to the last id of data, while has_more is true:
async function* all(path) {
let after = null;
while (true) {
const url = new URL('https://api.monerail.com/v1' + path);
url.searchParams.set('limit', '100');
if (after) url.searchParams.set('starting_after', after);
const page = await (await fetch(url, { headers: { Authorization: `Bearer ${process.env.MONERAIL_KEY}` } })).json();
yield* page.data;
if (!page.has_more) return;
after = page.data[page.data.length - 1].id;
}
}
for await (const tx of all('/transactions')) console.log(tx.type, tx.amount);def all_objects(path):
after = None
while True:
params = {"limit": 100}
if after:
params["starting_after"] = after
page = requests.get(
"https://api.monerail.com/v1" + path,
headers={"Authorization": f"Bearer {os.environ['MONERAIL_KEY']}"},
params=params,
timeout=30,
).json()
yield from page["data"]
if not page["has_more"]:
return
after = page["data"][-1]["id"]
for tx in all_objects("/transactions"):
print(tx["type"], tx["amount"])Some lists accept filters, such as type on transactions and events, or status and cardholder on cards. Keep the same filters on every page. Every page counts toward the rate limit.