Documentation menu

OTP & transactional

A dedicated path for one-time passwords and transactional alerts, kept separate from campaigns.

Caution

This endpoint is for OTPs and transactional messages only: login codes, payment alerts, receipts and delivery notifications. Sending promotional content here breaks network rules and can get your sender ID suspended. Use Send an SMS for marketing.

Endpoint

text
POST https://api.sms.pesarails.com/v1/otp/send

Request

The fields match a normal send. You can also send from a template.

curl
curl https://api.sms.pesarails.com/v1/otp/send \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "254712345678",
    "sender": "PESARAILS",
    "message": "Your PESA RAILS code is 4821. It expires in 5 minutes."
  }'

Response

200 OK
{
  "message": {
    "id": "a1b2c3",
    "status": "sent",
    "to": "254712345678",
    "sender": "PESARAILS",
    "segments": 1,
    "priceKes": 0.5,
    "balanceAfter": 499.5
  }
}

Hashed Safaricom numbers

For privacy-compliant transactional sends to hashed Safaricom MSISDNs, post to /v1/messages/hashed with the hashed number in to. The request and response are otherwise identical.

Tip

For OTPs, build the code into a template with a {{code}} variable so your message text stays consistent and auditable.