Skip to main content

API Reference

Complete reference documentation for all AfriRoute APIs. Each API provides RESTful endpoints with JSON payloads for seamless integration.


🌐 Base URLs​

EnvironmentURL
Productionhttps://api.afriroute.ai
Sandboxhttps://sandbox.api.afriroute.ai

πŸ”‘ Authentication​

All API requests require authentication via one of these methods:

-H "Authorization: Bearer $AFRIROUTE_API_KEY"

JWT Token​

-H "Authorization: Bearer your_jwt_token"

Learn more about authentication β†’


πŸ“‘ Available APIs​

1. SMS API​

Send and receive SMS messages across Africa.

  • Send SMS: POST /v1/sms/send
  • Get Status: GET /v1/sms/{message_id}
  • Send Bulk SMS: POST /v1/sms/bulk
  • Get Balance: GET /v1/sms/balance

View SMS API Documentation β†’


2. WhatsApp API​

Send rich media messages via WhatsApp Business API.

  • Send Message: POST /v1/whatsapp/send
  • Send Template: POST /v1/whatsapp/template
  • Upload Media: POST /v1/whatsapp/media
  • Get Message Status: GET /v1/whatsapp/{message_id}

View WhatsApp API Documentation β†’


3. Email API​

Send transactional and marketing emails.

  • Send Email: POST /v1/email/send
  • Send Bulk Email: POST /v1/email/bulk
  • Get Status: GET /v1/email/{message_id}
  • Manage Templates: POST /v1/email/templates

View Email API Documentation β†’


4. Voice API​

Make and receive voice calls programmatically.

  • Make Call: POST /v1/voice/call
  • Get Call Status: GET /v1/voice/{call_id}
  • Hangup Call: POST /v1/voice/{call_id}/hangup
  • Play Audio: POST /v1/voice/{call_id}/play

View Voice API Documentation β†’


5. USSD API​

Build interactive USSD applications.

  • Initiate Session: POST /v1/ussd/initiate
  • Handle Response: POST /v1/ussd/callback
  • End Session: POST /v1/ussd/{session_id}/end

View USSD API Documentation β†’


6. Payments API​

Accept mobile money payments across Africa.

  • Initiate Payment: POST /v1/payments/charge
  • Check Status: GET /v1/payments/{transaction_id}
  • Refund: POST /v1/payments/{transaction_id}/refund
  • Payment Methods: GET /v1/payments/methods

View Payments API Documentation β†’


7. Webhooks​

Receive real-time notifications for events.

  • Configure Webhook: POST /v1/webhooks
  • List Webhooks: GET /v1/webhooks
  • Delete Webhook: DELETE /v1/webhooks/{webhook_id}
  • Test Webhook: POST /v1/webhooks/{webhook_id}/test

View Webhooks Documentation β†’


πŸ“Š Common Request/Response Patterns​

Standard Success Response​

{
"success": true,
"data": {
"message_id": "msg_abc123",
"status": "queued",
"timestamp": "2025-12-10T12:30:00Z"
}
}

Standard Error Response​

{
"success": false,
"error": {
"code": "INVALID_REQUEST",
"message": "Invalid phone number format",
"details": "Phone number must be in E.164 format",
"request_id": "req_xyz789",
"timestamp": "2025-12-10T12:30:00Z"
}
}

🚨 HTTP Status Codes​

CodeStatusDescription
200OKRequest successful
201CreatedResource created successfully
400Bad RequestInvalid request parameters
401UnauthorizedAuthentication failed
403ForbiddenInsufficient permissions
404Not FoundResource not found
409ConflictResource conflict
422Unprocessable EntityValidation failed
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer error
503Service UnavailableService temporarily unavailable

⚑ Rate Limits​

Rate limits vary by plan and API:

PlanSMS/EmailWhatsAppVoicePayments
Free10/min5/min2/min5/min
Starter100/min50/min20/min50/min
Growth500/min200/min100/min200/min
EnterpriseCustomCustomCustomCustom

Rate Limit Headers​

Every response includes rate limit information:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 87
X-RateLimit-Reset: 1702317260

Handling Rate Limits​

async function sendWithRetry(payload, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await fetch('https://api.afriroute.ai/api/v1/sms/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': apiKey
},
body: JSON.stringify(payload)
});

if (response.status === 429) {
const retryAfter = response.headers.get('Retry-After') || 60;
console.log(`Rate limited. Retrying after ${retryAfter}s`);
await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
continue;
}

return await response.json();
} catch (error) {
if (i === maxRetries - 1) throw error;
}
}
}

πŸ”’ Security​

HTTPS Only​

All API requests must use HTTPS. HTTP requests are rejected.

API Key Security​

  • βœ… Store keys securely (environment variables)
  • βœ… Rotate keys regularly (every 90 days)
  • βœ… Use separate keys for different environments
  • ❌ Never commit keys to version control
  • ❌ Never expose keys in client-side code

Request Signing (For Webhooks)​

All webhooks include an X-AfriRoute-Signature header for verification.

Learn more about webhook security β†’


πŸ“± Phone Number Format​

All phone numbers must be in E.164 format:

+[country_code][number]

Examples​

CountryFormatExample
πŸ‡ͺπŸ‡Ή Ethiopia+251XXXXXXXXX+251911234567
πŸ‡°πŸ‡ͺ Kenya+254XXXXXXXXX+254712345678
πŸ‡³πŸ‡¬ Nigeria+234XXXXXXXXXX+2348012345678
πŸ‡¬πŸ‡­ Ghana+233XXXXXXXXX+233241234567
πŸ‡ΏπŸ‡¦ South Africa+27XXXXXXXXX+27821234567

Validation​

function validateE164(phoneNumber) {
const e164Regex = /^\+[1-9]\d{1,14}$/;
return e164Regex.test(phoneNumber);
}

// Usage
console.log(validateE164('+251911234567')); // true
console.log(validateE164('0911234567')); // false

🌍 Country Coverage​

AfriRoute supports messaging in 54+ African countries:

RegionCountriesSMSWhatsAppVoice
East AfricaET, KE, TZ, UG, RW, BIβœ…βœ…βœ…
West AfricaNG, GH, SN, CI, BF, MLβœ…βœ…βœ…
Southern AfricaZA, ZW, ZM, MW, MZ, BWβœ…βœ…βœ…
North AfricaEG, MA, TN, DZ, LYβœ…βœ…βš οΈ
Central AfricaCM, CD, CG, GA, TD, CFβœ…βœ…βš οΈ

View complete coverage β†’


πŸ“¦ SDKs & Libraries​

Official SDKs for popular programming languages:

LanguagePackageDocumentation
JavaScript/Node.jsnpm install afrirouteDocs β†’
Pythonpip install afrirouteDocs β†’
C#dotnet add package AfriRouteDocs β†’
Gogo get afriroute.ai/sdk-goDocs β†’

Quick Start with SDK​

// JavaScript
const AfriRoute = require('afriroute');
const client = new AfriRoute('$AFRIROUTE_API_KEY');

await client.sms.send({
to: '+251911234567',
from: 'AFRIROUTE',
text: 'Hello from AfriRoute!'
});
# Python
from afriroute import AfriRoute

client = AfriRoute('$AFRIROUTE_API_KEY')

client.sms.send(
to='+251911234567',
from_='AFRIROUTE',
text='Hello from AfriRoute!'
)

πŸ§ͺ Testing​

Sandbox Environment​

Test your integration without charges:

# Sandbox
https://sandbox.api.afriroute.ai

# Use test API key
$AFRIROUTE_API_KEY

Learn more about sandbox β†’

Postman Collection​

Import our official Postman collection:

Download Collection β†’


πŸ“„ API Versioning​

The API is versioned via URL path:

Current version: v1
https://api.afriroute.ai/api/v1/...

Version Policy​

  • Breaking changes: New major version (v2, v3, etc.)
  • Non-breaking changes: Same version
  • Deprecation notice: 6 months before removal
  • Support: Previous version supported for 12 months

πŸ†˜ Support​


πŸ“š Next Steps​

Explore detailed documentation for each API:

Or start with our Getting Started Guide β†’