Reference
Every endpoint, parameter, and response for the MySMSAPio SMS Gateway. All routes are prefixed with /api/v1.
The MySMSAPio API is a JSON REST API. There are two classes of consumer:
api_live_… key.gw_live_… key.Base URL
https://your-host/api/v1
Content-Type
application/json
All authenticated endpoints expect an API key in the Authorization header as a Bearer token. Keys are SHA-256 hashed at rest — the raw key is only shown once at creation.
api_live_<64 hex chars>
Permissions-based (send_sms, receive_sms…). Can expire.
gw_live_<64 hex chars>
Bound to a single gateway device. Must be active.
Limits are enforced via Redis and return 429 Too Many Requests with a retry_after hint.
| Resource | Limit | Window |
|---|---|---|
| Send SMS | 100 | per minute / API key |
| Send OTP | 3 | per hour / phone number |
| OTP verify attempts | 3 | per code |
Errors are returned as JSON with an error field. Validation errors also include details.
| Status | Meaning |
|---|---|
| <%= code %> | <%= meaning %> |
/sms/send
Queues an outbound message. The API returns immediately with a message_id; delivery happens asynchronously via an available gateway. Rate limited to 100/min per API key.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| to | string | yes | E.164 phone number (validated via Phonelib) |
| message | string | yes | Message body (max 1600 chars) |
Example request
Response · 202 Accepted
/sms/status/:message_id
Returns the current lifecycle state of a message, including timestamps.
Path parameters
| Parameter | Type | Description |
|---|---|---|
| message_id | string | The ID returned when the message was created |
Response · 200 OK
Statuses: queued → pending → sent → delivered | failed
/sms/received
Paginated list of inbound messages, newest first. Optional filters by phone number or date.
Query parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| phone_number | string | — | Filter by sender phone |
| since | datetime | — | Only messages after this time |
| limit | integer | 50 | Items per page |
Response · 200 OK
/otp/send
Generates a 6-digit code, sends it via SMS, and returns the expiry time. Max 3 codes per phone per hour.
Request body
| Parameter | Type | Required | Default |
|---|---|---|---|
| phone_number | string | yes | — |
| purpose | string | no | authentication |
| expiry_minutes | integer | no | 5 |
Response · 200 OK
/otp/verify
Validates the 6-digit code. After 3 failed attempts the code is expired. On success the code is marked verified and cannot be reused.
Request body
| Parameter | Type | Required |
|---|---|---|
| phone_number | string | yes |
| code | string | yes |
Success · 200
Failure · 200
/admin/stats
Aggregate system metrics: gateway counts, message throughput, pending/failed counts, and OTP performance for today.
Response · 200 OK
/admin/gateways
Returns every registered gateway device with live status and counters.
/admin/gateways/:id/toggle
Activate or deactivate a gateway. Toggling off stops it from receiving outbound commands.
Toggle response · 200 OK
/gateway/register
No auth Registers an Android device and returns a fresh gateway API key. Returns 409 if the device_id already exists.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| device_id | string | yes | Unique device identifier |
| name | string | no | Friendly name (defaults to device id prefix) |
Response · 201 Created
Save api_key immediately — it is never shown again.
/gateway/heartbeat
Refreshes the gateway's online status. A gateway is marked offline if no heartbeat arrives within 2 minutes (handled by CheckGatewayHealthJob).
Optional body
| Parameter | Type | Description |
|---|---|---|
| battery_level | integer | 0–100 |
| signal_strength | integer | dBm |
| messages_in_queue | integer | Pending outbound count on device |
Response · 200 OK
/gateway/sms/received
Called by the gateway when a new SMS arrives on the device. Creates an inbound record and triggers ProcessInboundSmsJob (which fires webhooks).
Request body
| Parameter | Type | Required |
|---|---|---|
| sender | string | yes |
| message | string | yes |
| timestamp | datetime | no |
Response · 200 OK
/gateway/sms/status
Updates an outbound message's status. On failed, RetryFailedSmsJob is enqueued if retries remain (< 3).
Request body
| Parameter | Type | Required | Values |
|---|---|---|---|
| message_id | string | yes | — |
| status | string | yes | sent · delivered · failed |
| error_message | string | no | Reason for failure |
Response · 200 OK
/cable
Gateways maintain a persistent Action Cable connection for real-time command dispatch and status reporting. Connections authenticate with the gateway API key as a query param.
Connect
Server → Gateway commands
Gateway → Server events
| action | Payload |
|---|---|
| heartbeat | battery_level, signal_strength, messages_in_queue |
| delivery_report | message_id, status, error_message |
| message_received | sender, message, timestamp |
Outbound HTTP POST
When configured, the API delivers signed event payloads to your URL via TriggerWebhookJob. If a secret key is set, each request is signed with HMAC-SHA256.
<%= e[:event] %>
<%= e[:desc] %>
Example payload (sms_received)
Verifying the signature