Pagination, filters, and sorting
To read more records than one response holds, request a page with page_size, send each response's next_page_token back as page_token, and stop when a response has no next_page_token. Every paginated list in the Flint API works this way, from orders and customers to refunds, payouts, and webhook events. The same request carries your filters, your sort, and any related records you want included on each row.
Lists that always return every result, including saved Flint Wallet cards and currency balances, have no page_token parameter or next_page_token response field.
Read the first page#
A paginated list takes two pagination parameters:
| Parameter | Type | What it does |
|---|---|---|
page_size | integer | Maximum records per page, from 1 to 100. Defaults to 20 when you leave it out; a few lists publish a different default in their reference, such as 100 on GET /v1/webhook-event-types. Tax registrations default to 20. A value outside 1 to 100 is rejected, not clamped. |
page_token | string | The next_page_token from the previous response. Leave it out on the first request. |
Fetch the first two orders:
curl "https://api.withflintpay.com/v1/orders?page_size=2" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"data": [
{
"order_id": "ord_01KWJZAEESGE95VN6GP5J7H6MQ",
"order_number": "1043",
"status": "open",
"payment_status": "unpaid",
"pricing_amounts": {
"total_money": { "amount": 5444, "currency": "USD" }
},
"created_at": "2026-07-02T18:04:11Z"
},
{
"order_id": "ord_01KWJYV5B8T0AHXQ2M4E7RCN2D",
"order_number": "1042",
"status": "closed",
"payment_status": "paid",
"pricing_amounts": {
"total_money": { "amount": 12000, "currency": "USD" }
},
"created_at": "2026-07-02T17:31:48Z"
}
],
"next_page_token": "Zm9yd2FyZC1vbmx5LW9wYXF1ZS1jdXJzb3I",
"request_id": "req_01KWM6WAHG3N9Q8T2V5XRZ7C4D"
}
The order objects are trimmed. Every list response has the same envelope:
data: the page of records, in the list's order. It can be empty.next_page_token: present when more records follow. It is left out on the last page.request_id: the ID of this request, for support.meta: response metadata such asapi_versionand anywarnings, when present.
List responses don't include a total count of matching records.
Fetch the next page#
Send the same request again with page_token set to the token you received:
curl "https://api.withflintpay.com/v1/orders?page_size=2&page_token=$NEXT_PAGE_TOKEN" \
-H "Authorization: Bearer YOUR_API_KEY"
When a response arrives without next_page_token, you have read the whole list.
Note: A token belongs to the query that produced it
Send every page of a run to the same endpoint, with the same filters and sort, under the same merchant and environment. Set page_token to the previous response's next_page_token. You may change page_size between pages. A token sent with a different filter or sort returns 400 INVALID_REQUEST with param: page_token. To change the query, start a new run from the first page.
Treat tokens as opaque. Don't parse or build them, and don't store them for later: their format isn't part of the API and can change. There are no page numbers or offsets, so a run moves forward one page at a time. If Flint rejects a token, start again from the first page.
You may also change expand mid-run, because it changes how each row is represented and not which rows the list returns. See Expansion and the cursor.
Read every record#
With an SDK#
The SDKs give every list operation an Items companion that follows next_page_token, keeps your filters on every page, and yields one record at a time. maxItems or maxPages caps the run. Each page fetch gets its own deadlineMs, including retries. To share one time budget across page fetches in Node, pass one AbortSignal.timeout(...) as signal when you start the iteration.
for await (const order of flint.orders.listItems(
{ payment_status: ["paid"], page_size: 100 },
{ maxItems: 1000, deadlineMs: 60000 },
)) {
console.log(order.order_id, order.pricing_amounts.total_money);
}
foreach ($flint->orders->listItems(
['payment_status' => ['paid'], 'page_size' => 100],
new RequestOptions(maxItems: 1000, deadlineMs: 60000),
) as $order) {
echo $order->order_id, PHP_EOL;
}
A plain list call returns one page with its next_page_token, and listPages yields one page at a time when you want each envelope.
With the CLI#
List commands return one page by default. --all fetches every page and merges them into one envelope, and --limit N collects up to N records, requesting at most 100 per page, and keeps next_page_token so you can continue with --page-token:
flint orders list --all --output json
flint orders list --limit 150 --output json
For a raw route, flint api get "/v1/orders?status=open" --all merges every page, and --paginate prints each page as its own JSON line. See CLI.
Over HTTP#
Loop until a response has no next_page_token. Lists use the read rate limit budget, so a long export should wait out a 429 and resume with the same token:
async function listAll(path, params) {
const records = [];
let pageToken;
for (;;) {
const url = new URL(path, "https://api.withflintpay.com");
for (const [key, value] of Object.entries(params)) {
url.searchParams.set(key, value);
}
if (pageToken) url.searchParams.set("page_token", pageToken);
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.FLINT_API_KEY}` },
});
if (response.status === 429) {
const seconds = Number(response.headers.get("Retry-After") ?? "1");
await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
continue;
}
const page = await response.json();
if (!response.ok) {
throw new Error(`${page.error.code}: ${page.error.message}`);
}
records.push(...page.data);
pageToken = page.next_page_token;
if (!pageToken) return records;
}
}
const openOrders = await listAll("/v1/orders", {
status: "open",
page_size: "100",
});
A loop that reads one page at a time stays well inside the read budget. If you run several loops in parallel, honor Retry-After and back off as Rate limits describes.
Order and sorting#
Every list returns records in a fixed default order, which its API reference states, such as "created_at descending, then order_id descending". Most lists return the newest records first. Some read in their natural order instead: product variants by position, inventory movements and delivery methods oldest first, webhook event types by name. When two records share a sort value, the resource ID breaks the tie, so a page boundary never repeats or skips a record whose sort value stays the same.
Lists that let you choose take two parameters:
sort_by: the response field to order by, named as it appears in the response, such ascreated_at,updated_at, orpricing_amounts.total_moneyon orders. Each list accepts its own set, and its reference lists them with the default.sort_direction:ascordesc. Some lists, such as inventory movements and the activity lists, take onlysort_directionto reverse their default order.
curl "https://api.withflintpay.com/v1/customers?sort_by=name&sort_direction=asc&page_size=50" \
-H "Authorization: Bearer YOUR_API_KEY"
Values are case-sensitive, and money fields sort numerically in minor units. Records without a value for the sort field have a fixed place: invoices without a due date or invoice number sort last in both directions when you sort by that field.
A run reads records in place, so changes made while you page through a list behave predictably:
- With a newest-first order, records created after your first page don't appear later in the run. Start a new run to pick them up.
- With an oldest-first order, such as
sort_by=created_at&sort_direction=asc, new records join the end of the list and your loop reaches them. - If you sort by a field that changes, such as
updated_at, a record updated during the run can appear again on a later page or be missed. De-duplicate by ID, or sort bycreated_atwhen you need every record exactly once.
Inventory levels use (updated_at, inventory_level_id) order with whole-second timestamps. A lower-ID level changed in the cursor's second stays behind that cursor. For stock syncs, exclude the current second with a fixed updated_before boundary, overlap completed windows, and consume durable inventory events or reconcile every level on each scheduled sync. Poll changed levels gives the guarantees and recovery steps; pagination alone is not a lossless change feed.
Filter a list#
Filters combine with pagination, and the cursor carries them through every page. Separate filters are ANDed: GET /v1/payment-intents?status=succeeded,canceled&refund_status=none returns payments that succeeded or were canceled and have no refunds.
curl "https://api.withflintpay.com/v1/orders?status=open&created_after=2026-01-01T00:00:00Z&sort_by=created_at&sort_direction=asc&page_size=50" \
-H "Authorization: Bearer YOUR_API_KEY"
Each endpoint's reference lists its filters. They follow a few shared rules.
Time ranges#
Timestamp range filters come in _after and _before pairs named for the field they filter: created_after and created_before filter created_at, updated_after filters updated_at, and invoice issued_after filters issued_at. Some lists filter their own timestamps, such as occurred_after on balance transactions and opened_after on payment reviews.
- They take RFC 3339 timestamps, such as
2026-09-01T00:00:00Z. A fractional-second bound compares as the instant you send. _afterincludes the instant it names, and_beforeexcludes it.created_after=2026-09-01T00:00:00Z&created_before=2026-10-01T00:00:00Zis exactly September, and the next window starts at2026-10-01T00:00:00Zwithout sharing a record.- A record with no value for the field matches no bound. An invoice that was never issued has no
issued_at, so anyissued_afterorissued_beforeleaves it out. - A range that ends before it starts returns
400 INVALID_REQUEST, withparamnaming the later bound.
Invoice lists filter due_date by calendar date: due_date_from (inclusive) and due_date_to (exclusive) take YYYY-MM-DD dates in each invoice's timezone, which is a snapshot of the merchant's timezone taken when the draft was written, or UTC when the merchant had none. due_date_from=2026-09-01&due_date_to=2026-10-01 selects September due dates.
Payouts filter arrival by calendar date: arrival_date_from and arrival_date_to take strict YYYY-MM-DD dates in UTC, with an inclusive lower date and an exclusive upper date. arrival_date_from=2026-09-01&arrival_date_to=2026-10-01 selects September arrivals. Timestamps and timezone offsets are rejected.
Several values in one filter#
A filter whose reference says it takes several values, such as status, accepts repeated keys, one comma-separated value, or both. status=active&status=archived and status=active,archived select the same records, and a record matches when it has any of the values. Flint trims spaces around each value, removes duplicates, and rejects the whole request for an empty or unknown value. Invoice collection_mode and credit note reason work the same way, so GET /v1/credit-notes?reason=goodwill&reason=billing_error and ?reason=goodwill,billing_error select the same notes.
A few ID filters take several values too: order_id on GET /v1/orders matches any of up to 100 IDs. Every other filter takes one value, including booleans, text, most IDs, sort_by, and sort_direction. Send it once: a repeated key returns 400 INVALID_REQUEST with detail code INVALID_VALUE. A bracketed key such as reason[] is not a Flint parameter and returns UNKNOWN_FIELD.
Archived and deleted records#
A list leaves out records whose status is archived or deleted unless your status filter names that status. Without a status filter, you get every other status. To include archived records with the rest, name every status you want, such as GET /v1/delivery-methods?status=active,inactive,archived.
Exact-match filters#
An exact-match filter compares your value with the whole stored value, never part of it. Customer segment and phone, invoice invoice_number, product sku, and risk list alias are examples. A comma is part of the value, not a separator, and a valid value that matches nothing returns an empty page. Use one when you hold an identifier from another system.
Some exact-match filters normalize your value before comparing, and others compare it as sent. Each parameter's reference says which:
| Filter | Comparison |
|---|---|
Customer segment and phone | As sent, including case and whitespace. Encode the leading + of a phone number as %2B, as in phone=%2B14155551234; an unencoded + reads as a space. |
Invoice invoice_number | Byte for byte, so inv-1042 doesn't select INV-1042. Invoices without a number, such as drafts, never match. |
Product and product variant sku | Ignores surrounding whitespace, case, and accents. Both cafe-12 and cafe-12 select Café-12. |
Product variant_external_reference_id and variant external_reference_id | Byte for byte, including case, whitespace, and Unicode. |
Payment method domain domain_name | Trimmed and lowercased, so Shop.Example.com selects shop.example.com. |
Risk list alias | As sent. It must already be a valid lowercase alias. |
Risk list item value | Normalized the way the list's item_type normalizes items you add. |
Payment intent and refund currency | A three-letter uppercase ISO 4217 code, such as USD. Lowercase or padded values are rejected. |
The cursor records each filter after normalization, so a later page can spell a normalized value differently. A run that started with domain_name=shop.example.com continues with domain_name=SHOP.EXAMPLE.COM, and one that started with sku=Café-12 continues with sku=cafe-12. A value compared as sent has no other spelling, so changing it ends the run.
On the product list, exact variant filters also decide which variant matched_variant names. See Find products through their variants.
Search#
Lists such as customers, orders, products, and returns take query, a search across several fields that the reference names. Text fields match any part of the value. Search ignores case and accents, and treats a run of whitespace as a single space. For example, cafe creme matches Café Crème. The characters %, _, and \ are ordinary characters, not wildcards. IDs match from the start and need their type prefix, so prod_01M2 finds a product and 01M2 doesn't.
query and an exact-match filter answer different questions. query=LATTE can return products whose name, description, or SKU contains that text. sku=ESP-LATTE-16 returns only a product with a variant whose whole SKU is ESP-LATTE-16. Use query for a search box and exact filters for lookups. You can send both, and a record must satisfy both.
Unsupported parameters#
Flint rejects a query parameter the endpoint doesn't accept, such as a typo or a filter from another resource, with 400 INVALID_REQUEST, detail code UNKNOWN_FIELD, and param naming the parameter. Parameter names are case-sensitive. A mistake fails on the first request instead of returning unfiltered results.
Expand related records#
Many merchant lists accept expand, which adds a related record to every row of the page. Expanding responses covers the paths each list accepts, the scopes they need, and how expansion works with pages and cursors.
Product variant page budget#
GET /v1/products?expand=variants returns at most 500 expanded variants per page. Flint ends the page before the first product that would exceed that budget, while always returning at least one product. Each product can have at most 250 non-archived variants, and its expanded variants are complete and never split across pages. The same budget applies to expand=variants.modifier_set.
page_size is a maximum number of products, so a page can end early even when more products match. For example, three products with 250 variants each take two pages: the first returns two products and a next_page_token, and the next starts with the third. Follow next_page_token until it is absent, even when a page is shorter than page_size.
Syncs and exports#
A token is for the request that follows it, not for storage. To make a long sync resumable, keep your own progress marker: page through the list oldest first, such as sort_by=created_at&sort_direction=asc, save the created_at of the last record you processed, and resume later with created_after set to that value. The bound is inclusive, so the first page repeats the last record; de-duplicate by ID.
To keep a copy current, read changes with updated_after on lists that offer it, and de-duplicate by ID, since a record can change more than once between runs.
If you poll a list to notice new payments, orders, or refunds, webhooks send those events to you as they happen, without spending your read budget on repeated runs. For running totals, update them from webhooks or count during a full run, since lists don't return counts.
Errors#
Pagination and filter mistakes return 400 INVALID_REQUEST with type: validation_error. param and details[0].param name the query parameter, details[0].code says what is wrong, and message says what to send. See Validation errors for the envelope.
param | Detail code | Cause and fix |
|---|---|---|
page_size | INVALID_VALUE | Not an integer from 1 to 100. Send a value in range, or leave it out for the default. |
page_token | INVALID_VALUE | The token is malformed or no longer valid, or a filter or the sort changed during the run. Send the token exactly as received with the original query, or start again from the first page. |
sort_by or sort_direction | INVALID_VALUE | The field isn't sortable on this list, or the direction isn't asc or desc. message lists the accepted values. |
| A filter | INVALID_VALUE | The value is malformed or unknown, a single-value filter was repeated, or a range ends before it starts. For a range, param names the later bound. |
| The unknown key | UNKNOWN_FIELD | The list doesn't accept that query parameter. Check the spelling against the endpoint's reference. |
expand | INVALID_VALUE | The path isn't listed for this endpoint, or the request names more than 10 paths. Nested paths must be explicitly supported, such as variants.modifier_set on products. |
Other errors a list can return while you page through it: