OTP (one-time passcode) is the most common SMS use case. Here's how to build and test a complete OTP flow in the sandbox before spending a cent.
1. Generate and send
curl "https://sms.esmsafrica.io/api/messages/send" \
-H "Authorization: Bearer esms_test_..." \
-d '{"to":"+254712341234","text":"Your code is 482910","sender_id":"eSMSAfrica"}'
You get a realistic response with the segment count and a test_… id. Tip: our OTP templates let you send just the code and we wrap it in an approved template.
2. Handle delivery
A delivered webhook arrives moments later ("livemode":false). Wire your UI to react to it — mark the code as sent, start your resend timer.
3. Rehearse the unhappy paths
Use magic numbers to test what your app does when things go wrong:
- …0000 — the SMS is undelivered; show a "resend" option.
- …0009 — insufficient balance (HTTP 402); alert your ops team.
4. Go live
Swap in your live key. Same code, real delivery, billed per segment. See the full sandbox docs to finish up.