One API call. A text on any Sri Lankan phone.

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.

Base URL
https://bestsms.lk/api/v1
Auth
Authorization: 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."
  }'
201Created
{
  "ok": true,
  "campaign_id": 18342,
  "status": "done",
  "type": "transactional",
  "recipients": 1,
  "credits_reserved": 1,
  "messages": [
    { "id": 904211, "phone": "94771234567", "status": "sent" }
  ]
}

Send your first SMS in three steps

  1. Create an accountStart on pay as you go or a monthly package. See pricing.
  2. Get a sender ID approvedRequest the name customers will see, like MYSHOP, from your dashboard. Usually approved within one working day.
  3. Create an API key and sendDashboard › API & webhooks. Keys start with bsk_live_, can be locked to your server's IP and revoked any time.

The basics

Authentication

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.

JSON in, JSON out

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.

Phone numbers

Any Sri Lankan mobile: 0771234567, 771234567 or +94771234567. Numbers are cleaned to 947XXXXXXXX and duplicates are sent once.

Rate limits

120 requests a minute per key, 300 per IP. Every response carries X-RateLimit-Remaining. Over the limit you get 429 with Retry-After.

Message types

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.

Counting and refunds

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.

Free SDKs for five languages

Each SDK covers every endpoint, retries safely on rate limits and network errors, and checks webhook signatures. MIT licence, no extra dependencies.

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

Node.js

Node.js 18+, CommonJS, ESM and TypeScript types
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

Python

Python 3.8+, typed
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

Java and Android

Java 8+, Android minSdk 21, one file
// 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

C# and .NET

.NET 6+ or netstandard2.0, async
dotnet add reference ./bestsms-dotnet/BestSms.csproj

using var sms = new BestSmsClient(key);
await sms.SendOtpAsync("0771234567");
Download bestsms-dotnet.zip 14 KB

Postman and OpenAPI

Try every endpoint, or generate a client

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.

Postman collection openapi.json

SDK guide: install, bulk and personal messages, OTP, errors and the full method list

OTP codes without storing codes

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.

  • 4 to 8 digits, your own message with {code}
  • Up to 5 codes per number every 10 minutes
  • Sent even to numbers on your opt-out list
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" }

Webhooks tell you what happened

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.deliveredThe network confirmed the text reached the phone
message.failedThe text could not be delivered (credit refunded)
campaign.finishedEvery number in a send is done
balance.lowCredits dropped to your alert level
giveaway.entrySomeone entered one of your giveaways

Payloads and signature code

A simple link for POS systems

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%2C450

Prefer POST where you can, because links can end up in logs. Lock the key to your shop's IP address.

Error codes

Check error.code in your code and show error.message to people.

CodeHTTPWhat it means
unauthorized401The API key is missing, wrong or revoked. A suspended account gets this code with HTTP 403.
forbidden_ip403The key has an IP allow-list and this request came from another IP.
rate_limited429Too 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_request422A 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_approved422The 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_reached422Your 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_mismatch422The 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_credits402Not enough credits for this send. Nothing was sent.
not_found404The message, campaign, group or giveaway does not exist on your account, or there is no such endpoint.
otp_invalid422The code is wrong or was already used. If no code was sent to that number, you get it with HTTP 404.
otp_expired422The code is older than its expiry time. Send a new one.
otp_too_many_attempts429Five wrong tries. Send a new code.
server_error500Something 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.