Rows in this response.
Get started
Page through long lists
Get every row of a long list, such as all of a site's searches or pages, a page at a time with a cursor.
Endpoints that return a list, such as a site’s searches, pages or tracked keywords, send it a page at a time. Each response says how many rows there are in all and how to get the next page.
The page object
Section titled “The page object”Every list response has a page next to its rows:
{ "rows": ["..."], "page": { "shown": 25, "total": 140, "nextCursor": "p.3k9x1z" }}page.shownintegerrequiredpage.totalintegerrequiredRows across all pages.
page.nextCursorstring | nullrequiredSend it as cursor to get the next page. null on the last page.
Parameters
Section titled “Parameters”limitintegerRows per page. Each endpoint’s reference shows its default and maximum, often 25 and 100.
cursorstringThe page to get: page.nextCursor from the previous response. Leave it out for the first page.
Get every row
Section titled “Get every row”Send the same request again with cursor set to the last page.nextCursor, until it’s null. Keep every other parameter the same: a cursor belongs to the request that returned it, and sending it with a different range or filter is refused with invalid_input.
# First pagecurl "https://api.onsite.so/api/v1/sites/example.com/performance/queries?range=last_28d&limit=200" \ -H "Authorization: Bearer $ONSITE_API_KEY"
# Next page: the same request, plus the cursor from page.nextCursorcurl "https://api.onsite.so/api/v1/sites/example.com/performance/queries?range=last_28d&limit=200&cursor=p.3k9x1z" \ -H "Authorization: Bearer $ONSITE_API_KEY"async function allRows(path, key) { const rows = []; let cursor = null;
do { const url = new URL(`https://api.onsite.so/api/v1${path}`); url.searchParams.set("limit", "200"); if (cursor) url.searchParams.set("cursor", cursor);
const response = await fetch(url, { headers: { Authorization: `Bearer ${process.env.ONSITE_API_KEY}` } }); const body = await response.json(); if (!response.ok) throw new Error(`${body.error.code}: ${body.error.message}`);
rows.push(...body[key]); cursor = body.page.nextCursor; } while (cursor);
return rows;}
const queries = await allRows("/sites/example.com/performance/queries?range=last_28d", "rows");import osimport requests
def all_rows(path, key): rows, cursor = [], None while True: params = {"limit": 200} if cursor: params["cursor"] = cursor response = requests.get( f"https://api.onsite.so/api/v1{path}", params=params, headers={"Authorization": f"Bearer {os.environ['ONSITE_API_KEY']}"}, ) body = response.json() response.raise_for_status() rows += body[key] cursor = body["page"]["nextCursor"] if not cursor: return rows
queries = all_rows("/sites/example.com/performance/queries?range=last_28d", "rows")