Concepts

Pagination

GET /v1/messages is paginated with limit (1 to 100, default 25) and position (an offset, default 0). Follow next_position until it is null.

TuskMail API: Pagination

What does a list response look like?

JSON
{
  "data": [ /* message objects */ ],
  "total": 140,
  "limit": 25,
  "position": 0,
  "next_position": 25
}
NameTypeDescription
dataarrayThe messages on this page.
totalintegerTotal messages matching the filters.
limit / positionintegerEcho of the page size and offset you requested.
next_positioninteger | nullPass as position to get the next page. null on the last page.

How do I page through everything?

Node.js
let position = 0;
while (position !== null) {
  const res = await fetch(`https://api.tuskmail.africa/v1/messages?folder=inbox&limit=100&position=${position}`, { headers });
  const page = await res.json();
  for (const m of page.data) console.log(m.subject);
  position = page.next_position;
}

Remember the rate limit: 60 requests per minute.