Paging through results
A list endpoint answers in one of three ways: a page and a cursor for the next, a page by limit and offset, or the whole list at once.
Cursor
These answer with entries and nextCursor:
| List | Endpoint | limit |
|---|---|---|
| Messages | GET / | Up to 200, 50 if left out |
| Campaigns | GET / | Up to 100, 25 if left out |
| A campaign's messages | GET / | Up to 500, 100 if left out |
| Recurring campaigns | GET / | Up to 100, 25 if left out |
| Contacts | GET / | Up to 200, 50 if left out |
| Activity | GET / | Up to 100, 50 if left out |
Ask for the first page:
curl "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/messages?limit=20" \
-H "Authorization: Bearer $CODELIA_API_KEY"const response = await fetch(
`https://api.sms.codelia.studio/v1/organizations/${process.env.CODELIA_ACCOUNT_ID}/messages?limit=20`,
{
headers: {
Authorization: `Bearer ${process.env.CODELIA_API_KEY}`,
},
},
);
console.log(response.status);
console.log(JSON.stringify(await response.json(), null, 2));Then pass the answer's nextCursor back as cursor, with the same filters, and repeat until nextCursor is null. A cursor belongs to the list it came from. On the campaign list, a cursor from another view is refused with 400 and invalid_.
Offset
These answer with an array, and page by limit and offset:
| List | Endpoint | limit |
|---|---|---|
| Opt-outs | GET / | Up to 1,000, 200 if left out |
| A list's members | GET / | Up to 500, 200 if left out |
offset is how many to skip, and 0 if you leave it out. This asks for the second page of 100:
curl "https://api.sms.codelia.studio/v1/organizations/$CODELIA_ACCOUNT_ID/opt-outs?limit=100&offset=100" \
-H "Authorization: Bearer $CODELIA_API_KEY"const response = await fetch(
`https://api.sms.codelia.studio/v1/organizations/${process.env.CODELIA_ACCOUNT_ID}/opt-outs?limit=100&offset=100`,
{
headers: {
Authorization: `Bearer ${process.env.CODELIA_API_KEY}`,
},
},
);
console.log(response.status);
console.log(JSON.stringify(await response.json(), null, 2));Add limit to offset for the next page. A page with fewer entries than limit is the last.
The whole list
These come back whole, with no paging:
- your lists,
GET /;organizations/ {accountId}/ contact-lists - your sender names,
GET /;organizations/ {accountId}/ sender-ids - your webhook endpoints,
GET /.organizations/ {accountId}/ webhook-endpoints
An endpoint's deliveries, GET /, are the most recent ones, newest first: up to limit, which is up to 500, and 50 if you leave it out. There's no next page.
With the TypeScript SDK
list() gets one page, and iterate() gets every page for you. See TypeScript SDK.