Pagination
Page through runs and documents of the PDF Loft API with a limit and a cursor, newest first.
Limit and cursor
The list calls, GET /v1/jobs and GET /v1/documents, return the newest first, a page at a time. Send limit from 1 to 100 (30 by default). The answer holds items and nextCursor. When nextCursor is not null, send it as cursor to get the next page. A cursor is opaque: do not build or change one.
let cursor;
do {
const url = new URL('https://api.pdfloft.com/v1/documents');
url.searchParams.set('limit', '100');
if (cursor) url.searchParams.set('cursor', cursor);
const page = await fetch(url, { headers }).then((r) => r.json());
for (const document of page.items) console.log(document.name);
cursor = page.nextCursor;
} while (cursor);cursor = None
while True:
params = {"limit": 100, **({"cursor": cursor} if cursor else {})}
page = requests.get("https://api.pdfloft.com/v1/documents", headers=headers, params=params).json()
for document in page["items"]:
print(document["name"])
cursor = page["nextCursor"]
if not cursor:
break