API Docs

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.
Key created in the portal
201 Created
{
  "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:

Header
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.

Authenticated request
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 .env to .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:

401 error codes
StatuserrorWhen it happens
401missing_tokenNo Authorization header, or it isn't a bearer token.
401invalid_tokenThe key doesn't exist, was deleted, or was mistyped.
401account_not_foundThe key belongs to an account that no longer exists.
401account_disabledThe account has been switched off. Contact support.
401account_not_verifiedThe account hasn't finished verification in the portal yet.
Response
401 Unauthorized
{
  "success": false,
  "status_code": 401,
  "status_text": "Unauthorized",
  "message": "invalid api key",
  "error": "invalid_token"
}