Pagination
Endpoints that return lists, such as GET /v1/messages, return one page at a time, newest first. (The messages above are shortened: each is the whole message object.)
A page
{
"object": "list",
"data": [
{ "id": "msg_4c0a7d3b2e5f4a6b9c8d7e6f5a4b3c2d", "object": "message", "status": "failed", "to": "+254733123456" },
{ "id": "msg_3b9f6c2a1d4e4f5a8b7c6d5e4f3a2b1c", "object": "message", "status": "failed", "to": "+254712345678" }
],
"has_more": true,
"next_cursor": "msg_3b9f6c2a1d4e4f5a8b7c6d5e4f3a2b1c"
}2
3
4
5
6
7
8
9
| Field | Meaning |
|---|---|
data | The items on this page |
has_more | true if there are more items after this page |
next_cursor | Pass it as starting_after to get the next page; null on the last page |
Parameters
| Parameter | Meaning |
|---|---|
limit | How many items per page, 1 to 100. Default 20. |
starting_after | The next_cursor from the page before. Leave it out for the first page. |
Keep the same filters (such as status, batch or created[gte]) on every page. Pages are cursor-based, so new messages arriving while you read don't make you skip or repeat items. GET /v1/messages lists every message of your organisation, the ones sent from the app included; a test key lists the sandbox's.
Read every page
This reads every failed message from one batch:
# First page
curl "https://api.semalink.africa/v1/messages?batch=bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a&status=failed&limit=100" \
-H "Authorization: Bearer $SEMALINK_API_KEY"
# Next page: pass next_cursor as starting_after
curl "https://api.semalink.africa/v1/messages?batch=bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a&status=failed&limit=100&starting_after=msg_3b9f6c2a1d4e4f5a8b7c6d5e4f3a2b1c" \
-H "Authorization: Bearer $SEMALINK_API_KEY"2
3
4
5
6
7
async function* listMessages(filters) {
let cursor = null;
do {
const params = new URLSearchParams({ ...filters, limit: '100' });
if (cursor) params.set('starting_after', cursor);
const response = await fetch(`https://api.semalink.africa/v1/messages?${params}`, {
headers: { Authorization: `Bearer ${process.env.SEMALINK_API_KEY}` },
});
const page = await response.json();
yield* page.data;
cursor = page.has_more ? page.next_cursor : null;
} while (cursor);
}
for await (const message of listMessages({ batch: 'bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a', status: 'failed' })) {
console.log(message.to, message.failure?.code);
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import os
import requests
def list_messages(**filters):
params = {**filters, "limit": 100}
while True:
response = requests.get(
"https://api.semalink.africa/v1/messages",
headers={"Authorization": f"Bearer {os.environ['SEMALINK_API_KEY']}"},
params=params,
timeout=30,
)
page = response.json()
yield from page["data"]
if not page["has_more"]:
break
params["starting_after"] = page["next_cursor"]
for message in list_messages(batch="bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a", status="failed"):
print(message["to"], (message.get("failure") or {}).get("code"))2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
function listMessages(array $filters): Generator
{
$params = $filters + ['limit' => 100];
do {
$ch = curl_init('https://api.semalink.africa/v1/messages?' . http_build_query($params));
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('SEMALINK_API_KEY')],
]);
$page = json_decode(curl_exec($ch), true);
curl_close($ch);
yield from $page['data'];
$params['starting_after'] = $page['next_cursor'];
} while ($page['has_more']);
}
foreach (listMessages(['batch' => 'bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a', 'status' => 'failed']) as $message) {
echo $message['to'], ' ', $message['failure']['code'] ?? '', PHP_EOL;
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Filtering by time
The parameters are literally named created[gte] and created[lte], and take ISO 8601 times. In a URL the brackets are encoded: created%5Bgte%5D=2026-12-01T00:00:00Z. URLSearchParams, requests and http_build_query do this for you (in curl, add -g or encode them yourself).