Batches
Send to up to 1,000 numbers in one request, with the same text or a personal text each, now or later.
The batch object
| Field | Type | Description |
|---|---|---|
id | string | The batch's id. |
object | string | Always batch. |
livemode | boolean | |
status | string | scheduled (waiting for send_at), held (a check by SemaLink), sending, completed (everything handed over; reports may still come), cancelled, or failed (it couldn't start: say the sender ID was suspended). |
from | string | |
type | string | One of service, promotional. |
text | string or null | The text every message has; null for a personalised batch. |
reference | string or null | |
send_at | string or null | |
created_at | string | |
completed_at | string or null | |
totals | object | |
totals. | integer | Every number asked for. |
totals. | integer | The messages made. |
totals. | integer | Numbers refused at the request (never charged). |
totals. | integer | |
totals. | integer | |
totals. | integer | |
totals. | integer | |
totals. | integer | |
totals. | integer | |
totals. | integer | |
totals. | integer | |
cost | Money | What its messages cost: charged, or set aside until they go. |
refunded | Money | What came back: messages cancelled or refused before reaching the network. |
Example
{
"id": "bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a",
"object": "batch",
"livemode": true,
"status": "sending",
"from": "GREENHILL",
"type": "service",
"text": "Your order 1042 is ready for collection at Greenhill Shop, Moi Avenue. Call 0712 345 678.",
"reference": "december-reminders",
"send_at": null,
"created_at": "2026-12-01T07:30:00.000Z",
"completed_at": null,
"totals": {
"recipients": 3,
"accepted": 2,
"rejected": 1,
"scheduled": 0,
"queued": 2,
"held": 0,
"sent": 0,
"delivered": 0,
"failed": 0,
"expired": 0,
"cancelled": 0
},
"cost": {
"amount": 160,
"currency": "KES",
"display": "KES 1.60"
},
"refunded": {
"amount": 0,
"currency": "KES",
"display": "KES 0.00"
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Send a batch
/v1/batchesScope: messages:sendSends to up to 1,000 numbers: the same text to every number in to, or a personalised text each in messages. Each number is accepted (with its message) or rejected and why (invalid_number, unsupported_country, opted_out, duplicate_in_request, no_price), never charged when rejected. Optional send_at; a scheduled batch can be cancelled.
Headers
| Name | Type | Required | Description |
|---|---|---|---|
Idempotency-Key | string | Optional | Any unique string (a UUID): a retry with the same key and body within 24 hours gets the first answer, with Idempotent-Replayed: true. |
Body
| Name | Type | Required | Description |
|---|---|---|---|
from | string | Required | The sender ID the message comes from: its name (GREENHILL) or its id (snd_...). Live: an approved one. Sandbox: any of yours, whatever its status, or SANDBOX. |
type | string | Optional | service (the default) for transactional messages; promotional for marketing, which adds the opt-out line in Kenya (STOP*456*9*5#) and may only go 07:00-19:00 East Africa Time. |
text | string | Optional | The text every number in to gets. Leave it out with messages. |
to | array of strings | Optional | Up to 1,000 numbers, each sent text. |
messages | array of objects | Optional | Personalised: up to 1,000 {to, text, reference}, each with its own text. Instead of text and to. |
messages | string | Required | |
messages | string | Required | |
messages | string | Optional | Your own reference (an invoice or order number), returned on the message and in its events. Not checked for uniqueness. |
reference | string | Optional | Your reference for the batch, on the batch object. |
send_at | string (time) | Optional | Send later: 5 minutes to 90 days from now (ISO 8601). Leave it out to send now. |
Returns
202 Accepted Accepted: the batch, and each recipient accepted or rejected. A batch object with recipients.
| Field | Type | Description |
|---|---|---|
recipients | array of objects | One per number asked for, in order: accepted (with its message) or rejected and why. |
recipients | integer | Its place in to or messages, from 0. |
recipients | string | The number as you sent it. |
recipients | string or null | In E.164; null when it is not a number. |
recipients | string | One of accepted, rejected. |
recipients | string or null | The message's id when accepted. |
recipients | object or null | |
recipients | string | One of invalid_number, unsupported_country, duplicate_in_request, no_price, opted_out. |
recipients | string |
Errors
| Status | Code | For example |
|---|---|---|
| 400 | parameter_missing | Missing required parameter: from. |
| 400 | parameter_invalid | Invalid send_at: choose a time at least 5 minutes from now, or leave it out to send now. |
| 400 | parameter_unknown | Unknown parameter: sender. |
| 402 | insufficient_balance | The balance is KES 40.00 short of this send's KES 800.00. Top up, then send again. |
| 403 | sending_paused | SemaLink has paused sending on this account. Reply to our email or contact support to sort it out. |
| 403 | account_not_active | This account isn't active yet, so it can't send messages |
| 409 | sending_disabled | Sending is switched off for now, so nothing was sent |
| 422 | message_too_long | The text is 172 characters: one SMS holds 160. Shorten it by 12. |
| 422 | unsupported_characters | The text has characters outside the SMS alphabet: ā (U+0101). Replace or remove them. |
| 422 | sender_id_not_approved | GREENHILL isn't approved to send yet. Send from an approved sender ID. |
| 422 | outside_sending_hours | Promotions to Kenya go between 07:00 and 19:00 East Africa Time. The next opening is 2026-12-02T04:00:00.000Z: send then, or pass it as send_at. |
| 422 | promotional_not_available | Promotions to Tanzania aren't available yet. Send it as a service message if it is one. |
| 422 | daily_limit_reached | Your account can send 1,000 messages a day. You've sent 990 today, so this send of 20 is over by 10. Send it tomorrow, or to fewer people. |
| 422 | content_blocked | SemaLink can't send this message as it is: its content is of a kind we don't carry. Contact support if you think this is wrong. |
| 422 | no_valid_recipients | None of the numbers can be sent to: each is rejected. POST /v1/messages/estimate says why for each. |
Like any POST, it can also answer invalid_json idempotency_key_invalid invalid_api_key key_revoked key_expired scope_missing ip_not_allowed browser_requests_not_allowed api_blocked account_suspended idempotency_key_reused idempotency_key_in_use idempotency_answer_unavailable request_too_large unsupported_media_type rate_limited internal_error request_timeout.
Request
curl https://api.semalink.africa/v1/batches \
-H "Authorization: Bearer $SEMALINK_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"from": "GREENHILL",
"type": "service",
"text": "Your order 1042 is ready for collection at Greenhill Shop, Moi Avenue. Call 0712 345 678.",
"to": [
"+254712345678",
"0722000111",
"0712 34"
],
"reference": "december-reminders"
}'2
3
4
5
6
7
8
9
10
11
12
13
14
15
const response = await fetch('https://api.semalink.africa/v1/batches', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SEMALINK_API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': crypto.randomUUID(), // keep it if you retry
},
body: JSON.stringify({
from: 'GREENHILL',
type: 'service',
text: 'Your order 1042 is ready for collection at Greenhill Shop, Moi Avenue. Call 0712 345 678.',
to: ['+254712345678', '0722000111', '0712 34'],
reference: 'december-reminders',
}),
});
const batch = await response.json();
console.log(response.status, batch);2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import os
import uuid
import requests
response = requests.post(
"https://api.semalink.africa/v1/batches",
headers={
"Authorization": f"Bearer {os.environ['SEMALINK_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()), # keep it if you retry
},
json={
"from": "GREENHILL",
"type": "service",
"text": "Your order 1042 is ready for collection at Greenhill Shop, Moi Avenue. Call 0712 345 678.",
"to": ["+254712345678", "0722000111", "0712 34"],
"reference": "december-reminders",
},
timeout=30,
)
batch = response.json()
print(response.status_code, batch)2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$ch = curl_init('https://api.semalink.africa/v1/batches');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SEMALINK_API_KEY'),
'Content-Type: application/json',
'Idempotency-Key: ' . bin2hex(random_bytes(16)), // keep it if you retry
],
CURLOPT_POSTFIELDS => json_encode([
'from' => 'GREENHILL',
'type' => 'service',
'text' => 'Your order 1042 is ready for collection at Greenhill Shop, Moi Avenue. Call 0712 345 678.',
'to' => ['+254712345678', '0722000111', '0712 34'],
'reference' => 'december-reminders',
]),
]);
$batch = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($batch);2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Response
{
"id": "bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a",
"object": "batch",
"livemode": true,
"status": "sending",
"from": "GREENHILL",
"type": "service",
"text": "Your order 1042 is ready for collection at Greenhill Shop, Moi Avenue. Call 0712 345 678.",
"reference": "december-reminders",
"send_at": null,
"created_at": "2026-12-01T07:30:00.000Z",
"completed_at": null,
"totals": {
"recipients": 3,
"accepted": 2,
"rejected": 1,
"scheduled": 0,
"queued": 2,
"held": 0,
"sent": 0,
"delivered": 0,
"failed": 0,
"expired": 0,
"cancelled": 0
},
"cost": {
"amount": 160,
"currency": "KES",
"display": "KES 1.60"
},
"refunded": {
"amount": 0,
"currency": "KES",
"display": "KES 0.00"
},
"recipients": [
{
"index": 0,
"input": "+254712345678",
"to": "+254712345678",
"status": "accepted",
"message": "msg_3b9f6c2a1d4e4f5a8b7c6d5e4f3a2b1c",
"rejection": null
},
{
"index": 1,
"input": "0722000111",
"to": "+254722000111",
"status": "accepted",
"message": "msg_4c0a7d3b2e5f4a6b9c8d7e6f5a4b3c2d",
"rejection": null
},
{
"index": 2,
"input": "0712 34",
"to": null,
"status": "rejected",
"message": null,
"rejection": {
"code": "invalid_number",
"message": "This number is too short."
}
}
]
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
"error": {
"type": "invalid_request_error",
"code": "message_too_long",
"message": "The text is 172 characters: one SMS holds 160. Shorten it by 12.",
"param": "text",
"characters": 172,
"max_characters": 160,
"doc_url": "https://docs.semalink.africa/errors#message_too_long",
"request_id": "req_5f1d0c2e8a9b4c3d9e7f6a5b4c3d2e1f"
}
}2
3
4
5
6
7
8
9
10
11
12
{
"error": {
"type": "insufficient_balance",
"code": "insufficient_balance",
"message": "The balance is KES 40.00 short of this send's KES 800.00. Top up, then send again.",
"shortfall": {
"amount": 4000,
"currency": "KES",
"display": "KES 40.00"
},
"doc_url": "https://docs.semalink.africa/errors#insufficient_balance",
"request_id": "req_5f1d0c2e8a9b4c3d9e7f6a5b4c3d2e1f"
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
Get a batch
/v1/batches/{id}Scope: messages:readA batch with its messages counted by status, its cost and what came back. Its messages: GET /v1/messages?batch=.
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
id | string | Required | The bat_... id. |
Returns
200 OK The batch. A batch object.
Errors
| Status | Code | For example |
|---|---|---|
| 404 | resource_not_found | There's no batch bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a for this key. |
Like any request, it can also answer invalid_api_key key_revoked key_expired scope_missing ip_not_allowed browser_requests_not_allowed api_blocked account_suspended rate_limited internal_error request_timeout.
Request
curl https://api.semalink.africa/v1/batches/bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a \
-H "Authorization: Bearer $SEMALINK_API_KEY"2
const response = await fetch('https://api.semalink.africa/v1/batches/bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a', {
headers: {
Authorization: `Bearer ${process.env.SEMALINK_API_KEY}`,
},
});
const batch = await response.json();
console.log(response.status, batch);2
3
4
5
6
7
8
import os
import requests
response = requests.get(
"https://api.semalink.africa/v1/batches/bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a",
headers={
"Authorization": f"Bearer {os.environ['SEMALINK_API_KEY']}",
},
timeout=30,
)
batch = response.json()
print(response.status_code, batch)2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$ch = curl_init('https://api.semalink.africa/v1/batches/bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SEMALINK_API_KEY'),
],
]);
$batch = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($batch);2
3
4
5
6
7
8
9
10
11
12
13
14
Response
{
"id": "bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a",
"object": "batch",
"livemode": true,
"status": "sending",
"from": "GREENHILL",
"type": "service",
"text": "Your order 1042 is ready for collection at Greenhill Shop, Moi Avenue. Call 0712 345 678.",
"reference": "december-reminders",
"send_at": null,
"created_at": "2026-12-01T07:30:00.000Z",
"completed_at": null,
"totals": {
"recipients": 3,
"accepted": 2,
"rejected": 1,
"scheduled": 0,
"queued": 2,
"held": 0,
"sent": 0,
"delivered": 0,
"failed": 0,
"expired": 0,
"cancelled": 0
},
"cost": {
"amount": 160,
"currency": "KES",
"display": "KES 1.60"
},
"refunded": {
"amount": 0,
"currency": "KES",
"display": "KES 0.00"
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"error": {
"type": "invalid_request_error",
"code": "resource_not_found",
"message": "There's no batch bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a for this key.",
"param": "id",
"doc_url": "https://docs.semalink.africa/errors#resource_not_found",
"request_id": "req_5f1d0c2e8a9b4c3d9e7f6a5b4c3d2e1f"
}
}2
3
4
5
6
7
8
9
10
{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "This API key isn't one we know. Check it was copied whole, or make a new one in Developer > API keys.",
"doc_url": "https://docs.semalink.africa/errors#invalid_api_key",
"request_id": "req_5f1d0c2e8a9b4c3d9e7f6a5b4c3d2e1f"
}
}2
3
4
5
6
7
8
9
Cancel a scheduled batch
/v1/batches/{id}/cancelScope: messages:sendCancels a batch that hasn't started (scheduled, or held for a check); what was set aside for it comes back at once. A cancelled batch answers as it is.
Headers
| Name | Type | Required | Description |
|---|---|---|---|
Idempotency-Key | string | Optional | Any unique string (a UUID): a retry with the same key and body within 24 hours gets the first answer, with Idempotent-Replayed: true. |
Path parameters
| Name | Type | Required | Description |
|---|---|---|---|
id | string | Required | The bat_... id. |
Returns
200 OK The cancelled batch. A batch object.
Errors
| Status | Code | For example |
|---|---|---|
| 404 | resource_not_found | There's no batch bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a for this key. |
| 409 | batch_not_cancellable | This batch is sending: only a scheduled batch can be cancelled. |
Like any POST, it can also answer invalid_json idempotency_key_invalid invalid_api_key key_revoked key_expired scope_missing ip_not_allowed browser_requests_not_allowed api_blocked account_suspended idempotency_key_reused idempotency_key_in_use idempotency_answer_unavailable request_too_large unsupported_media_type rate_limited internal_error request_timeout.
Request
curl -X POST https://api.semalink.africa/v1/batches/bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a/cancel \
-H "Authorization: Bearer $SEMALINK_API_KEY" \
-H "Idempotency-Key: $(uuidgen)"2
3
const response = await fetch('https://api.semalink.africa/v1/batches/bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a/cancel', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SEMALINK_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(), // keep it if you retry
},
});
const batch = await response.json();
console.log(response.status, batch);2
3
4
5
6
7
8
9
10
import os
import uuid
import requests
response = requests.post(
"https://api.semalink.africa/v1/batches/bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a/cancel",
headers={
"Authorization": f"Bearer {os.environ['SEMALINK_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()), # keep it if you retry
},
timeout=30,
)
batch = response.json()
print(response.status_code, batch)2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
$ch = curl_init('https://api.semalink.africa/v1/batches/bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a/cancel');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SEMALINK_API_KEY'),
'Idempotency-Key: ' . bin2hex(random_bytes(16)), // keep it if you retry
],
]);
$batch = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($batch);2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Response
{
"id": "bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a",
"object": "batch",
"livemode": true,
"status": "sending",
"from": "GREENHILL",
"type": "service",
"text": "Your order 1042 is ready for collection at Greenhill Shop, Moi Avenue. Call 0712 345 678.",
"reference": "december-reminders",
"send_at": null,
"created_at": "2026-12-01T07:30:00.000Z",
"completed_at": null,
"totals": {
"recipients": 3,
"accepted": 2,
"rejected": 1,
"scheduled": 0,
"queued": 2,
"held": 0,
"sent": 0,
"delivered": 0,
"failed": 0,
"expired": 0,
"cancelled": 0
},
"cost": {
"amount": 160,
"currency": "KES",
"display": "KES 1.60"
},
"refunded": {
"amount": 0,
"currency": "KES",
"display": "KES 0.00"
}
}2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"error": {
"type": "invalid_request_error",
"code": "batch_not_cancellable",
"message": "This batch is sending: only a scheduled batch can be cancelled.",
"doc_url": "https://docs.semalink.africa/errors#batch_not_cancellable",
"request_id": "req_5f1d0c2e8a9b4c3d9e7f6a5b4c3d2e1f"
}
}2
3
4
5
6
7
8
9
{
"error": {
"type": "invalid_request_error",
"code": "resource_not_found",
"message": "There's no batch bat_7a1c2e3f4b5d4c6e8f9a0b1c2d3e4f5a for this key.",
"param": "id",
"doc_url": "https://docs.semalink.africa/errors#resource_not_found",
"request_id": "req_5f1d0c2e8a9b4c3d9e7f6a5b4c3d2e1f"
}
}2
3
4
5
6
7
8
9
10