Pagination
Page through list endpoints with cursors, and narrow them with limit, filters, sorting and search.
Every list endpoint, such as GET /customers or GET /charges, returns its
objects a page at a time, newest first, and you page through it with cursors.
The examples pass -g to curl so that it sends the square brackets in
filter[...] as they are.
Cursor pagination
| Parameter | Description |
|---|---|
limit | How many objects to return, from 1 to 100. Defaults to 10. A larger value returns 100. |
starting_after | An object id. The page starts right after this object. Pass the last id of a page to get the next page. |
ending_before | An object id. The page ends right before this object. Pass the first id of a page to get the previous page. |
curl -g "$WALLET/customers?limit=2" \
-H "Authorization: Bearer ${SECRET_KEY}" \
-H "X-Country: TH"{
"object": "list",
"data": [
{ "id": "cus_8d2e41f0c9b84f7e9a1d5b3c7e6f2a10", "object": "customer" },
{ "id": "cus_51b07a3e2d9c4c8b8f6e1a4d2c9b7e35", "object": "customer" }
],
"has_more": true,
"url": "/api/v1/app1/platform/wallet/customers"
}has_more is true when more objects follow the last one on the page. Ask for
the next page with that id:
curl -g "$WALLET/customers?limit=2&starting_after=cus_51b07a3e2d9c4c8b8f6e1a4d2c9b7e35" \
-H "Authorization: Bearer ${SECRET_KEY}" \
-H "X-Country: TH"To read a whole list, keep passing the last id until has_more is false:
async function* listAll(path, params = {}) {
let startingAfter;
for (;;) {
const query = new URLSearchParams({ ...params, limit: '100' });
if (startingAfter) query.set('starting_after', startingAfter);
const res = await fetch(`${process.env.WALLET}${path}?${query}`, {
headers: {
Authorization: `Bearer ${process.env.SECRET_KEY}`,
'X-Country': 'TH',
},
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const page = await res.json();
yield* page.data;
if (!page.has_more || page.data.length === 0) return;
startingAfter = page.data[page.data.length - 1].id;
}
}
for await (const customer of listAll('/customers')) {
console.log(customer.id);
}Things to know:
- The id you pass in
starting_afterorending_beforemust be an object in the same list, matching the same filters. Any other id is refused with400. has_morelooks in the direction you page: after the last object withstarting_after(or neither), before the first object withending_before.pageis refused with400(validation.query.invalid,parampage).
Sorting
sort takes a field and a direction separated by a colon:
curl -g "$WALLET/charges?sort=created_at:asc" \
-H "Authorization: Bearer ${SECRET_KEY}" \
-H "X-Country: TH"- The default is
created_at:desc, newest first. - A field without a direction sorts ascending.
- Most lists sort only by
created_at. Sorting by a field the list does not support is refused with400(E1112).
Filtering
Filters take the form filter[field][operator]=value. Leaving out the operator
means eq:
# Charges of one customer, created in October 2026
curl -g "$WALLET/charges?filter[customer_id]=cus_8d2e41f0c9b84f7e9a1d5b3c7e6f2a10&filter[created_at][gte]=2026-10-01T00:00:00Z&filter[created_at][lt]=2026-11-01T00:00:00Z" \
-H "Authorization: Bearer ${SECRET_KEY}" \
-H "X-Country: TH"| Operator | Matches when the field |
|---|---|
eq | equals the value. A comma-separated value matches any of its items. |
neq | does not equal the value. |
gt, gte, lt, lte | is greater than, at least, less than, or at most the value. |
like | contains the value, ignoring case. |
in | equals any item of a comma-separated list. |
between | lies between two comma-separated values, both included. |
null | is empty, with true; has a value, with false. |
Several filters on one request must all match.
Filters take the same forms responses use: a timestamp may be Unix seconds
(filter[created][gte]=1790812800) or RFC 3339 (2026-10-01T00:00:00Z),
created and updated name created_at and updated_at, and currency codes
may be lowercase (thb) or uppercase (THB).
Searching
q searches a list's text fields for a value, ignoring case and matching
anywhere in the field. On customers it searches name and email:
curl -g "$WALLET/customers?q=somchai" \
-H "Authorization: Bearer ${SECRET_KEY}" \
-H "X-Country: TH"A list without searchable fields refuses q with 400 (E1112).
Which fields a list accepts
Filters and search fields differ from list to list. A successful list response names them in two headers:
| Header | Lists |
|---|---|
X-Filterable-Fields | The fields you can use in filter[...], comma-separated. |
X-Searchable-Fields | The fields q searches, comma-separated. |
A filter, sort or search the list doesn't support is refused with 400
(E1112, pagination.unsupported_input). The error also lists what was refused
(rejected) and what the list accepts (allowed_filters, allowed_sort,
allowed_search).