Pagination, filtering and ordering
How to walk through lists with page and page_size, filter and order results, and sync changes incrementally with updated_after.
Pagination
List endpoints return a page of results in this format:
{
"count": 123,
"next": "https://api.billora.app/api/v1/invoices/?page=3&page_size=50",
"previous": "https://api.billora.app/api/v1/invoices/?page=1&page_size=50",
"results": [ { "id": 5120, "number": "F-2026-0001" } ]
}| Parameter | Default | Description |
|---|---|---|
page | 1 | Page number, starting at 1. |
page_size | 50 | Items per page, up to 200 (larger values are capped at 200). |
countis the total number of items matching the filters.nextandpreviousare full URLs (ornull). To walk a list, follownextuntil it isnullinstead of building URLs yourself.- A page out of range returns
404 not_found.
Some lists (products, units, payments…) historically returned a plain array in the web app. With an API key they always use the paginated format above.
async function* listAll(path) {
let url = `https://api.billora.app/api/v1${path}`;
while (url) {
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.BILLORA_API_KEY}` } });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const page = await res.json();
yield* page.results;
url = page.next;
}
}
for await (const customer of listAll("/customers/?page_size=200")) {
console.log(customer.id, customer.legal_name);
}import os, requests
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['BILLORA_API_KEY']}"
def list_all(path):
url = f"https://api.billora.app/api/v1{path}"
while url:
res = session.get(url, timeout=30)
res.raise_for_status()
page = res.json()
yield from page["results"]
url = page["next"]
for customer in list_all("/customers/?page_size=200"):
print(customer["id"], customer["legal_name"])function listAll(string $path): Generator {
$url = "https://api.billora.app/api/v1" . $path;
while ($url) {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("BILLORA_API_KEY")],
CURLOPT_RETURNTRANSFER => true,
]);
$page = json_decode(curl_exec($ch), true);
yield from $page["results"];
$url = $page["next"];
}
}
foreach (listAll("/customers/?page_size=200") as $customer) {
echo $customer["id"], " ", $customer["legal_name"], "\n";
}Filters
Filters are query string parameters. Invalid values (a malformed date, a non-numeric id) return 400 validation_error, never a surprisingly empty list.
Filters shared by every public resource
| Parameter | Example | Returns items… |
|---|---|---|
created_after | 2026-10-01 | created at or after that date/time |
created_before | 2026-10-31T23:59:59Z | created before that date/time |
updated_after | 2026-11-01T08:00:00Z | changed at or after that date/time |
updated_before | 2026-11-01 | changed before that date/time |
search | talleres | containing the text in their search fields (number, name, tax id, notes…) |
ordering | -created_at | ordered by that field (see below) |
They accept a date (YYYY-MM-DD) or an ISO 8601 date-time with offset. A date without time means 00:00 that day in Spanish mainland time (Europe/Madrid). *_after filters are inclusive (>=) and *_before ones exclusive (<), so ranges chain without overlap.
Per-resource filters
Each resource adds its own; the full list is in the reference. For example, on /invoices/:
| Parameter | Description |
|---|---|
status | draft, sent, partially_paid, paid, overdue, rectified, cancelled… |
customer | Customer id. |
number | Number contains this text. |
date_from / date_to | Issue date from / to (YYYY-MM-DD). |
total_min / total_max | Total including tax between those amounts. |
is_rectifying | true to list only corrective invoices. |
is_simplified | true to list only simplified invoices. |
curl "https://api.billora.app/api/v1/invoices/?status=overdue&date_from=2026-01-01&ordering=due_date" \
-H "Authorization: Bearer $BILLORA_API_KEY"Ordering
ordering takes a field name; prefix it with - for descending order. Combine several with commas: ordering=-issue_date,number. Each resource documents which fields it accepts; for sales documents they are issue_date, number, total and created_at (default -issue_date,-number).
Incremental sync
To keep a copy of the data in your system (ERP, BI, CRM), don't download everything every time: ask only for what changed since the last sync with updated_after.
- Store the sync start time before you start requesting data.
- Request
updated_after=<last sync>with a stable order (ordering=created_at) and walk every page. - Upsert by
idin your database. - When you finish without errors, store the time from step 1 as the new “last sync”.
Subtracting a few minutes from the previous mark avoids missing changes committed right during the sync; since you upsert by id, processing an item twice has no effect.
import { setTimeout as sleep } from "node:timers/promises";
const API = "https://api.billora.app/api/v1";
const headers = { Authorization: `Bearer ${process.env.BILLORA_API_KEY}` };
export async function syncInvoices(db) {
const startedAt = new Date();
const since = await db.getCursor("invoices"); // ISO string or null
const margin = since ? new Date(new Date(since).getTime() - 5 * 60_000).toISOString() : null;
let url = `${API}/invoices/?page_size=200&ordering=created_at` + (margin ? `&updated_after=${encodeURIComponent(margin)}` : "");
while (url) {
const res = await fetch(url, { headers });
if (res.status === 429) {
await sleep(Number(res.headers.get("Retry-After") ?? 5) * 1000);
continue;
}
if (!res.ok) throw new Error(`HTTP ${res.status} ${res.headers.get("X-Request-Id")}`);
const page = await res.json();
for (const invoice of page.results) await db.upsertInvoice(invoice);
url = page.next;
}
await db.setCursor("invoices", startedAt.toISOString());
}import os, time
from datetime import datetime, timedelta, timezone
import requests
API = "https://api.billora.app/api/v1"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['BILLORA_API_KEY']}"
def sync_invoices(db):
started_at = datetime.now(timezone.utc)
since = db.get_cursor("invoices") # datetime or None
params = {"page_size": 200, "ordering": "created_at"}
if since:
params["updated_after"] = (since - timedelta(minutes=5)).isoformat()
url = f"{API}/invoices/"
while url:
res = session.get(url, params=params, timeout=30)
if res.status_code == 429:
time.sleep(int(res.headers.get("Retry-After", 5)))
continue
res.raise_for_status()
page = res.json()
for invoice in page["results"]:
db.upsert_invoice(invoice)
url, params = page["next"], None # next already carries the query string
db.set_cursor("invoices", started_at)Combine it with webhooks
Incremental sync is the safety net; webhooks tell you instantly. The most robust setup uses both: process webhooks in real time and run the sync periodically to recover any missed event.
Deletions don't show up in updated_after (the item no longer exists). To mirror them, listen to the *.deleted events or compare ids periodically.
