HTTP API
The HTTP API is the interface of a self-hosted server. A client that does not embed the library uses these routes. SMSBridge.send() does not call this API.
The server listens on port 8080 unless PORT is set.
Authentication
/v1/sms/* requires:
Authorization: Bearer <profile API key>The API key is printed on the first start of the server. See Self-hosting.
A missing header, a header that is not a bearer token, or an unknown key returns status 401 and { "error": string, "code": "UNAUTHORIZED" }. The error string is "Missing or invalid Authorization header" when the header is absent or is not a bearer token, and "Invalid API key" when the token does not match a profile.
The other routes on this page do not read that header.
metadata is not accepted on these routes. Per-message vendor fields are available only to SMSBridge.send().
Routes
The process registers every path in this table. The dashboard UI is mounted at /portal and calls the same handlers with that prefix. /api/v1/providers is the exception: the UI calls /portal/api/providers.
| Method | Path | Also at |
|---|---|---|
GET | /health | |
GET | /metrics | |
POST | /v1/sms/send | |
GET | /v1/sms/:id/status | |
GET | /api/v1/providers | /portal/api/providers |
PATCH | /api/v1/providers/:id | /portal/api/providers/:id |
GET | /api/portal/stats | /portal/api/portal/stats |
GET | /api/portal/queue-status | /portal/api/portal/queue-status |
GET | /api/portal/queue-jobs | /portal/api/portal/queue-jobs |
POST | /api/portal/test-send | /portal/api/portal/test-send |
GET | /api/portal/messages | /portal/api/portal/messages |
GET | /api/portal/messages/:id/logs | /portal/api/portal/messages/:id/logs |
GET | /api/portal/providers | /portal/api/portal/providers |
POST | /api/portal/providers | /portal/api/portal/providers |
PATCH | /api/portal/providers/:id | /portal/api/portal/providers/:id |
DELETE | /api/portal/providers/:id | /portal/api/portal/providers/:id |
GET | /api/portal/profiles | /portal/api/portal/profiles |
POST | /api/portal/profiles | /portal/api/portal/profiles |
PATCH | /api/portal/profiles/:id | /portal/api/portal/profiles/:id |
DELETE | /api/portal/profiles/:id | /portal/api/portal/profiles/:id |
GET | /api/portal/profile-providers | /portal/api/portal/profile-providers |
POST | /api/portal/profile-providers | /portal/api/portal/profile-providers |
DELETE | /api/portal/profile-providers/:id | /portal/api/portal/profile-providers/:id |
GET | /api/portal/sender-ids | /portal/api/portal/sender-ids |
POST | /api/portal/sender-ids | /portal/api/portal/sender-ids |
DELETE | /api/portal/sender-ids/:id | /portal/api/portal/sender-ids/:id |
POST | /sandbox/bulksmsbd/smsapi | /portal/api/sandbox/bulksmsbd/smsapi |
POST | /sandbox/bulksmsbd/getBalanceApi | /portal/api/sandbox/bulksmsbd/getBalanceApi |
POST | /sandbox/greenweb/g_api.php | /portal/api/sandbox/greenweb/g_api.php |
GET | /sandbox/greenweb/g_api.php | /portal/api/sandbox/greenweb/g_api.php |
GET | /sandbox/messages | /portal/api/sandbox/messages |
GET | /sandbox/settings | /portal/api/sandbox/settings |
POST | /sandbox/settings/:providerType | /portal/api/sandbox/settings/:providerType |
DELETE | /sandbox/messages | /portal/api/sandbox/messages |
GET | /portal/ | Dashboard UI. /portal redirects to /portal/. |
GET | /portal/* | A file from the dashboard build, or index.html when the path has no file extension. |
JSON error bodies from the SMS routes are { "error": string, "code": string }. A handler that throws an unexpected error returns status 500 and { "error": "Gateway Error", "code": "INTERNAL_ERROR" }.
GET /health
Status 200: { "status": "ok" }.
GET /metrics
Status 200. Body is Prometheus text. Content-Type is the Prometheus content type.
POST /v1/sms/send
Enqueue a message for delivery. Requires a profile API key.
Request body
Content-Type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
recipient | string | yes | Recipient number. Length 10 to 20. |
body | string | yes | Message text. Length 1 to 1600. |
priority | string | no | low, normal, high, or critical. Default: normal. |
routingHint | string | no | Provider id, name, or type. The named provider has to be a candidate for the profile. |
isMasked | boolean | no | When true, only a provider with a masked sender ID can be selected. Default: false. |
curl -sS -X POST http://localhost:8080/v1/sms/send \
-H "Authorization: Bearer $SMS_BRIDGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"recipient":"01700000000","body":"Your code is 123456"}'Response
Status 202:
| Field | Type | Description |
|---|---|---|
messageId | string | Id of the stored message. |
status | string | queued. |
Errors
| Status | code | Condition |
|---|---|---|
400 | VALIDATION_ERROR | recipient, body, or priority is invalid. |
401 | UNAUTHORIZED | The profile API key is missing or unknown. |
GET /v1/sms/:id/status
Return one stored message. :id is the messageId from POST /v1/sms/send. Requires a profile API key.
Response
Status 200:
| Field | Type | Description |
|---|---|---|
id | string | Message id. |
status | string | pending, queued, sent, failed, delivered, or dead. |
recipient | string | Recipient passed at creation. |
providerId | string or null | Provider that accepted the message, after one has been selected. |
retryCount | number | Delivery attempts recorded on the message. |
createdAt | string | Creation time. |
updatedAt | string | Last update time. |
Errors
| Status | code | Condition |
|---|---|---|
404 | NOT_FOUND | No message exists with :id. |
401 | UNAUTHORIZED | The profile API key is missing or unknown. |
GET /api/v1/providers
List the providers loaded from the environment or from configs.yaml.
Status 200. Each element:
| Field | Type | Description |
|---|---|---|
id | string | Provider id, such as bulksmsbd. |
displayName | string | Label stored for the dashboard. |
enabled | boolean | When false, routing skips the provider. |
priority | number | Lower numbers are tried first under priority ordering. |
configured | boolean | true when credentials for id are loaded. |
senderIds | string[] | Sender IDs from the configuration. |
balance | number | Result of checkBalance(), or 0 when the call fails. |
createdAt | string | |
updatedAt | string |
PATCH /api/v1/providers/:id
Change enablement or priority. :id is the provider id.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
enabled | boolean | no | |
priority | number | no |
At least one field is required. Status 400 and { "error": "No valid update fields provided" } when the body has neither. Status 400 and { "error": "Provider ID is required" } when :id is empty. An unknown id returns status 404.
Status 200 returns the updated row: id, displayName, enabled, priority, createdAt, updatedAt.
Portal
The paths below are also available under /portal/api/portal. Responses are the stored rows. Timestamps are ISO strings. Boolean columns are JSON booleans.
GET /api/portal/stats
Status 200:
| Field | Type | Description |
|---|---|---|
total | number | Messages stored. |
sent | number | Messages with status sent. |
failed | number | Messages with status failed. |
pending | number | Messages with status pending. |
activeProviders | number | Rows in providers with isActive true. |
todayCount | number | Messages created since local midnight. |
sandboxCount | number | Messages captured by the sandbox. |
GET /api/portal/messages
Query limit. Default 50. Status 200: an array of message rows.
| Field | Type |
|---|---|
id, profileId, recipient, body | string |
priority | low, normal, high, or critical |
routingHint, providerId, providerName, senderId | string or null |
isMasked | boolean |
status | pending, queued, sent, failed, delivered, or dead |
routingStrategy, pivotedFrom, responseBody | string or null |
cost | number or null |
retryCount, latency | number |
queuedAt, dequeuedAt, processedAt, createdAt, updatedAt | string or null |
GET /api/portal/messages/:id/logs
Status 200: an array of { "id", "messageId", "event", "detail", "createdAt" }, newest first.
GET /api/portal/queue-status
Status 200:
| Field | Type | Description |
|---|---|---|
counts.active | number | |
counts.waiting | number | Jobs waiting in Redis. |
counts.failed | number | |
counts.completed | number | |
counts.delayed | number | |
activeJobs | array | Up to 50 jobs. See the job fields below. |
waitingJobs | array | Up to 50 jobs. |
failedJobs | array | Up to 50 jobs. |
GET /api/portal/queue-jobs
| Query | Default | Description |
|---|---|---|
types | active | Comma-separated BullMQ states, such as wait,failed. |
start | 0 | First index. |
end | 49 | Last index. |
Status 200: an array of jobs.
| Field | Type |
|---|---|
id | string |
name | string |
data | object |
status | string |
failedReason | string, when the job failed |
stacktrace | string[], when present |
processedOn, finishedOn | number, epoch milliseconds, when present |
timestamp | number |
POST /api/portal/test-send
Enqueue a message the same way POST /v1/sms/send does. This route does not check the profile API key. The caller supplies profileId.
| Field | Type | Required |
|---|---|---|
recipient | string | yes |
body | string | yes |
profileId | string | yes |
priority | string | no. Default normal. |
Status 200: { "messageId": string, "status": "queued" }.
Providers, profiles, and sender IDs
GET /api/portal/providers returns the rows in the providers table. This is separate from GET /api/v1/providers, which returns the providers loaded from configuration.
POST /api/portal/providers inserts a row. Status 201.
| Field | Type | Required |
|---|---|---|
name | string | yes |
type | string | yes. bulksmsbd or greenweb. |
baseUrl | string | yes |
apiKey | string | yes |
apiSecret | string | no |
isActive | boolean | no. Default true. |
realBalance | number | no. Default 0. |
PATCH /api/portal/providers/:id writes the JSON fields onto that row. DELETE /api/portal/providers/:id returns { "success": true }.
GET /api/portal/profiles returns profile rows: id, name, apiKey, routingStrategy, routingConfig, fixedProviderId, createdAt.
POST /api/portal/profiles inserts a profile. Status 201. apiKey is generated as sb_ plus 32 hex characters when the body omits it. routingStrategy defaults to priority_failover. routingConfig defaults to "{}".
| Field | Type | Required |
|---|---|---|
name | string | yes |
apiKey | string | no |
routingStrategy | string | no. priority_failover, weighted_distribution, health_aware, rule_based, fixed, or priority. |
routingConfig | string | no. JSON text. |
fixedProviderId | string | no |
PATCH /api/portal/profiles/:id updates the row. DELETE /api/portal/profiles/:id returns { "success": true }.
GET /api/portal/sender-ids returns { "id", "providerId", "senderId", "isMasked", "isActive", "createdAt" }.
POST /api/portal/sender-ids inserts one. Status 201.
| Field | Type | Required |
|---|---|---|
providerId | string | yes |
senderId | string | yes |
isMasked | boolean | no. Default false. |
isActive | boolean | no. Default true. |
DELETE /api/portal/sender-ids/:id returns { "success": true }.
GET /api/portal/profile-providers returns links between a profile and a provider. Query profileId limits the list to one profile. Each row is { "id", "profileId", "providerId", "senderId", "createdAt" }.
POST /api/portal/profile-providers inserts a link. Status 201. Body: profileId, providerId, and optional senderId.
DELETE /api/portal/profile-providers/:id returns { "success": true }.
Sandbox
These routes imitate BulkSMSBd and GreenWeb, and they store the captured messages. Point a provider base_url at this server to exercise delivery without the vendor.
POST /sandbox/bulksmsbd/smsapi
Content-Type: application/x-www-form-urlencoded or multipart/form-data.
| Field | Description |
|---|---|
senderid | Sender ID. |
number | Recipient. |
message | Text. |
When the sandbox settings for bulksmsbd exist and a random draw falls under failureRate, the response is text, the configured errorCode, or 1005. Otherwise status 200:
{ "response_code": 202, "message_id": 0, "success": "SMS Submitted Successfully" }The successful call is appended to the captured messages.
POST /sandbox/bulksmsbd/getBalanceApi
Status 200: { "response_code": 202, "balance": 10000 }.
POST /sandbox/greenweb/g_api.php
JSON or form body. The message is smsdata[0]:
| Field | Description |
|---|---|
to | Recipient. |
message | Text. |
from | Sender ID. |
A simulated failure returns { "status": "<errorCode or FAILED>" }. Success returns an array of one object: to, message, status (SENT), message_id.
GET /sandbox/greenweb/g_api.php
Query json. When json is present, the body is { "balance": "10000.00" }. Otherwise the body is the text 10000.00.
GET /sandbox/messages
Status 200: up to 100 captured messages, newest first. Each row is { "id", "providerType", "recipient", "body", "senderId", "rawRequest", "createdAt" }.
DELETE /sandbox/messages
Deletes every captured message. Status 200: { "success": true }.
GET /sandbox/settings
Status 200: an array of { "providerType", "failureRate", "errorCode", "latency", "updatedAt" }.
POST /sandbox/settings/:providerType
Inserts or replaces the settings for :providerType (bulksmsbd or greenweb).
| Field | Type | Description |
|---|---|---|
failureRate | number | 0 to 1. The fraction of calls that fail. |
latency | number | Milliseconds to wait before responding. |
errorCode | string | Returned when a call is selected to fail. |
Status 200: the stored settings row.
Dashboard UI
GET /portal redirects to GET /portal/. That response is index.html from dashboard/dist. GET /portal/<file> returns that file when it exists. A path with no file extension returns index.html, and the UI's hash router selects the screen. A missing asset returns status 404.