Authentication
Create API keys and send them with every request.
Every endpoint requires an API key, except the few marked Public (such as Verify an OTP). Keys are sent in the standard Authorization header.
API keys
API keys are created in the NBM SMS portal, not through the API. Sign in, open API, then choose New API key. Give each key a name you will recognise later — Production, Staging, Billing system — or leave it blank to call it Default.
- Keys start with
nbm_and never expire. - You can have as many keys as you like. Each can be renamed, given its own webhook URL, or deleted on its own.
- Deleting a key takes effect immediately: the next request made with it is refused.
{
"success": true,
"status_code": 201,
"status_text": "Created",
"message": "api key has been created",
"data": {
"id": "1d9b7e3a-2f7e-4b3e-9d0a-8c1a6b2e4f5c",
"name": "Production",
"api_key": "nbm_3f9c1d7a52be48e0a6c4d1f7b29e8a05c6d3f1e7a9b2c4d6e8f0a1b3c5d7e9f1",
"webhook_url": "https://example.co.tz/hooks/nbm-sms"
}
}Using an API key
Send the key as a bearer token on every protected request:
Authorization: Bearer nbm_3f9c1d7a52be48e0a6c4…Keys are not tied to a login session, so there is nothing to refresh and no logout. All requests must use HTTPS; plain HTTP requests are refused so that keys never travel unencrypted.
curl https://sms.nbmbrand.com/api/v1/messages \
-H "Authorization: Bearer $API_KEY"Per-key webhook URL
Each key can carry its own webhook_url, set when the key is created or changed later in the portal. Sender name and purchase callbacks go to the webhook of the key that created that request; message delivery callbacks always go to your account's default webhook. See Webhooks for the full routing rules.
Keeping keys safe
- Server side only. Call the API from your backend. Never ship a key inside a mobile app, browser JavaScript or a desktop installer — anyone can extract it.
- One key per integration. If one system is compromised you can delete its key without touching the others.
- Environment variables or a secret manager, not source code. Add your
.envto.gitignore. - Rotate on suspicion. Create a new key, deploy it, then delete the old one. There is no downtime.
- Watch your usage. Unexpected messages in your history or a falling balance are the first sign of a leaked key.
Authentication errors
A missing or wrong key, or an account that cannot send, returns 401 Unauthorized with a machine-readable error:
| Status | error | When it happens |
|---|---|---|
| 401 | missing_token | No Authorization header, or it isn't a bearer token. |
| 401 | invalid_token | The key doesn't exist, was deleted, or was mistyped. |
| 401 | account_not_found | The key belongs to an account that no longer exists. |
| 401 | account_disabled | The account has been switched off. Contact support. |
| 401 | account_not_verified | The account hasn't finished verification in the portal yet. |
{
"success": false,
"status_code": 401,
"status_text": "Unauthorized",
"message": "invalid api key",
"error": "invalid_token"
}