SafeEdge SMS API
Send text messages to any Ghana mobile number under your own sender ID, follow every message from your
request to the handset, and buy units, all from your own code.
Base URL: https://api.dinn.safeedgesystems.com. Every request and answer is JSON. Money is in
pesewas (GHS 1.00 = 100), and times are ISO 8601 in UTC, which is Ghana time.
Quickstart
- Get your keys. SafeEdge creates your account and gives you a test key
(
ssk_test_…) and a live key (ssk_live_…). Each is shown to SafeEdge once; keep
it in your server's secrets, never in a web page or an app.
- Check your account and approved sender IDs:
curl https://api.dinn.safeedgesystems.com/v1/account \
-H "Authorization: Bearer $SAFEEDGE_KEY"
- Send with your test key first: nothing is delivered or charged, but you get every answer and
webhook exactly as in live.
curl https://api.dinn.safeedgesystems.com/v1/messages \
-H "Authorization: Bearer $SAFEEDGE_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-1043-shipped" \
-d '{
"sender_id": "ACMESHOP",
"message": "Hello {name}, order {order} has shipped.",
"recipients": [
{ "to": "0241234567", "variables": { "name": "Ama", "order": "1043" }, "reference": "order-1043" }
]
}'
- Follow it: read
GET /v1/messages/{id}, or better, add a
webhook and be told.
Then switch to your live key. Nothing else changes.
Keys and scopes
Send your key on every request: Authorization: Bearer ssk_live_…. SafeEdge stores only a fingerprint
of it, so a lost key cannot be shown again: ask SafeEdge to revoke it and issue a new one.
| Scope | Allows |
send | Sending and dry runs. |
read | Everything you can read: the log, batches, usage, sender IDs (and requesting new ones), webhooks, opt-outs. |
billing | Buying units. |
Give each system the least it needs. A key that sits inside a website or a phone app should have
send only, so it can never read your log or spend money.
Sender IDs
A sender ID is the name your recipients see instead of a number: 3 to 11 letters, digits, spaces,
_ . -, with at least one letter. You can only send under your own approved names
(GET /v1/sender-ids, can_send: true).
GET /v1/sender-ids/check?name=ACMESHOP says whether a name can be had, and why not.
POST /v1/sender-ids/requests asks for one, with what the messages are for. SafeEdge reviews it and
submits it to the network registry; the sender_id.status_changed webhook tells you the outcome.
A name the registry has refused can never be registered again, by anyone. Names of networks,
banks or government bodies are refused outright. Check first, and describe your messages honestly.
Sending messages
POST /v1/messages sends one text, or a personalised text per recipient, to 1 to 1000 numbers.
- Numbers in any usual form:
0241234567, 233241234567, +233 24 123 4567.
- Placeholders:
{name} in message is filled from each recipient's
variables. A recipient missing one is blocked (missing_variable), not sent with a gap.
- Own text: a recipient's
message replaces the shared one.
- Your reference:
reference (up to 100 characters) comes back in the log and in webhooks.
- Idempotency: send an
Idempotency-Key header. If your request times out, send the
same request with the same key again: you get the first answer, and nothing is sent twice.
curl https://api.dinn.safeedgesystems.com/v1/messages \
-H "Authorization: Bearer $SAFEEDGE_KEY" -H "Content-Type: application/json" \
-H "Idempotency-Key: promo-2026-12-06" \
-d '{"sender_id":"ACMESHOP","message":"Hi {name}, 10% off today only.",
"recipients":[{"to":"0241234567","variables":{"name":"Ama"}},
{"to":"0201234567","variables":{"name":"Kofi"}}]}'
const res = await fetch('https://api.dinn.safeedgesystems.com/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SAFEEDGE_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': 'promo-2026-12-06',
},
body: JSON.stringify({
sender_id: 'ACMESHOP',
message: 'Hi {name}, 10% off today only.',
recipients: [
{ to: '0241234567', variables: { name: 'Ama' } },
{ to: '0201234567', variables: { name: 'Kofi' } },
],
}),
});
const { data, error } = await res.json();
if (error) throw new Error(`${error.code}: ${error.message}`);
for (const m of data.messages) console.log(m.to, m.status, m.reason ?? '');
import os, requests
r = requests.post(
"https://api.dinn.safeedgesystems.com/v1/messages",
headers={"Authorization": f"Bearer {os.environ['SAFEEDGE_KEY']}",
"Idempotency-Key": "promo-2026-12-06"},
json={"sender_id": "ACMESHOP", "message": "Hi {name}, 10% off today only.",
"recipients": [{"to": "0241234567", "variables": {"name": "Ama"}},
{"to": "0201234567", "variables": {"name": "Kofi"}}]},
timeout=30,
)
body = r.json()
if "error" in body:
raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")
for m in body["data"]["messages"]:
print(m["to"], m["status"], m.get("reason") or "")
$ch = curl_init('https://api.dinn.safeedgesystems.com/v1/messages');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SAFEEDGE_KEY'),
'Content-Type: application/json',
'Idempotency-Key: promo-2026-12-06',
],
CURLOPT_POSTFIELDS => json_encode([
'sender_id' => 'ACMESHOP',
'message' => 'Hi {name}, 10% off today only.',
'recipients' => [
['to' => '0241234567', 'variables' => ['name' => 'Ama']],
['to' => '0201234567', 'variables' => ['name' => 'Kofi']],
],
]),
]);
$body = json_decode(curl_exec($ch), true);
if (isset($body['error'])) throw new Exception($body['error']['code']);
foreach ($body['data']['messages'] as $m) echo $m['to'], ' ', $m['status'], PHP_EOL;
The answer lists every recipient in the order you sent them, each with its own id,
status (queued, held_for_review or blocked), reason,
pages and units. A blocked recipient is never sent and never charged:
| reason | why |
invalid_number | Not a Ghana mobile number. |
duplicate_recipient | The same number is earlier in this request. |
missing_variable | A {placeholder} had no value. |
empty_message | No text for this recipient. |
message_too_long | Over 10 pages. |
spam_suspected | Matched a content rule; reason_detail says which. |
opted_out | The number is on your opt-out list. |
Dry run: POST /v1/messages/check takes the same body and answers everything a send
would decide (the final text of each message, its pages and units, what would be blocked and why, whether it would
wait for review, and whether you have enough units), with nothing stored, sent or charged.
Pages and units
One unit is one page of text, counted the way the network provider bills:
- Plain text (the standard SMS alphabet): 150 characters a unit, so 1 to 150 characters is 1
unit, 151 to 300 is 2, and so on.
{ } [ ] ~ \ | ^ € count as two characters each.
- Anything else (an emoji, a curly quote, many accented letters) switches the whole text to
70 characters for one unit, then 67 a unit.
At most 10 units a message. The dry run tells you the exact count before you send.
Units are taken when a message is accepted. They come back when a message is blocked in review or refused before
it was sent. A message that reached the network is charged whatever happens next, because the network charges for it.
Message statuses
queued → sending → submitted → sent → delivered
↘ not_delivered | expired | prohibited
| status | meaning | final? |
queued | Accepted, about to go. | |
held_for_review | SafeEdge checks it first (a new account's first sends, or text a content rule flagged, or a suspended account). | |
sending | Being handed to the provider. | |
submitted | With the SMS provider. | |
sent | With the mobile network. | |
delivered | On the handset. | yes |
not_delivered | The network could not deliver it (phone off for too long, number not in use). | yes |
expired | The network gave up after its retry window. | yes |
prohibited | The network refused the content or the sender ID. | yes |
held_by_provider | The provider has not passed it on after 2 hours, perhaps for its content. It may still move on. | |
blocked | Stopped before sending. Never charged. | yes |
failed | Refused before it was sent. Units returned. | yes |
unknown | The provider did not answer. It is never sent again automatically; SafeEdge settles it. | |
not_confirmed | The provider never confirmed it; SafeEdge settled it as charged (it most likely went). | yes |
GET /v1/messages/{id} shows the whole journey: every status, when, why, and who moved
it (api, safeedge_review, safeedge, network, sandbox).
What may be sent
Every account shares the same network routes, so every text is checked before it leaves.
- A new account's first sends wait briefly for SafeEdge to read them (
held_for_review).
- Content rules block phishing patterns (an "account blocked" warning, asking for a PIN or code, "money sent by
mistake", prize scams, shortened or bare-IP links) and hold others for a person to read.
- If more than 20% of an account's messages in an hour are refused by the networks, sending pauses automatically
and SafeEdge gets in touch (the
account.status_changed webhook tells you at once).
Send only to people who agreed to hear from you, say who you are, and honour every request to stop
(opt-outs).
The message log
GET /v1/messages lists everything you sent, newest first, with each number in full and each text
(texts are kept for 90 days). Filter by status (comma separated), batch_id,
sender_id, reference, to (a number), mode,
created_after and created_before.
Lists answer {"data": [...], "pagination": {"has_more": true, "next_cursor": "…"}}. Pass
next_cursor back as ?cursor= for the next page; limit is up to 100.
Also: GET /v1/batches (one per request, counted by status), GET /v1/usage?from=&to=
(per day: sent, delivered, failed, pages, units) and GET /v1/account/units (your units statement).
Webhooks
Instead of asking, be told. Register an HTTPS endpoint on your server and choose events:
curl https://api.dinn.safeedgesystems.com/v1/webhooks \
-H "Authorization: Bearer $SAFEEDGE_KEY" -H "Content-Type: application/json" \
-d '{"url":"https://shop.acme.example/safeedge-hooks",
"events":["message.status_changed","balance.low","purchase.completed"]}'
The answer contains your endpoint's signing secret (whsec_…) once: store
it with your other secrets. Up to 5 endpoints.
| event | when |
message.status_changed | A message moves on after your send was answered (sent, delivered, failed…). |
sender_id.status_changed | One of your sender IDs is approved, refused or removed. |
balance.low | Your units fall below your alert level (PATCH /v1/account, 100 by default). |
purchase.completed / purchase.failed | A purchase is paid, or fails or expires. |
account.status_changed | Your account is suspended or reinstated. |
Each delivery is a POST of:
{
"id": "3f2b6c1e-8a1d-4e4b-9b8f-2c1d0e9a7b6c",
"type": "message.status_changed",
"timestamp": "2026-12-06T10:00:09Z",
"data": { "id": "…", "to": "0241234567", "status": "delivered", "reference": "order-1043", … }
}
- Answer any 2xx within 10 seconds. Do slow work after answering.
- Anything else, a redirect included, is retried after 1 minute, 5 minutes, 30 minutes, 2, 6, 12 and 24 hours.
- The same event can arrive more than once, and events can arrive out of order: use
id to ignore
repeats and data.at to order them.
- An endpoint that fails 50 times in a row with no success for a day is switched off; fix it, then switch it on
with
PATCH /v1/webhooks/{id} {"active": true}.
POST /v1/webhooks/{id}/test sends a test event; GET /v1/webhooks/{id}/deliveries shows every attempt.
Verifying webhooks
Deliveries are signed the Standard Webhooks way, so
their libraries (standardwebhooks on npm, PyPI, Packagist and others) verify them. Or by hand: the
webhook-signature header is v1, and the base64 HMAC-SHA256 of
{webhook-id}.{webhook-timestamp}.{raw body}, keyed with the base64-decoded part of your secret after
whsec_. Use the raw body, before any JSON parsing, and refuse a timestamp more than
5 minutes old.
import crypto from 'node:crypto';
export function verifySafeEdge(secret, headers, rawBody) {
const id = headers['webhook-id'];
const ts = headers['webhook-timestamp'];
if (!id || !ts || Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
const expected = crypto.createHmac('sha256', key).update(`${id}.${ts}.${rawBody}`).digest('base64');
return String(headers['webhook-signature'] ?? '').split(' ').some((s) => {
const [version, sig] = s.split(',');
return version === 'v1' && sig?.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
});
}
import base64, hashlib, hmac, time
def verify_safeedge(secret: str, headers: dict, raw_body: bytes) -> bool:
msg_id, ts = headers.get("webhook-id"), headers.get("webhook-timestamp")
if not msg_id or not ts or abs(time.time() - int(ts)) > 300:
return False
key = base64.b64decode(secret.removeprefix("whsec_"))
expected = base64.b64encode(
hmac.new(key, f"{msg_id}.{ts}.".encode() + raw_body, hashlib.sha256).digest()).decode()
return any(hmac.compare_digest(s.split(",", 1)[1], expected)
for s in headers.get("webhook-signature", "").split() if s.startswith("v1,"))
function verify_safeedge(string $secret, array $h, string $rawBody): bool {
$id = $h['webhook-id'] ?? ''; $ts = $h['webhook-timestamp'] ?? '';
if ($id === '' || $ts === '' || abs(time() - (int) $ts) > 300) return false;
$key = base64_decode(preg_replace('/^whsec_/', '', $secret));
$expected = base64_encode(hash_hmac('sha256', "$id.$ts.$rawBody", $key, true));
foreach (explode(' ', $h['webhook-signature'] ?? '') as $s) {
[$v, $sig] = array_pad(explode(',', $s, 2), 2, '');
if ($v === 'v1' && hash_equals($expected, $sig)) return true;
}
return false;
}
Check your code against the standard's own example: secret whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw,
id msg_p5jXN8AQM9LWM0D4loKWxJek, timestamp 1614265330, body
{"test": 2432232314} must give v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=
(skip the age check for this test).
Buying units
Needs a key with the billing scope. GET /v1/packages lists what you can buy; then
POST /v1/purchases with package_id and a method:
checkout: answers a checkout_url on Paystack. The payer pays by card
or mobile money there (Paystack handles the prompt and any code); add callback_url to bring them back
to your site. Paystack's charge is added on top (surcharge_pesewas). An unpaid checkout expires
after 24 hours.
send_and_claim: answers a merchant number, an amount and a code. Pay
exactly that amount by mobile money to that number and quote the code as the reference. No charge on top.
The units arrive the moment the payment is confirmed, with a purchase.completed webhook;
GET /v1/purchases/{id} also shows it. At most 5 unpaid purchases at once.
Opt-outs
When someone asks you to stop, add their number: every later send to it is blocked (opted_out) and
never charged. The list is yours alone.
POST /v1/opt-outs {"to": "0241234567", "note": "Replied STOP by email"}
POST /v1/opt-outs/remove {"to": "0241234567"}
GET /v1/opt-outs
Numbers go in the body, never in a URL, so they never land in a web server's logs.
Errors and limits
A failure is {"error": {"code": "insufficient_units", "message": "…"}} with the HTTP status that fits.
Act on the code; the message is for people. Every answer carries X-Request-Id.
| HTTP | means | do |
| 400, 413, 422 | The request is wrong. | Fix it; retrying the same request will not help. |
| 401, 403 | The key is missing, wrong, revoked, lacks the scope, or the account is suspended. | Check the key; contact SafeEdge. |
| 402 | Not enough units. | Buy a package. |
| 404, 405 | No such thing on your account, or the wrong method. | |
| 409 | A conflict (an Idempotency-Key reused for a different request). | |
| 429 | A limit. | Wait Retry-After seconds. |
| 500, 503 | Our side. | Retry with the same Idempotency-Key, with back-off. |
Every code is listed in the API reference (Error). Limits: reading, 120 requests a
minute per key; sending, your account's messages per minute and per 24 hours (see GET /v1/account);
5 sender ID requests a day.
Test mode
A ssk_test_ key behaves exactly like a live one (checks, answers, statuses, webhooks) but goes to the
provider's sandbox: nothing is delivered and nothing is charged. A test message moves to delivered
with the source sandbox. Test sends count towards your limits and are reported apart in usage.
Support
Email support.dinndata@gmail.com or WhatsApp 0595093277. Quote the
X-Request-Id of the answer you are asking about, never your API key.