Skip to content
Chatwise
Skip to Content
Developer docs

Pagination

Read long lists page by page with cursors, and pull only what is new.

View as Markdown

Lists come in pages. Each answer has the items in data and, in pagination.nextCursor, where the next page starts:

{
  "data": [],
  "pagination": { "nextCursor": "eyJ2IjoxLCJiaW5kaW5nIjoiZXhhbXBsZSJ9" }
}
  • limit sets how many items a page has, from 1 to 100. The default is 50.
  • Leave out cursor for the first page. For the next one, send nextCursor as cursor and repeat the same filters and order.
  • nextCursor is null on the last page.
  • A cursor only works with the request it came from. With other filters, or another order, it is refused with a 400. Don't read or build cursors yourself.
  • Conversations are sorted by their latest message, so one that gets a message while you read the pages moves to the top, and you can miss it.

Read every page

async function* everyItem(path, query = {}) {
  let cursor;
  do {
    const search = new URLSearchParams({ ...query, limit: "100", ...(cursor && { cursor }) });
    const response = await fetch(`https://api.chatwise.so${path}?${search}`, {
      headers: { Authorization: `Bearer ${process.env.CHATWISE_API_KEY}` },
    });
    const body = await response.json();
    if (!response.ok) throw new Error(`${response.status}: ${body.message}`);
    yield* body.data;
    cursor = body.pagination.nextCursor;
  } while (cursor);
}

for await (const message of everyItem("/v1/messages", { channel: "WHATSAPP" })) {
  console.log(message.id, message.text);
}

Which routes have pages

Conversations, messages, a conversation's messages, WhatsApp templates and webhook deliveries. Webhook endpoints and event types are short lists and come whole.

Filter by date

Conversations and messages take from and to: ISO 8601 times with a time zone and at most milliseconds, such as 2026-11-01T00:00:00Z. from is included, to isn't, and from must come before to. In a URL, write the + of a time zone such as +05:30 as %2B.

Pull only new messages

To copy messages on a schedule, sort by when Chatwise stored them. That also finds imported history, whose sentAt is older:

curl 'https://api.chatwise.so/v1/messages?timeField=ingestedAt&order=asc&from=2026-11-13T00:00:00Z&to=2026-11-14T00:00:00Z&limit=100' \
  -H "Authorization: Bearer $CHATWISE_API_KEY"

Keep to fixed while you read the pages of one run, let runs overlap a little, and dedupe by message id. To get messages as they arrive instead, use webhooks.

On this page