Core concepts
Pagination
List endpoints return one page at a time, newest first. Follow nextCursor until it's null.
Parameters#
| Query parameter | Meaning |
|---|---|
limit | Items per page, from 1 to 100. Default 25. Values outside the range are clamped to it. |
cursor | The nextCursor from the previous page. Leave it out for the first page. It's opaque: don't build or change it. |
Response#
{
"data": ["…"],
"nextCursor": "aWQ6NTAxMg",
"hasMore": true
}- Items are ordered newest first.
- On the last page,
nextCursorisnullandhasMoreisfalse. - Keep any filters the same on every page of one read.
- Items created while you page don't appear on later pages, because they're newer than the cursor. Start again from the first page to pick them up.
Which endpoints are paginated#
| Paginated (returns a page) | Not paginated (returns an array) |
|---|---|
GET /customersGET /invoicesGET /webhook-endpoints/{id}/deliveries | GET /customers/{id}/enrollmentsGET /invoices/{id}/paymentsGET /webhook-endpoints |
Reading every page#
let cursor = null;
do {
const url = new URL(`${process.env.FLUX_BASE_URL}/api/v1/invoices`);
url.searchParams.set("limit", "100");
if (cursor) url.searchParams.set("cursor", cursor);
const response = await fetch(url, { headers: { Authorization: `ApiKey ${process.env.FLUX_API_KEY}` } });
const page = await response.json();
for (const invoice of page.data) console.log(invoice.number, invoice.status);
cursor = page.nextCursor;
} while (cursor);import os
import requests
url = f"{os.environ['FLUX_BASE_URL']}/api/v1/invoices"
headers = {"Authorization": f"ApiKey {os.environ['FLUX_API_KEY']}"}
params = {"limit": 100}
while True:
page = requests.get(url, headers=headers, params=params, timeout=30).json()
for invoice in page["data"]:
print(invoice["number"], invoice["status"])
if not page["nextCursor"]:
break
params["cursor"] = page["nextCursor"]<?php
$cursor = null;
do {
$query = http_build_query(array_filter(['limit' => 100, 'cursor' => $cursor]));
$ch = curl_init(getenv('FLUX_BASE_URL') . '/api/v1/invoices?' . $query);
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => ['Authorization: ApiKey ' . getenv('FLUX_API_KEY')],
CURLOPT_RETURNTRANSFER => true,
]);
$page = json_decode(curl_exec($ch), true);
foreach ($page['data'] as $invoice) {
echo $invoice['number'], ' ', $invoice['status'], PHP_EOL;
}
$cursor = $page['nextCursor'];
} while ($cursor !== null);using System.Net.Http.Json;
using System.Text.Json;
string? cursor = null;
do
{
var url = $"{baseUrl}/api/v1/invoices?limit=100" + (cursor is null ? "" : $"&cursor={Uri.EscapeDataString(cursor)}");
var page = await http.GetFromJsonAsync<JsonElement>(url);
foreach (var invoice in page.GetProperty("data").EnumerateArray())
Console.WriteLine($"{invoice.GetProperty("number")} {invoice.GetProperty("status")}");
cursor = page.GetProperty("nextCursor").GetString();
} while (cursor is not null);type invoicePage struct {
Data []struct {
Number string `json:"number"`
Status string `json:"status"`
} `json:"data"`
NextCursor *string `json:"nextCursor"`
}
cursor := ""
for {
q := url.Values{"limit": {"100"}}
if cursor != "" {
q.Set("cursor", cursor)
}
req, _ := http.NewRequest("GET", os.Getenv("FLUX_BASE_URL")+"/api/v1/invoices?"+q.Encode(), nil)
req.Header.Set("Authorization", "ApiKey "+os.Getenv("FLUX_API_KEY"))
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
var page invoicePage
json.NewDecoder(resp.Body).Decode(&page)
resp.Body.Close()
for _, inv := range page.Data {
fmt.Println(inv.Number, inv.Status)
}
if page.NextCursor == nil {
break
}
cursor = *page.NextCursor
}