PHP
PHP 8.0+ with curl# unzip bestsms-php.zip into your project
require 'bestsms-php/src/Client.php';
$sms = new \BestSMS\Client(getenv('BESTSMS_KEY'));
$sms->sendOtp('0771234567');
Download bestsms-php.zip 13 KB
Send receipts, OTP codes and campaigns from your own software with your approved sender ID. JSON over HTTPS, a delivery report for every number, and free SDKs for five languages.
https://bestsms.lk/api/v1Authorization: Bearer bsk_live_…curl -X POST https://bestsms.lk/api/v1/sms/send \
-H "Authorization: Bearer $BESTSMS_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "0771234567",
"sender_id": "MYSHOPOTP",
"type": "transactional",
"message": "Your order #2041 is ready for pickup."
}'$sms = new \BestSMS\Client(getenv('BESTSMS_KEY'));
$res = $sms->send('0771234567', 'Your order #2041 is ready for pickup.', [
'sender_id' => 'MYSHOPOTP',
'type' => 'transactional',
]);const sms = new BestSMS(process.env.BESTSMS_KEY);
const res = await sms.send('0771234567', 'Your order #2041 is ready for pickup.', {
senderId: 'MYSHOPOTP',
type: 'transactional',
});sms = BestSMS(os.environ["BESTSMS_KEY"])
res = sms.send("0771234567", "Your order #2041 is ready for pickup.",
sender_id="MYSHOPOTP", type="transactional")BestSMS sms = new BestSMS(System.getenv("BESTSMS_KEY"));
JsonObject res = sms.send("0771234567", "Your order #2041 is ready for pickup.",
new BestSMS.SendOptions().senderId("MYSHOPOTP")
.type(BestSMS.MessageType.TRANSACTIONAL));using var sms = new BestSmsClient(Environment.GetEnvironmentVariable("BESTSMS_KEY"));
var res = await sms.SendAsync("0771234567", "Your order #2041 is ready for pickup.",
new SendOptions { SenderId = "MYSHOPOTP", Type = MessageType.Transactional });{
"ok": true,
"campaign_id": 18342,
"status": "done",
"type": "transactional",
"recipients": 1,
"credits_reserved": 1,
"messages": [
{ "id": 904211, "phone": "94771234567", "status": "sent" }
]
}bsk_live_, can be locked to your server's IP and revoked any time.Send your key as Authorization: Bearer (recommended) or X-API-Key. The simple GET link also accepts ?api_key=. Keep keys on your server, never in a web page or mobile app.
Every response has "ok". Reads return 200, creates return 201. Errors return a 4xx or 5xx status with error.code and a readable error.message.
Any Sri Lankan mobile: 0771234567, 771234567 or +94771234567. Numbers are cleaned to 947XXXXXXXX and duplicates are sent once.
120 requests a minute per key, 300 per IP. Every response carries X-RateLimit-Remaining. Over the limit you get 429 with Retry-After.
Transactional for OTP codes, receipts and alerts. Promotional for offers. Each sender ID sends only its own type, so many businesses use two, like MYSHOPOTP and MYSHOP.
English: 160 characters per SMS (153 per part when longer). Sinhala, Tamil and emoji: 70 (67). Messages that fail are refunded to your balance automatically.
All paths are relative to https://bestsms.lk/api/v1. Open any row for parameters, samples in four languages and example responses.
Each SDK covers every endpoint, retries safely on rate limits and network errors, and checks webhook signatures. MIT licence, no extra dependencies.
# unzip bestsms-php.zip into your project
require 'bestsms-php/src/Client.php';
$sms = new \BestSMS\Client(getenv('BESTSMS_KEY'));
$sms->sendOtp('0771234567');
Download bestsms-php.zip 13 KB
npm install ./bestsms-node
const BestSMS = require('bestsms');
const sms = new BestSMS(process.env.BESTSMS_KEY);
await sms.sendOtp('0771234567');
Download bestsms-node.zip 15 KB
pip install https://bestsms.lk/sdk-files/downloads/bestsms-python.zip
from bestsms import BestSMS
sms = BestSMS(os.environ["BESTSMS_KEY"])
sms.send_otp("0771234567")
Download bestsms-python.zip 13 KB
// copy BestSMS.java into src/main/java/lk/bestsms/
BestSMS sms = new BestSMS(System.getenv("BESTSMS_KEY"));
sms.sendOtp("0771234567", new BestSMS.OtpOptions());
Download bestsms-java.zip 15 KB
dotnet add reference ./bestsms-dotnet/BestSms.csproj
using var sms = new BestSmsClient(key);
await sms.SendOtpAsync("0771234567");
Download bestsms-dotnet.zip 14 KB
Import the Postman collection, set the api_key variable and run any request. The OpenAPI 3.0 file works with code generators and API tools.
SDK guide: install, bulk and personal messages, OTP, errors and the full method list
Call POST /otp/send and we generate the code, text it from your transactional sender ID and keep only a hash. Then pass what the person typed to POST /otp/verify. Codes work once, expire after the time you set (60 to 1,800 seconds) and lock after five wrong tries.
{code}POST /api/v1/otp/send
{
"to": "0771234567",
"length": 6,
"expiry": 300,
"message": "Your MyShop login code is {code}."
}
→ 201 { "ok": true, "otp_id": 3311,
"expires_at": "2026-12-01T09:35:00+05:30" }POST /api/v1/otp/verify
{ "to": "0771234567", "code": "482916" }
→ 200 { "ok": true, "verified": true }
→ 422 { "ok": false, "error": { "code": "otp_invalid",
"attempts_left": 4 } }Add a URL in Dashboard › API & webhooks and we POST JSON to it. Every call is signed: X-BestSMS-Signature is sha256= plus the HMAC-SHA256 of the raw body with your secret. The SDKs check it for you.
message.delivered | The network confirmed the text reached the phone |
message.failed | The text could not be delivered (credit refunded) |
campaign.finished | Every number in a send is done |
balance.low | Credits dropped to your alert level |
giveaway.entry | Someone entered one of your giveaways |
Some POS and billing software can only open a web address. Use the GET link: same result as POST /sms/send, with the key and URL-encoded message in the query string.
https://bestsms.lk/api/v1/send?api_key=bsk_live_xxxx&to=0771234567&sender_id=MYSHOPOTP&message=Your%20bill%20is%20Rs%202%2C450Prefer POST where you can, because links can end up in logs. Lock the key to your shop's IP address.
Check error.code in your code and show error.message to people.
| Code | HTTP | What it means |
|---|---|---|
unauthorized | 401 | The API key is missing, wrong or revoked. A suspended account gets this code with HTTP 403. |
forbidden_ip | 403 | The key has an IP allow-list and this request came from another IP. |
rate_limited | 429 | Too many requests: over the per-minute limit on this key (120 by default), over 300 a minute from one IP address, or over 5 OTP codes to one number in 10 minutes. Wait the number of seconds in the Retry-After header, then retry. |
invalid_request | 422 | A field is missing or not valid. The message says which one. A JSON body that cannot be parsed returns this code with HTTP 400. |
sender_not_approved | 422 | The sender ID is not approved on your account, or you have no approved sender ID of the type you asked for. OTP codes need a transactional one. |
sender_limit_reached | 422 | Your plan already has as many sender IDs of this type as it includes (approved plus waiting). Withdraw a waiting request or move to a package with more sender IDs. |
sender_type_mismatch | 422 | The sender ID is the other type from the one you asked for, such as a promotional sender ID sent with "type": "transactional" or used for an OTP code. Use one of your sender IDs of that type. |
insufficient_credits | 402 | Not enough credits for this send. Nothing was sent. |
not_found | 404 | The message, campaign, group or giveaway does not exist on your account, or there is no such endpoint. |
otp_invalid | 422 | The code is wrong or was already used. If no code was sent to that number, you get it with HTTP 404. |
otp_expired | 422 | The code is older than its expiry time. Send a new one. |
otp_too_many_attempts | 429 | Five wrong tries. Send a new code. |
server_error | 500 | Something failed on our side. Retry, and contact us if it keeps happening. An OTP that could not be sent returns this code with HTTP 502. |