API documentation

Send SMS through your own Android phones with one HTTP request.

Base URLhttps://sms.tritech.com.pk
Keep API keys on your server. A key can send SMS as your account. Never put one inside an Android app, a website, browser JavaScript, or a public repository. The phones don’t need one either — they pair with a one-time QR code.

Authentication

Create a key under API Keys. Send it as a bearer token on every request:

Authorization: Bearer sgw_…

A key belongs to one account and only ever sees that account’s phones and messages. Revoking it takes effect on the next request. Anything belonging to another account answers 404, exactly as if it did not exist.

Send a message

POST /v1/messages

FieldRequiredMeaning
toyesThe recipient, in international format: +923001234567.
bodyyesThe text, up to 1,600 characters. Long or non-Latin text is sent as several SMS.
target_device_idnoSend from this phone. Omit it to use any online phone of yours.
ttl_secondsnoHow long the message may wait to be sent, in seconds: 10 to 86,400. Default 600 (10 minutes). See Expiry.
curl -X POST https://sms.tritech.com.pk/v1/messages \
  -H "Authorization: Bearer $SMS_GATEWAY_API_KEY" \
  -H "Idempotency-Key: order-1234-confirmation" \
  -H "Content-Type: application/json" \
  -d '{"to":"+923001234567","body":"Your order #1234 is confirmed."}'

Answers:

Expiry — how long a message waits

Every message has a time-to-live. If none of your phones has sent it by then, it is never sent and its state becomes EXPIRED. The default is 10 minutes (600 seconds). Set ttl_seconds on the request to change it for that message, from 10 seconds up to 24 hours.

Match it to how long the message is useful. For a one-time code, use the code’s own validity, so a phone that comes back online late doesn’t send a code that no longer works. For a reminder that is still useful hours later, use a longer value. The countdown starts when we accept the request, not when a phone picks it up.

Idempotency — never send twice

Every message needs an Idempotency-Key header (or a job_id field). It becomes the message’s id. Sending the same key again returns the original message and sends nothing — so if your request times out, retry it with the same key and you can’t send the SMS twice. Use a new key for each new message. Keys are per account, up to 128 characters of letters, digits and . _ : -.

Get a message’s status

GET /v1/messages/:id returns the state and its history — never the text.

curl https://sms.tritech.com.pk/v1/messages/order-1234-confirmation \
  -H "Authorization: Bearer $SMS_GATEWAY_API_KEY"
StateMeaning
QUEUEDWaiting for one of your phones.
ASSIGNED, RECEIVED_BY_DEVICE, SENDINGA phone has it and is sending.
SENTThe phone’s SIM sent it. This is success.
DELIVEREDThe carrier confirmed delivery (not all carriers report this).
FAILEDIt could not be sent; error_code says why.
EXPIREDNo phone sent it before its time-to-live ran out.
UNKNOWNThe phone never reported back. It may or may not have gone out, and is never resent automatically.

GET /v1/messages?limit=25&state=FAILED lists your messages, newest first, with a next_cursor for the next page (?cursor=…).

Phones

GET /v1/health/gateways lists your phones with their status (healthy, warning, offline), battery, SIM state and last contact. GET /v1/devices is the plain list.

Choosing a phone

Pass a phone’s device_id as target_device_id to send from it. It must be one of your phones (404 device_not_found otherwise), and the message waits for that phone specifically.

Dual-SIM phones

A phone with two SIMs sends from the ones ticked in its app. We share messages between them and keep each SIM within its own hourly and daily limit, which is the phone’s limit unless you set one for that SIM: PUT /v1/devices/:id/sims/:subscription_id/quota with {"hourly_quota": 30, "daily_quota": 150} (null goes back to the phone’s). A SIM that keeps failing is skipped and tested again later; the phone is paused only when all its SIMs are. GET /v1/devices lists each phone’s sims with their state, limits and use.

Phone health checks

A phone whose SIM keeps failing (no signal, no balance, SIM removed) is paused: it gets no messages until a short test SMS from it goes out. Choose where that test goes, normally your own number in the same country:PUT /v1/account/health-check with {"number": "+923001234567"}. We send a 6-digit code to it from one of your phones; confirm it with POST /v1/account/health-check/verify and {"code": "123456"}. A phone can have its own number at /v1/devices/:id/health-check. Without one, a paused phone texts its own number if it is known, or is tested with one of your real messages.

Tests are sent from your SIM, at most 24 per phone per day, and are not in your message list or your message limits. POST /v1/devices/:id/resume tests a paused phone now; POST /v1/devices/:id/test sends a test from any phone.

Webhooks

When enabled for your account, we POST a JSON event to your URL for message.status (a message reached a final state), device.offline, device.degraded (a phone whose SIM kept failing was paused: it gets no messages until a test message sends) and device.recovered (with cause offline or sending). Payloads never contain message text. Delivery is retried with backoff; X-Webhook-Id is stable across retries, so use it to ignore duplicates.

Verify every delivery with the signing secret you were shown when creating the endpoint:

import crypto from 'node:crypto';

// rawBody: the request body exactly as received (a string or Buffer).
function verify(rawBody, headers, secret) {
  const timestamp = headers['x-webhook-timestamp'];
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false; // replayed
  const expected = 'sha256=' + crypto
    .createHmac('sha256', secret)
    .update(`${timestamp}.${rawBody}`)
    .digest('hex');
  const given = headers['x-signature'] ?? '';
  return given.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected));
}

Errors

Errors are JSON: {"error":"code"}.

StatusCodeWhat to do
400idempotency_key_required, invalid_idempotency_key, to_and_body_required, invalid_recipient, invalid_body, invalid_ttl_secondsFix the request. Numbers must be E.164 (+923001234567).
401unauthorizedThe key is missing, wrong or revoked.
403insufficient_scopeA read-only operations key can’t send. Use a full key.
404not_found, device_not_foundNo such message or phone in your account.
409idempotency_key_reusedThat key was already used for a different number. Use a new key.
413payload_too_largeThe request is over 64 KB.
429quota_exceeded (with quota and limit)Your account’s hourly, daily or pending-message limit. See Settings → Limits. Retrying immediately won’t help.
429rate_limited (with retry_after_seconds)Too many requests too fast. Wait for the Retry-After header, then retry with the same key.
503no_device_availableCheck your phones in the dashboard (open the app, fix the SIM), then retry with the same key.

Examples

JavaScript (on your server)

// Node 18+ / Bun / Deno. Run this on your SERVER, never in a browser.
const response = await fetch('https://sms.tritech.com.pk/v1/messages', {
  method: 'POST',
  headers: {
    authorization: `Bearer ${process.env.SMS_GATEWAY_API_KEY}`,
    'idempotency-key': crypto.randomUUID(), // store it with your record to retry safely
    'content-type': 'application/json',
  },
  body: JSON.stringify({ to: '+923001234567', body: 'Hello from my app' }),
});
const result = await response.json();
if (!response.ok) throw new Error(result.error);
console.log(result.job_id, result.state);

A server-side integration

// Express: your frontend calls YOUR endpoint; only your server holds the key.
app.post('/api/send-code', requireSignedInUser, async (req, res) => {
  const jobId = `login-${req.user.id}-${Date.now()}`;
  const r = await fetch('https://sms.tritech.com.pk/v1/messages', {
    method: 'POST',
    headers: {
      authorization: `Bearer ${process.env.SMS_GATEWAY_API_KEY}`,
      'idempotency-key': jobId,
      'content-type': 'application/json',
    },
    body: JSON.stringify({ to: req.user.phone, body: `Your code is ${makeCode(req.user)}` }),
  });
  if (r.status === 503) return res.status(503).json({ message: 'Try again shortly.' });
  if (!r.ok) return res.status(502).end();
  res.json({ sent: true });
});