SMS API Integration Guide for Developers in Tanzania
Send SMS straight from your app, website, or backend. This developer guide walks through API keys, the send endpoint, checking delivery status, and topping up credits.
Written by DARSMS
Updated
To send SMS from your own software in Tanzania with DARSMS, create an API key in the dashboard, then send an HTTPS POST to https://dev.darsms.co.tz/api/v1/integrations/sms/send with the header X-API-Key, a JSON body containing senderId, to (one number or a list) and message, and store the messageIds in the response to check delivery later. The API uses the same prepaid credits and prices as the dashboard (TZS 15 per credit for purchases of 10,000 or more; smaller bundles have higher rates), and creating API keys is free.
SMS API at a glance
- Base URL: https://dev.darsms.co.tz/api/v1
- Authentication: an API key from the dashboard, sent in the X-API-Key header on every request.
- Format: JSON over HTTPS. Every response has success, message and data fields.
- Phone numbers: Tanzanian numbers as 2557XXXXXXXX, +2557XXXXXXXX or 07XXXXXXXX; all are normalised to 255 format and duplicates are removed.
- Message length: up to 1,600 characters. One SMS holds 160 standard characters (70 with emoji or special symbols); longer messages are sent in parts of 153 (or 67) characters, and each part uses one credit per recipient.
- Rate limits: 180 requests per minute per API key; payment endpoints allow 10 per minute. Exceeding a limit returns HTTP 429.
- Delivery status: QUEUED, SENT, DELIVERED, FAILED or REJECTED, checked by message ID. Use status polling; there are no customer delivery webhooks.
- Cost: same per-SMS prices as the dashboard. Credits are used when a message is sent.
1. Create an API key
Register a free DARSMS account, open API Keys in the dashboard and create a key. Treat it like a password: keep it in an environment variable on your server, never ship it in a mobile app or browser code, never commit it to source control, and regenerate or revoke it if it is exposed. Each key can be revoked on its own, so use a separate key for each system.
2. Find your Sender ID
Every account can send with the default DARSMS sender. Once your custom Sender ID is approved, list your approved senders and pass the label as senderId when sending.
curl "https://dev.darsms.co.tz/api/v1/integrations/sender-ids" \
-H "X-API-Key: $DARSMS_API_KEY"3. Send an SMS
Send one message to one or many recipients in a single request. A successful request returns HTTP 202 with a batchId, the number of messages queued, the number of duplicates removed and one messageId per recipient.
curl -X POST "https://dev.darsms.co.tz/api/v1/integrations/sms/send" \
-H "Content-Type: application/json" \
-H "X-API-Key: $DARSMS_API_KEY" \
-d '{
"senderId": "DARSMS",
"to": ["255712345678", "255754321987"],
"message": "Dear James, your payment is due on 5 May."
}'const response = await fetch("https://dev.darsms.co.tz/api/v1/integrations/sms/send", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": process.env.DARSMS_API_KEY,
},
body: JSON.stringify({
senderId: "DARSMS",
to: ["255712345678"],
message: "Your verification code is 482913. It expires in 5 minutes.",
}),
});
const { success, message, data } = await response.json();
if (!success) throw new Error(message);
// data.messageIds: store these to check delivery status laterimport os, requests
response = requests.post(
"https://dev.darsms.co.tz/api/v1/integrations/sms/send",
headers={"X-API-Key": os.environ["DARSMS_API_KEY"]},
json={
"senderId": "DARSMS",
"to": ["255712345678"],
"message": "Your order #1042 has been dispatched.",
},
timeout=15,
)
body = response.json()
if not body["success"]:
raise RuntimeError(body["message"])
message_ids = body["data"]["messageIds"]<?php
$ch = curl_init("https://dev.darsms.co.tz/api/v1/integrations/sms/send");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-Key: " . getenv("DARSMS_API_KEY"),
],
CURLOPT_POSTFIELDS => json_encode([
"senderId" => "DARSMS",
"to" => ["255712345678"],
"message" => "Your school fees balance is TZS 150,000.",
]),
]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
$messageIds = $data["data"]["messageIds"];4. Check delivery status
Look up a message using its messageId. QUEUED means it is awaiting processing, SENT means it was submitted, and DELIVERED means a network delivery report was received. A message can instead become FAILED or REJECTED; inspect any available errorMessage. Reports may arrive later, and delivery is not proof of reading. Poll with increasing gaps rather than in a tight loop.
curl "https://dev.darsms.co.tz/api/v1/integrations/sms/status/MESSAGE_ID" \
-H "X-API-Key: $DARSMS_API_KEY"5. Check your balance and top up
Read your SMS balance with GET /integrations/balance before large sends. To top up from code, call POST /integrations/purchases with quantitySms (minimum 100) and payerPhone. The payer receives a mobile-money prompt to approve, and credits are added automatically once payment is confirmed. GET /integrations/purchases lists purchase history, and POST /integrations/purchases/{purchaseId}/pay re-sends the prompt for a pending, failed or cancelled purchase.
curl -X POST "https://dev.darsms.co.tz/api/v1/integrations/purchases" \
-H "Content-Type: application/json" \
-H "X-API-Key: $DARSMS_API_KEY" \
-d '{ "quantitySms": 1000, "payerPhone": "255712345678" }'6. Handle errors
Errors use success: false with a readable message. Common statuses include 401 for a missing or invalid key, 403 for an inactive account, 422 for schema validation and 429 for rate limits. Invalid input can also return 400. Fix the request before retrying validation or permission errors. Back off after 429. A send request that times out may already have been accepted: reconcile stored records before resubmitting to avoid duplicate messages.
Best practices
- Call the API from your server only, never directly from a browser or mobile app.
- Send many recipients in one request instead of one request per number, to stay well under the rate limit.
- Keep OTP messages short, time-limited and out of your logs.
- Store messageIds with your own records so support can trace any message.
- Watch your balance and top up before it runs out; sends fail when the balance is too low.
- Only send marketing messages to people who agreed to receive them. Opted-out numbers are skipped automatically.
The API documentation has every endpoint with request and response examples in cURL, JavaScript, Python, Java and PHP. Test with a few numbers on different networks, confirm the delivery statuses, then switch your production traffic over.
How do you prevent duplicate sends?
Deduplication within one recipient list does not make a second POST request safe. Keep a record linking each business event, recipient and returned messageId. Mark accepted events in your application and investigate ambiguous timeouts before retrying. Do not assume the SMS endpoint supports a client idempotency header; the documented send payload does not include one.
Production launch checklist
- Test both a local 07XXXXXXXX number and its 255 format, and confirm the normalised recipient.
- Check every response for an error before reading data.messageIds. Add timeouts and transport-error handling to the simplified examples above.
- Budget using the longest personalised message, not only the template text.
- Keep API keys and sensitive message contents out of browser code, support screenshots and routine logs.
Ready to start sending bulk SMS?
Create a free DARSMS account, test with the default sender, and request a custom Sender ID when you are ready.
