Skip to Content

Documentation

Pagination

Read a list a page at a time, passing each page's cursor to get the next one.

Lists come a page at a time. Each page says whether there is another, and where it starts.

Page Fields

A page holds its items and says where the next one starts.

FieldContains
dataThe page's items
pagination.hasMoreWhether there is a next page
pagination.nextCursorWhere the next page starts

The first request takes no cursor. Pass each page's nextCursor as cursor to read the next one, until a page comes with hasMore set to false and nextCursor to null.

Read Every Page

This reads every post of an account, a page at a time.

import { SocialAPI } from "@socialapihq/sdk";

const client = new SocialAPI({ apiKey: process.env.SOCIALAPI_API_KEY });

let cursor: string | undefined;
do {
  const page = await client.tiktok.profilePosts({ handle: "nike", cursor });
  for (const post of page.data) console.log(post.url, post.stats.views);
  cursor = page.pagination.hasMore ? (page.pagination.nextCursor ?? undefined) : undefined;
} while (cursor);

Cost and Cache

Each page is a call of its own. It costs credits and is cached like any other, so reading it again soon is free.

Cursors

A cursor belongs to its list and its parameters, so use it with the same parameters, and soon after you get it. Page sizes differ by platform, as Compare Platforms shows.