Webhooks
Get delivery, sender name and purchase updates pushed to your server.
Instead of polling, give NBM SMS a URL on your server and it will POST a small JSON message whenever something you care about changes. Every callback has the same shape — an entity saying what changed, its id and the new status.
Registering a webhook URL
Webhook URLs are set in the portal (API section), not through the API. There are two kinds:
| Setting | Receives |
|---|---|
| Account default webhook | Every message delivery callback, whichever key sent the message. Also the fallback for sender name and purchase callbacks. |
| Per-key webhook | Sender name and purchase callbacks for requests made with that key. If the key has none, the account default is used. |
Sender name requests and purchases made from the portal (not the API) always use the account default.
How callbacks are delivered
POSTwithContent-Type: application/json, to an HTTPS URL.- Reply with any
2xxwithin 10 seconds. Do slow work after replying, or in a queue. - A failed or slow delivery is logged but not retried.
Message status callback
Sent when a message reaches delivered or undelivered. Earlier steps (sending, sent…) aren't pushed — poll List messages if you need them.
entitystringrequiredmessages.iduuidrequiredstatusstringrequireddelivered or undelivered.{
"entity": "messages",
"id": "6b2f6e2a-4b0e-4e9a-9a2e-1a2b3c4d5e6f",
"status": "delivered"
}Sender name status callback
Sent when a sender name you requested is approved, declined, disabled or enabled again.
entitystringrequiredsender-names.iduuidrequiredstatusstringrequiredrequested, approved or declined.is_disabledbooleanrequired{
"entity": "sender-names",
"id": "9a1c1e2a-4b0e-4e9a-9a2e-1a2b3c4d5e6f",
"status": "approved",
"is_disabled": false
}Purchase status callback
Sent when a credit purchase is paid.
entitystringrequiredpurchases.iduuidrequiredstatusstringrequiredpending or paid.{
"entity": "purchases",
"id": "3d4e6e2a-4b0e-4e9a-9a2e-1a2b3c4d5e6f",
"status": "paid"
}Receiving callbacks
Minimal receivers that reply fast and then fetch the real record:
import express from "express";
const app = express();
app.use(express.json());
app.post("/hooks/nbm-sms", async (req, res) => {
// 1. Answer straight away: NBM waits at most 10 seconds.
res.sendStatus(204);
// 2. Then do the work.
const { entity, id, status } = req.body;
if (entity === "messages") {
// Fetch the message to get the full, current record.
const r = await fetch(`https://sms.nbmbrand.com/api/v1/messages/${id}`, {
headers: { Authorization: `Bearer ${process.env.NBM_SMS_API_KEY}` },
});
const { data } = await r.json();
await markOrderNotification(data.id, data.status); // your code
}
});
app.listen(3000);<?php
// routes/web.php (Laravel) — exclude this path from CSRF protection.
Route::post('/hooks/nbm-sms', function (Illuminate\Http\Request $request) {
$entity = $request->input('entity');
$id = $request->input('id');
$status = $request->input('status');
// Queue the work so the response goes back immediately.
dispatch(new App\Jobs\HandleNbmSmsCallback($entity, $id, $status));
return response()->noContent(); // 204
});from flask import Flask, request
import os, requests
app = Flask(__name__)
@app.post("/hooks/nbm-sms")
def nbm_sms():
event = request.get_json(force=True)
if event.get("entity") == "messages":
r = requests.get(
f"https://sms.nbmbrand.com/api/v1/messages/{event['id']}",
headers={"Authorization": f"Bearer {os.environ['NBM_SMS_API_KEY']}"},
timeout=10,
)
message = r.json()["data"]
# ... update your records with message["status"]
return "", 204