BestSMS.lk

SMS API

Send SMS and OTP codes to Sri Lankan mobiles, track delivery, and manage sender IDs, contacts and giveaways from your own software. Every endpoint takes and returns JSON.

Base URL
https://bestsms.lk/api/v1
Format
JSON in, JSON out, UTF-8
Time zone
Asia/Colombo for every date

Every response has "ok". When something goes wrong you get an HTTP 4xx or 5xx status with an error object you can show or log.

200Success
{
  "ok": true,
  ...
}
422Error
{
  "ok": false,
  "error": {
    "code": "sender_not_approved",
    "message": "That sender ID is not approved on your account."
  }
}

Authentication

Create a key in Dashboard › API & webhooks. Keys start with bsk_live_ and are shown once, so store yours somewhere safe. You can lock a key to your server's IP addresses and revoke it at any time.

Send the key in one of these ways:

  • Authorization: Bearer <API_KEY> (recommended)
  • X-API-Key: <API_KEY>
  • ?api_key=<API_KEY>, only for the simple GET /send link

Never put a key in a website's front-end code or a mobile app. Call the API from your server.

curl https://bestsms.lk/api/v1/balance \
  -H "Authorization: Bearer bsk_live_xxxxxxxxxxxxxxxx"

Phone numbers and limits

Any Sri Lankan mobile number works in any of these forms. Numbers are cleaned to 947XXXXXXXX and duplicates in one request are sent once.

0771234567771234567+9477123456794771234567

Each key can make 120 requests a minute. Over that you get 429 rate_limited. One send request can have up to 100,000 numbers, so batch big lists into one call instead of calling once per number.

How SMS are counted

One credit sends one SMS part to one number. Long messages are split into parts and each part costs a credit. If a message has any Sinhala, Tamil, emoji or other character outside the standard SMS alphabet, the whole message is sent as Unicode.

Text typeOne SMSEach part of a longer SMS
Standard (GSM) English text160 characters153 characters
Unicode: Sinhala, Tamil, emoji70 characters67 characters

The characters ^ { } \ [ ] ~ | € count as two in standard text.

Account

Check your balance

GET/balance

Returns your remaining credits and the price per SMS on your account.

curl "https://bestsms.lk/api/v1/balance" \
  -H "Authorization: Bearer $BESTSMS_KEY"
200Response
{
    "ok": true,
    "credits": 9480,
    "price_per_sms": 1.3500000000000001
}

SMS

Send SMS

POST/sms/send

Send one message to one or many numbers. Credits for every number are held when the request is accepted, and credits for numbers that fail are refunded when the campaign finishes. Up to 100 recipients are sent before the response returns; larger lists are queued and sent in the background.

FieldTypeDetails
torequiredstring | arrayNumbers separated by commas, or an array. For personal messages pass an array of objects: {"phone", "name", "field1", "field2"} and use {name}, {field1}, {field2} in the message.
messagerequiredstringThe text. Up to 1,530 characters (10 SMS parts).
sender_idrequiredstringAn approved sender ID on your account.
schedule_atstringSend later, in Sri Lanka time. Format "2026-12-01 09:30".
namestringCampaign name shown in your dashboard.
client_refstringYour own reference, returned with each message.
curl -X POST "https://bestsms.lk/api/v1/sms/send" \
  -H "Authorization: Bearer $BESTSMS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "0771234567,0762289014",
    "sender_id": "MYSHOP",
    "message": "Your order #2041 is ready for pickup.",
    "client_ref": "order-2041"
}'
200Response
{
    "ok": true,
    "campaign_id": 18342,
    "status": "done",
    "recipients": 2,
    "credits_reserved": 2,
    "invalid": 0,
    "opted_out": 0,
    "messages": [
        {
            "id": 904211,
            "phone": "94771234567",
            "status": "sent"
        },
        {
            "id": 904212,
            "phone": "94762289014",
            "status": "sent"
        }
    ]
}

Send with a simple link

GET/send

For POS systems and devices that can only open a URL. Same response as POST /sms/send. Put the key in the api_key query parameter and URL-encode the message. Prefer POST /sms/send wherever you can, because links can end up in logs.

FieldTypeDetails
api_keyrequiredstringYour API key.
torequiredstringNumbers separated by commas.
messagerequiredstringURL-encoded text.
sender_idrequiredstringAn approved sender ID.
https://bestsms.lk/api/v1/send?api_key=bsk_live_xxxx&to=0771234567&sender_id=MYSHOP&message=Your%20bill%20is%20Rs%202%2C450.%20Thank%20you!
200Response
{
    "ok": true,
    "campaign_id": 18343,
    "status": "done",
    "recipients": 1,
    "credits_reserved": 1,
    "invalid": 0,
    "opted_out": 0,
    "messages": [
        {
            "id": 904213,
            "phone": "94771234567",
            "status": "sent"
        }
    ]
}

Get a message status

GET/sms/{id}

Status is one of queued, sent, delivered, failed or cancelled. Encoding is gsm (160 characters per SMS) or unicode (70).

FieldTypeDetails
idrequiredintegerMessage id from the send response.
curl "https://bestsms.lk/api/v1/sms/904211" \
  -H "Authorization: Bearer $BESTSMS_KEY"
200Response
{
    "ok": true,
    "message": {
        "id": 904211,
        "campaign_id": 18342,
        "phone": "94771234567",
        "status": "delivered",
        "segments": 1,
        "encoding": "gsm",
        "gateway_ref": "a91f0c2e",
        "error": null,
        "client_ref": "order-2041",
        "created_at": "2026-12-01 09:30:02",
        "sent_at": "2026-12-01 09:30:03",
        "delivered_at": "2026-12-01 09:30:05"
    }
}

Campaigns

List campaigns

GET/campaigns

Newest first, 50 per page.

FieldTypeDetails
pageintegerPage number, starting at 1.
curl "https://bestsms.lk/api/v1/campaigns?page=1" \
  -H "Authorization: Bearer $BESTSMS_KEY"
200Response
{
    "ok": true,
    "campaigns": [
        {
            "id": 18342,
            "name": "Year-end sale",
            "sender": "MYSHOP",
            "status": "done",
            "total": 2480,
            "sent": 2443,
            "delivered": 2381,
            "failed": 37,
            "credits_used": 2443,
            "scheduled_at": null,
            "created_at": "2026-12-01 09:30:00"
        }
    ],
    "page": 1,
    "pages": 4
}

Get one campaign

GET/campaigns/{id}

Returns the same fields as the list, for one campaign.

FieldTypeDetails
idrequiredintegerCampaign id.
curl "https://bestsms.lk/api/v1/campaigns/18342" \
  -H "Authorization: Bearer $BESTSMS_KEY"
200Response
{
    "ok": true,
    "campaign": {
        "id": 18342,
        "name": "Year-end sale",
        "sender": "MYSHOP",
        "status": "sending",
        "total": 2480,
        "sent": 1200,
        "delivered": 980,
        "failed": 4,
        "credits_used": 1200,
        "scheduled_at": null,
        "created_at": "2026-12-01 09:30:00"
    }
}

Cancel a campaign

POST/campaigns/{id}/cancel

Stops a scheduled or sending campaign. Messages not yet sent are cancelled and their credits are refunded right away.

FieldTypeDetails
idrequiredintegerCampaign id.
curl -X POST "https://bestsms.lk/api/v1/campaigns/18350/cancel" \
  -H "Authorization: Bearer $BESTSMS_KEY"
200Response
{
    "ok": true,
    "refunded": 2480
}

Sender IDs

List sender IDs

GET/sender-ids

All sender IDs on your account and their status: pending, approved, rejected or revoked. Only approved ones can send.

curl "https://bestsms.lk/api/v1/sender-ids" \
  -H "Authorization: Bearer $BESTSMS_KEY"
200Response
{
    "ok": true,
    "sender_ids": [
        {
            "sender_id": "MYSHOP",
            "status": "approved",
            "created_at": "2026-11-28 10:12:00"
        },
        {
            "sender_id": "MYSHOP SALE",
            "status": "pending",
            "created_at": "2026-12-01 08:01:00"
        }
    ]
}

Request a sender ID

POST/sender-ids

Asks our team to approve a new sender ID. It must be 3 to 11 characters: letters, digits, spaces, dots, & or -, with at least one letter.

FieldTypeDetails
sender_idrequiredstringThe name customers will see.
business_namerequiredstringYour registered business or brand name.
purposerequiredstringWhat you will send with it.
sample_messagestringAn example message.
curl -X POST "https://bestsms.lk/api/v1/sender-ids" \
  -H "Authorization: Bearer $BESTSMS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sender_id": "MYSHOP",
    "business_name": "My Shop (Pvt) Ltd",
    "purpose": "Order updates and offers for our customers",
    "sample_message": "Your order #2041 is ready for pickup."
}'
200Response
{
    "ok": true,
    "id": 57,
    "status": "pending"
}

OTP

Send an OTP code

POST/otp/send

Generates a random code, texts it and stores only a hash of it. Sending a new code to the same number replaces the old one.

FieldTypeDetails
torequiredstringOne mobile number.
sender_idrequiredstringAn approved sender ID.
lengthintegerDigits, 4 to 8. Default 6.
expiryintegerSeconds the code stays valid, 60 to 1800. Default 300.
messagestringMust contain {code}. Default "Your verification code is {code}".
curl -X POST "https://bestsms.lk/api/v1/otp/send" \
  -H "Authorization: Bearer $BESTSMS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "0771234567",
    "sender_id": "MYSHOP",
    "length": 6,
    "expiry": 300,
    "message": "Your MyShop login code is {code}. It expires in 5 minutes."
}'
200Response
{
    "ok": true,
    "otp_id": 3311,
    "expires_at": "2026-12-01 09:35:00"
}

Verify an OTP code

POST/otp/verify

Checks a code. A code works once. After 5 wrong tries it is locked and you get otp_too_many_attempts.

FieldTypeDetails
torequiredstringThe number the code was sent to (or pass otp_id instead).
otp_idintegerFrom the send response.
coderequiredstringWhat the person typed.
curl -X POST "https://bestsms.lk/api/v1/otp/verify" \
  -H "Authorization: Bearer $BESTSMS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "0771234567",
    "code": "482916"
}'
200Response
{
    "ok": true,
    "verified": true
}

Contacts

List contact groups

GET/groups

Your contact groups with the number of contacts in each.

curl "https://bestsms.lk/api/v1/groups" \
  -H "Authorization: Bearer $BESTSMS_KEY"
200Response
{
    "ok": true,
    "groups": [
        {
            "id": 4,
            "name": "Loyalty members",
            "contacts": 2480
        },
        {
            "id": 7,
            "name": "Wholesale",
            "contacts": 112
        }
    ]
}

Add a contact

POST/contacts

Adds a number to a group. Pass group (a name) instead of group_id and the group is created if it does not exist. Adding a number that is already in the group updates its name and fields.

FieldTypeDetails
group_idintegerExisting group id.
groupstringGroup name, created if missing.
phonerequiredstringMobile number.
namestringUsed by {name}.
field1stringUsed by {field1}.
field2stringUsed by {field2}.
curl -X POST "https://bestsms.lk/api/v1/contacts" \
  -H "Authorization: Bearer $BESTSMS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "group": "Loyalty members",
    "phone": "0771234567",
    "name": "Nimal",
    "field1": "1,250 points"
}'
200Response
{
    "ok": true,
    "contact_id": 88412
}

Add an opt-out

POST/optouts

Numbers on your opt-out list are skipped in every campaign. OTP messages still go through.

FieldTypeDetails
phonerequiredstringMobile number.
reasonstringWhy, for your records.
curl -X POST "https://bestsms.lk/api/v1/optouts" \
  -H "Authorization: Bearer $BESTSMS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "phone": "0771234567",
    "reason": "Replied STOP"
}'
200Response
{
    "ok": true
}

Giveaways

List giveaways

GET/giveaways

Your giveaways with their public link and entry count. Type is draw, quiz, instant or referral.

curl "https://bestsms.lk/api/v1/giveaways" \
  -H "Authorization: Bearer $BESTSMS_KEY"
200Response
{
    "ok": true,
    "giveaways": [
        {
            "slug": "xmas-hamper",
            "title": "Win a Christmas hamper",
            "type": "draw",
            "status": "live",
            "entries": 3214,
            "link": "https://bestsms.lk/g/xmas-hamper",
            "ends_at": "2026-12-25 23:59:00"
        }
    ]
}

List giveaway entries

GET/giveaways/{slug}/entries

Entries for one giveaway, oldest first, 100 per page.

FieldTypeDetails
slugrequiredstringThe giveaway slug.
pageintegerPage number.
curl "https://bestsms.lk/api/v1/giveaways/xmas-hamper/entries?page=1" \
  -H "Authorization: Bearer $BESTSMS_KEY"
200Response
{
    "ok": true,
    "entries": [
        {
            "name": "Nimal Perera",
            "phone": "94771234567",
            "email": null,
            "verified": true,
            "referrals": 3,
            "bonus_entries": 6,
            "created_at": "2026-12-02 18:22:10",
            "answers": {
                "city": "Kandy"
            }
        }
    ],
    "page": 1,
    "pages": 33
}

Reference

Errors

Check ok first. When it is false, error.code is stable and safe to branch on; error.message is written for people.

CodeHTTPMeaning
unauthorized401The API key is missing, wrong or revoked.
forbidden_ip403The key has an IP allow-list and this request came from another IP.
rate_limited429More than 120 requests in a minute on this key. Wait and retry.
invalid_request422A field is missing or not valid. The message says which one.
sender_not_approved422The sender ID is not approved on your account.
insufficient_credits402Not enough credits for this send. Nothing was sent.
not_found404The message, campaign or giveaway does not exist on your account.
otp_invalid422The code is wrong.
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.
402Response
{
  "ok": false,
  "error": {
    "code": "insufficient_credits",
    "message": "Not enough credits. This needs 2,480 credits and you have 1,200."
  }
}

Webhooks

Add a webhook URL in Dashboard › API & webhooks and copy the signing secret. We POST a JSON body to your URL when something happens. Reply with any 2xx status within 6 seconds.

EventWhen
campaign.finishedEvery number in a campaign has been sent or has failed. Includes totals and credits used.
message.deliveredThe network confirms a message reached the phone.
balance.lowYour credits drop below the alert level you set.
giveaway.entrySomeone enters one of your giveaways.

Every call has these headers:

  • X-BestSMS-Event: the event name
  • X-BestSMS-Signature: sha256= followed by the hex HMAC-SHA256 of the raw request body, keyed with your secret

Compute the HMAC over the raw body before parsing it, and compare with a constant-time function.

POST /your/webhook
X-BestSMS-Event: campaign.finished
X-BestSMS-Signature: sha256=5d1c0f...

{
  "event": "campaign.finished",
  "time": "2026-12-01T09:34:12+05:30",
  "data": {
    "campaign_id": 18342,
    "status": "done",
    "total": 2480,
    "sent": 2443,
    "failed": 37,
    "credits_used": 2443
  }
}

Ready to try it?

Create an account, request a sender ID and make a key. Your dashboard shows every API call's messages under Delivery reports.

Create free account