Text.lk offers two simple methods to send OTPs via SMS:
- Sending OTP as a Normal SMS (Message Type: ‘plain’) • You generate the OTP on your end, store it in your database, and send it as a regular SMS.
• Example SMS:
“Your ABC app OTP is 245634”
• When the customer submits the OTP, you validate it against your stored OTP.
Learn More about Sending OTP as a Normal SMS
- Generating OTP via Text.lk API (Message Type: ‘otp’) • Let Text.lk generate the OTP for you!
• Use the shortcode {{OTPx}} in your message, where x represents the OTP length (4, 5, 6, 7, or 8).
• Example API request:
• If you send:
“Your ABC app OTP is {{OTP5}}”
• The customer will receive:
“Your ABC app OTP is 45645”
• The generated OTP will also be available in the API response under response[‘data’][‘otp’].
Quick Guide to Sending OTP via API:
1. Set ‘type’ as ‘otp’.
2. Use the OTP shortcode in your message:
• {{OTP4}} → 4-digit OTP
• {{OTP5}} → 5-digit OTP
• {{OTP6}} → 6-digit OTP (default)
• {{OTP7}}, {{OTP8}} → 7 or 8-digit OTP
3. Example messages:
• “Your SuperApp verification code is: {{OTP5}}”
• “Your Handy OTP code is: {{OTP6}}”
4. Once sent, the API response will contain the generated OTP under response[‘data’][‘otp’].
Example request to send Text.lk OTP SMS
curl -X POST https://app.text.lk/api/v3/sms/send \
-H 'Authorization: Bearer API_KEY' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"recipient":"94710000000",
"sender_id":"TextLKDemo",
"type":"otp",
"message":"Your SuperApp verification code is: {{OTP5}}"
}'
HTTP
Example response from Text.lk after sending Text.lk OTP SMS
{
"status": "success",
"message": "Your message was successfully delivered",
"data": {
"uid": "xxxxxxxxxxxxx",
"to": "94710000000",
"from": "TextLKDemo",
"message": "Your SuperApp verification code is: 12345",
"status": "Delivered",
"cost": "1",
"sms_count": 1,
"otp": 12345
}
}
HTTP
This method ensures a seamless, automated OTP generation process with secure delivery.