Pagination
Every list comes a page at a time, in one shape, with a cursor to the next page.
Five endpoints return lists: List conversations, Search documents, List mailboxes, List groups and List tags. Each answers the same way:
{
"data": [ { "id": "cnv_8k2m4q7rx9tbw3hd", "subject": "Where is my order?" } ],
"has_more": true,
"next_cursor": "eyJ2IjoxLCJrIjpbMSwyLC0zLC0xNzkxNTU2MzI1MDAwLCJjbnZfOGsybTRxN3J4OXRidzNoZCJdfQ.9f2c4e1a7b3d5f60a8c2e4b6d8f0a1c3"
}
datais the page, in order.has_moreis true when there's more after it.next_cursoris where the next page starts. Null on the last page.
Each list takes:
limit: how many per page, from 1 to 100. Leave it out and you get 25.cursor: thenext_cursorfrom the page before. Leave it out for the first page.
Pass the same filters with every page (only limit may change). A cursor is opaque and signed: don't build or change one. A cursor the API didn't give out, one changed on the way, or one sent with other filters, another sort or another key answers 400 invalid_request with param: "cursor", never a silent restart from the top. If that happens mid-walk (say, after you switched to a new key), start again from the first page, without a cursor.
Reading every page
let cursor = null;
const all = [];
do {
const url = new URL("https://app.userookery.com/api/v1/conversations");
url.searchParams.set("view", "open");
url.searchParams.set("limit", "100");
if (cursor) url.searchParams.set("cursor", cursor);
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.ROOKERY_API_KEY}` } });
const page = await res.json();
all.push(...page.data);
cursor = page.next_cursor;
} while (cursor);
import os, requests
cursor, everything = None, []
while True:
params = {"view": "open", "limit": 100}
if cursor:
params["cursor"] = cursor
page = requests.get(
"https://app.userookery.com/api/v1/conversations",
headers={"Authorization": f"Bearer {os.environ['ROOKERY_API_KEY']}"},
params=params,
).json()
everything.extend(page["data"])
cursor = page["next_cursor"]
if not cursor:
break
Each page counts toward the rate limit. Most jobs need one page, not all of them: see below.
Order
A cursor marks where the last page ended, by the last item's place in the order, not by a count. So a page never repeats or skips an item that didn't change in between, even when new ones arrive.
- Conversations come in the inbox's order, and
sortpicks another:newest,waited(whoever has waited longest first) ordue(the soonest due first). Each goes by priority first and orders within it, so the first page is always the most pressing. Ties go by id. Every page keeps the order the first page was read in, even as time passes and something becomes overdue. - Documents come newest first.
- Mailboxes, groups and tags come in name order.
A conversation that changes while you page (a new message, a new priority) may move to a page you've already read. To act on what changed, use webhooks rather than reading the list again.
Ask for less
Narrowing the list is usually better than reading all of it:
viewpicksopen,waiting,snoozed,closedorall. Most work lives inopen.mailbox_idkeeps to one inbox. Get the ids from List mailboxes.qsearches the text of every message, so a name, an order number or an address finds the thread.referencefinds the conversations about one of your app's records, likeorder_8841.assigned=meshows what's assigned to your key's agent, andassigned=unassignedwhat nobody has.priority,target_state(on_track,at_risk,overdueornone) andscreening(pendinglists New senders) narrow it further.sort=dueputs what's due soonest first, so the first page is what needs a reply next.- For documents,
kindpicks invoices, receipts, contracts and so on, andqsearches titles and what Rook read.