viakite
Dashboard

API/Basics/Pagination

Pagination

Cursors and limits

Endpoints that list things, such as keys, goals, webhooks or deliveries, return one page at a time. You ask for up to 200 rows, and the answer holds a cursor that points at the next page. Pass it back until there is none.

A page

Every list answers with data and, when more rows follow, next_cursor:

response.json
1{
2 "data": [
3 { "id": "gol_01JD8Q3W6ZK4M2N7P9R5T1V3X8", "name": "Signed up" },
4 { "id": "gol_01JD8Q5B2C4E6G8J0L2N4P6R8T", "name": "Started trial" }
5 ],
6 "next_cursor": "MjAyNi0xMS0xOVQxMDozMDowMFp8Z29sXzAxSkQ4UTVCMkM0RTZHOEowTDJONFA2UjhU"
7}

When next_cursor is missing, you have the last page. An empty list is { "data": [] }, never null.

Parameters

limitintegerdefault 50
How many rows to return, from 1 to 200. Anything else is 400 invalid_limit.
cursorstring
The next_cursor of the previous page. Leave it out for the first page. A cursor the API didn't give you is 400 invalid_cursor.
terminal
1curl "https://us.api.vk.viabio.me/v1/projects/prj_…/goals?limit=200&cursor=MjAyNi0x…" \
2 -H "Authorization: Bearer sk_live_us_…"

Treat the cursor as an opaque string: don't build one, change one or store one for later. Keep the same limit and other parameters while you walk one list.

Order

Rows come in a fixed order, by the time they were made and then by id, so a page never repeats a row or skips one, even when rows are added while you walk the list. Most lists are oldest first; a few, such as a webhook's deliveries, are newest first. The reference says which for each list.

Walk every page

list-all.mjs
1const base = "https://us.api.vk.viabio.me";
2const headers = { Authorization: `Bearer ${process.env.VIAKITE_SECRET_KEY}` };
3
4async function* listAll(path) {
5 let cursor;
6 do {
7 const url = new URL(path, base);
8 url.searchParams.set("limit", "200");
9 if (cursor) url.searchParams.set("cursor", cursor);
10
11 const res = await fetch(url, { headers });
12 if (!res.ok) throw new Error((await res.json()).error.code);
13 const page = await res.json();
14
15 yield* page.data;
16 cursor = page.next_cursor;
17 } while (cursor);
18}
19
20for await (const goal of listAll("/v1/projects/prj_…/goals")) {
21 console.log(goal.id, goal.name);
22}
list_all.py
1import os
2import requests
3
4BASE = "https://us.api.vk.viabio.me"
5HEADERS = {"Authorization": f"Bearer {os.environ['VIAKITE_SECRET_KEY']}"}
6
7def list_all(path):
8 params = {"limit": 200}
9 while True:
10 res = requests.get(BASE + path, headers=HEADERS, params=params)
11 res.raise_for_status()
12 page = res.json()
13 yield from page["data"]
14 cursor = page.get("next_cursor")
15 if not cursor:
16 return
17 params["cursor"] = cursor
18
19for goal in list_all("/v1/projects/prj_…/goals"):
20 print(goal["id"], goal["name"])

Reports are not paged

Analytics queries don't use cursors. POST /v1/projects/{project}/analytics/query returns all its rows in one answer: 100 rows by default, up to 10,000 with limit. To get fewer rows, filter or ask for fewer breakdowns; see Querying analytics.

Not built yet

A cursor to read past 10,000 rows of a report is planned and not built. For a breakdown with more values than that, split the date range or add a filter and run several queries.

Next steps