Guide
Pagination
Lists that can grow long come back a page at a time, with a cursor or with a limit and an offset.
Cursor paging: texts#
GET /v1/messages returns every text sent or received, newest first. Ask for up to 200 at a time with limit. Each page has a nextCursor: pass it as cursor to get the next, older page. On the last page nextCursor is empty. Keep the same filters on every page.
const headers = { Authorization: `Bearer ${process.env.SMSBLAST_API_KEY}` };
let cursor = null;
do {
const url = new URL('https://app.smsblast.net/v1/messages');
url.searchParams.set('direction', 'inbound'); // keep the same filters on every page
url.searchParams.set('limit', '200');
if (cursor) url.searchParams.set('cursor', cursor);
const page = await (await fetch(url, { headers })).json();
for (const text of page.messages) console.log(text.createdAt, text.from, text.body);
cursor = page.nextCursor;
} while (cursor);import os
import requests
headers = {"Authorization": f"Bearer {os.environ['SMSBLAST_API_KEY']}"}
params = {"direction": "inbound", "limit": 200} # keep the same filters on every page
while True:
page = requests.get("https://app.smsblast.net/v1/messages", headers=headers, params=params).json()
for text in page["messages"]:
print(text["createdAt"], text["from"], text["body"])
if not page["nextCursor"]:
break
params["cursor"] = page["nextCursor"]New texts arriving while you page do not shift the pages, because the cursor marks a place in time.
Limit and offset: contacts and conversations#
GET /v1/contacts and GET /v1/conversations take limit and offset (how many to skip). Contacts also tell you matching, how many match your filters across all pages. For conversations, stop when a page comes back with fewer than limit.
const headers = { Authorization: `Bearer ${process.env.SMSBLAST_API_KEY}` };
const limit = 500;
for (let offset = 0; ; offset += limit) {
const url = `https://app.smsblast.net/v1/contacts?status=subscribed&limit=${limit}&offset=${offset}`;
const page = await (await fetch(url, { headers })).json();
for (const contact of page.contacts) console.log(contact.phone, contact.first_name);
if (offset + page.contacts.length >= page.matching) break;
}import os
import requests
headers = {"Authorization": f"Bearer {os.environ['SMSBLAST_API_KEY']}"}
limit, offset = 500, 0
while True:
page = requests.get(
"https://app.smsblast.net/v1/contacts",
headers=headers,
params={"status": "subscribed", "limit": limit, "offset": offset},
).json()
for contact in page["contacts"]:
print(contact["phone"], contact["first_name"])
offset += len(page["contacts"])
if offset >= page["matching"]:
breakWhich lists page#
| Endpoint | Paging | limit |
|---|---|---|
GET /v1/messages | Cursor | 1 to 200, default 50 |
GET /v1/messages/inbound | Newest only | 1 to 200, default 50 |
GET /v1/contacts | Limit and offset | 1 to 500, default 50 |
GET /v1/workflows/{id}/runs | Newest only | 1 to 200, default 50 |
GET /v1/conversations | Limit and offset | 1 to 200, default 50 |
GET /v1/webhooks/{id}/deliveries | Newest only | 1 to 100, default 50 |
“Newest only” lists return the most recent entries, up to limit, with no further pages. The other lists return everything, or their most recent entries as each says:
GET /v1/contacts/{id}/consent: Every opt-in and opt-out for one contact, oldest first: your proof of consent.GET /v1/imports: Your 50 most recent import jobs, newest first.GET /v1/lists: All your lists, newest first, with how many contacts each has.GET /v1/segments: All your segments, newest first, each with how many contacts match it now.GET /v1/campaigns: Your 200 most recent campaigns (by when they were sent, or created for drafts), with headline results.GET /v1/workflows: All your workflows, newest first, with counts of people part way through, finished, exited and failed, and texts sent.GET /v1/forms: All your signup forms, newest first, with their views and signups.GET /v1/keywords: Your signup keywords, newest first, with how many people joined with each.GET /v1/webhooks: Your webhook endpoints, oldest first (without their secrets), and every event type you can subscribe to.