Mobi SMS
REST API v1
JSON + HMAC Webhooks

Mobi SMS Client Integration Guide

Everything your engineering team needs to send SMS, send bulk & scheduled campaigns, use smart multi-SIM carrier routing, poll message status, and verify real-time webhooks.

Customize Code Examples

Fill in your API URL or test credentials below to update every code sample on this page live. Values stay in your browser only.

1. Overview & Quick Start

Your backend sends HTTPS requests to the Mobi SMS REST API. Mobi SMS queues each SMS, pushes it to a paired Android gateway phone over Firebase Cloud Messaging, and sends it through the phone's SIM card. Delivery updates and incoming SMS flow back to your server via signed webhooks or polling.

Step 1

Verify Account

Create an account in the dashboard and verify your email address.

Step 2

Pair Android Phone

Install the Android app, grant SMS/Phone permissions, and disable battery optimization.

Step 3

Create API Key

Generate a key in the dashboard and store it in your backend environment.

Step 4

Send & Listen

Call POST /gateway/send-sms and subscribe to webhooks for delivery & replies.

Acceptance vs. Carrier Delivery

A 200 OK response from a send endpoint means Mobi SMS accepted and queued the batch — not that the recipient handset already received it. Use Webhooks (recommended) or status polling to observe final sent, delivered, or failed states.

2. Authentication

Send your API key in the x-api-key request header on every call. Never expose your API key in browser or mobile client code.

GET/auth/who-am-i

Verify your API key and inspect the account it belongs to. Invalid or revoked keys return 401 Unauthorized with {"error":"Unauthorized","code":"AUTH_INVALID"}.

curl "http://localhost:2026/api/v1/auth/who-am-i" \
  -H "x-api-key: YOUR_API_KEY"

3. Send SMS

Send one message to one or more recipients. Omit deviceId and simSubscriptionId to let Mobi SMS automatically route to the best carrier-matched SIM and device.

POST/gateway/send-sms
FieldTypeRequiredDescription
recipientsstring[]
Required
Phone numbers or short codes (E.164 like +85512345678 recommended; local format works within the SIM's country). Spaces are stripped; letters are rejected with 400.
messagestring
Required
Non-empty SMS text. Long messages are segmented by the carrier (160 chars GSM-7, 70 chars Unicode/Khmer/emoji).
deviceIdstring
Optional
Pin sending to a specific paired device. Omit for smart multi-device routing.
simSubscriptionIdnumber
Optional
Android SIM subscriptionId from GET /gateway/devices. Omit for automatic carrier-matched SIM selection.
scheduledAtstring
Optional
Future ISO-8601 timestamp with timezone (e.g. 2026-12-01T02:00:00Z). Requires server SMS queue enabled.
curl -X POST "http://localhost:2026/api/v1/gateway/send-sms" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "recipients": ["+85512345678"],
    "message": "Your verification code is 481920. It expires in 10 minutes."
  }'
Example 200 OK response
{
  "data": {
    "success": true,
    "message": "SMS added to queue for processing",
    "smsBatchId": "673c2e1f9a8b7c6d5e4f3a21",
    "recipientCount": 1
  }
}

4. Bulk & Scheduled SMS

Send personalized messages to different recipients in one API call (max request body 2 MB). Each item in messages[] can have its own text, recipients, simSubscriptionId, and scheduledAt. Large batches are paced in waves automatically and return estimatedCompletionAt.

POST/gateway/send-bulk-sms
curl -X POST "http://localhost:2026/api/v1/gateway/send-bulk-sms" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messageTemplate": "Payment reminder",
    "messages": [
      {
        "recipients": ["+85512345678"],
        "message": "Hi Sokha, invoice #881 is due tomorrow."
      },
      {
        "recipients": ["+85515987654"],
        "message": "Hi Dara, invoice #882 is due tomorrow.",
        "scheduledAt": "2026-12-01T02:00:00Z"
      }
    ]
  }'
Example 200 OK response
{
  "data": {
    "success": true,
    "message": "SMS added to queue for processing",
    "smsBatchId": "673c2f0a1b2c3d4e5f6a7b89",
    "recipientCount": 2,
    "estimatedCompletionAt": "2026-12-01T02:05:00.000Z"
  }
}

5. Smart Multi-Device & Multi-SIM Carrier Routing

When you omit deviceId and simSubscriptionId, Mobi SMS automatically detects Cambodian recipient carriers (+855, 00855, 855, or local 0XX), picks an enabled healthy device with an IN_SERVICE SIM on the same mobile operator, and load-balances round-robin across matching SIM slots.

CarrierRecognized Number Prefixes
Cellcard011, 012, 014, 017, 061, 076, 077, 078, 079, 085, 089, 092, 095, 099
Smart010, 015, 016, 069, 070, 081, 086, 087, 093, 096, 098
Metfone031, 060, 066, 067, 068, 071, 088, 090, 097
Seatel (Yes)018
Cootel038
  • Health-aware

    Skips offline phones, invalid push tokens, and out-of-service or locked SIM cards.

  • Round-robin spread

    Balances traffic evenly across matching SIM slots and devices to avoid Android/carrier send caps.

  • Automatic fallback

    For international numbers or unmatched carriers, falls back to the healthiest least-recently-used active SIM.

6. Read & Track Messages

Query sent and received SMS across all devices on your account. Supports page numbers for UI browsing or cursor pagination (order=asc + meta.nextCursor) for zero-duplicate polling.

GET/gateway/messages
GET/gateway/devices/{deviceId}/sms-batch/{smsBatchId}
GET/gateway/devices/{deviceId}/sms/{smsId}
Query ParamValues / FormatDescription
directionall | sent | receivedDefault all. Outbound vs inbound.
statuspending | dispatched | sent | delivered | failed | unknown | receivedFilter by delivery state. Combine with smsBatchId to find failed items.
deviceIds / smsBatchId / searchstringComma-separated device IDs (max 100), a batch ID, or text / phone substring search.
from / toISO-8601 w/ TZ or YYYY-MM-DDfrom inclusive, to exclusive on createdAt. Timezone required.
page / limit / cursor / orderlimit 1–100 (default 50)page and cursor are mutually exclusive. Use order=asc when polling.
# List received SMS (newest first)
curl "http://localhost:2026/api/v1/gateway/messages?direction=received&limit=20" \
  -H "x-api-key: YOUR_API_KEY"

# Inspect failed messages in a specific batch
curl "http://localhost:2026/api/v1/gateway/messages?smsBatchId=YOUR_BATCH_ID&status=failed" \
  -H "x-api-key: YOUR_API_KEY"
Example 200 OK response
{
  "data": [
    {
      "_id": "673c3100a1b2c3d4e5f60001",
      "message": "YES confirm",
      "direction": "received",
      "channel": "sms",
      "status": "received",
      "sender": "+85512345678",
      "receivedAt": "2026-11-27T04:55:10.000Z",
      "createdAt": "2026-11-27T04:55:11.200Z",
      "simUsed": {
        "subscriptionId": 1,
        "slotIndex": 0,
        "carrierName": "Cellcard",
        "countryIso": "kh",
        "mcc": "456",
        "mnc": "01"
      }
    }
  ],
  "meta": {
    "page": 1,
    "limit": 50,
    "total": 1,
    "totalPages": 1,
    "nextCursor": null,
    "hasMore": false
  }
}

Message Status Lifecycle

StatusDirectionMeaning
pending
sent
Accepted on the server; waiting in queue, paced wave, or schedule.
dispatched
sent
Pushed to the Android phone via FCM; awaiting phone confirmation.
sent
sent
Handed to the mobile carrier and accepted for transmission.
delivered
sent
Carrier confirmed handset delivery (when supported by carrier).
failed
sent
Delivery failed on server, push service, or phone (see errorCode).
unknown
sent
No phone status report arrived within 20 minutes after due time.
received
received
Incoming SMS received on the phone and uploaded to Mobi SMS.

7. Webhooks & Signature Verification

Receive real-time HTTPS POST callbacks for incoming SMS and outbound status transitions. Subscriptions can be managed in the dashboard or through the REST API below.

POST/webhooks
GET/webhooks
PATCH/webhooks/{webhookId}
DELETE/webhooks/{webhookId}
GET/webhooks/notifications
EventWhen it fires
MESSAGE_RECEIVEDIncoming SMS received on a phone (requires Receive SMS on; skipped if uploaded > 48h late).
MESSAGE_SENTCarrier accepted an outgoing SMS from the phone.
MESSAGE_DELIVEREDRecipient handset confirmed delivery via carrier receipt.
MESSAGE_FAILEDOutgoing SMS failed (includes errorCode, errorName, and errorMessage).
UNKNOWN_STATEOutgoing SMS entered an unrecognized or timed-out status.

Create a Webhook Subscription

deliveryUrl must be a public http/https URL (private/loopback hosts are rejected). signingSecret must be at least 20 characters.

curl -X POST "http://localhost:2026/api/v1/webhooks" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production SMS Events",
    "deliveryUrl": "https://api.yourapp.com/webhooks/mobi-sms",
    "signingSecret": "whsec_replace_with_at_least_20_chars",
    "events": [
      "MESSAGE_RECEIVED",
      "MESSAGE_SENT",
      "MESSAGE_DELIVERED",
      "MESSAGE_FAILED"
    ]
  }'

Event Payload Shapes

{
  "smsId": "673c3100a1b2c3d4e5f60001",
  "sender": "+85512345678",
  "message": "YES confirm",
  "receivedAt": "2026-11-27T04:55:10.000Z",
  "deviceId": "673b0001a1b2c3d4e5f60099",
  "webhookSubscriptionId": "673b9999a1b2c3d4e5f60001",
  "webhookEvent": "MESSAGE_RECEIVED",
  "idempotencyKey": "c7a6e13b-6c44-4c8d-9b34-3f62f2c3a41d",
  "simUsed": {
    "subscriptionId": 1,
    "slotIndex": 0,
    "carrierName": "Cellcard",
    "countryIso": "kh",
    "mcc": "456",
    "mnc": "01"
  }
}

Verify Webhook Signatures (HMAC-SHA256)

Every delivery carries X-Textbee-Signature: t=<unix>,v1=<hex>, where v1 is the hex HMAC-SHA256 of <t>.<raw_body> using your signingSecret. Always verify against the raw request bytes, reject timestamps older than 300 seconds, compare in constant time, and deduplicate retries using payload.idempotencyKey.

# Test your webhook handler locally by generating a valid signature:
SECRET="whsec_replace_with_at_least_20_chars"
TIMESTAMP=$(date +%s)
BODY='{"smsId":"673c3100a1b2c3d4e5f60001","sender":"+85512345678","message":"YES","webhookEvent":"MESSAGE_RECEIVED","idempotencyKey":"test-1"}'
SIG=$(printf "%s.%s" "$TIMESTAMP" "$BODY" | openssl dgst -sha256 -hmac "$SECRET" -hex | awk '{print $NF}')

curl -X POST "https://api.yourapp.com/webhooks/mobi-sms" \
  -H "Content-Type: application/json" \
  -H "X-Textbee-Timestamp: $TIMESTAMP" \
  -H "X-Textbee-Signature: t=$TIMESTAMP,v1=$SIG" \
  -d "$BODY"
Retries & auto-pause: Return 2xx within 10 seconds. 5xx and network/timeout failures retry up to 10 attempts (3m → 5m → 30m → 1h → 6h → 1d → 3d → 7d → 30d). 4xx responses abort after 3 attempts. Subscriptions with persistent failures are automatically paused (isActive: false) and can be re-enabled via PATCH /webhooks/{webhookId}.

8. Devices, Quota & Health Endpoints

Inspect paired Android devices, SIM card status, account totals, plan limits, and service uptime.

EndpointPurpose
GET/gateway/devicesList paired devices, lastHeartbeat, battery/network state, and simInfo.sims[].
PATCH/gateway/devices/{id}Update device label (name) or toggle enabled.
POST/gateway/devices/{id}/set-defaultSet the default sending device for your account.
GET/gateway/statsTotal sent SMS, received SMS, devices, and API keys.
GET/gateway/sms-permission-statusCheck if a missing Android SEND_SMS permission is currently blocking sends.
GET/billing/current-subscriptionActive plan limits (dailyLimit, monthlyLimit, bulkSendLimit) & remaining usage.
GET/healthPublic liveness probe (no auth, no rate limit). Returns 200 when healthy or 503 when degraded.
curl "http://localhost:2026/api/v1/gateway/devices" \
  -H "x-api-key: YOUR_API_KEY"

9. Errors, Rate Limits & Troubleshooting

The API enforces a global per-IP rate limit of 500 requests / minute in addition to plan SMS quotas. Both return 429 Too Many Requests.

HTTP StatusMeaning & Resolution
200 / 201Request accepted or resource created.
400Validation error: empty message, invalid phone number, no enabled device, unverified email, past scheduledAt, or invalid filter.
401Missing, invalid, or revoked x-api-key.
403 / 404Account restricted (403) or referenced device/message/batch/webhook not found on your account (404).
429Rate limit (500 req/min/IP) or plan daily/monthly/batch SMS quota reached. Inspect hasReachedLimit and monthlyResetAt.
500Transient server or queue error — retry with exponential backoff.
Example 429 quota response payload
{
  "message": "Your account has used all 50 messages your plan allows today...",
  "hasReachedLimit": true,
  "dailyLimit": 50,
  "dailyRemaining": 0,
  "monthlyLimit": 500,
  "monthlyRemaining": 320,
  "monthlyResetAt": "2026-12-01T00:00:00.000Z",
  "bulkSendLimit": 50
}

Common SMS Delivery Error Codes

Code / NameSourceRetryableResolution
PERMISSION_DENIED
device
No
Grant SMS and Phone permissions inside the Mobi SMS Android app.
1
GENERIC_FAILURE
device
Yes
Check cellular signal and SIM SMS credit balance, then retry.
2
RADIO_OFF
device
No
Disable Airplane Mode and turn on cellular service on the phone.
4
NO_SERVICE
device
Yes
Phone has no mobile signal; check coverage or SIM status.
5
LIMIT_EXCEEDED
device
Yes
Android outgoing SMS cap hit; increase Send Delay or add devices.
10
NETWORK_REJECT
device
No
Carrier rejected the SMS; verify SIM balance and destination number.
FCM_TOKEN_NOT_REGISTERED
PUSH_TOKEN_NOT_REGISTERED
push
No
Open the Mobi SMS Android app and re-register the device.
DISPATCH_FAILED
server
Yes
Transient server handoff failure; retry with backoff.

Production Go-Live Checklist

  • • Store x-api-key in environment variables or a secret vault.
  • • Keep gateway phone(s) plugged in and exempt from Android battery optimization.
  • • Validate recipient phone numbers (digits + optional +, no letters) before calling the API.
  • • Verify X-Textbee-Signature on raw bytes and deduplicate using idempotencyKey.