Professional Documents
Culture Documents
{
"username": "abc@example.com",
"password": "abc@123"
}
"accessToken":"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzdXBlckBteWxpbmV4LmNvbSIsInR5cGUiOiJhY
2Nlc3NUb2tlbiIsImV4cCI6MTYyOTIyMzM0NiwiaWF0IjoxNjI5MjIyNzQ2fQ.QefL26z2LKOeVX9awXjQaji
bL9MhzE4XjXqwaQ-ypWSXYbsSptn6wHIHcROtbh5P34MTORpZh98yykBQ298Fkw",
"refreshToken":"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzdXBlckBteWxpbmV4LmNvbSIsInR5cGUiOiJy
ZWZyZXNoVG9rZW4iLCJleHAiOjE2MjkzMDkxNDYsImlhdCI6MTYyOTIyMjc0Nn0.VUtAnwdSjsMesxs90lw39
GvYOLK8QY_cyHiFmYzYGtiX9AtCk1SmvWgn2-lh-5EgWJit6gRssHbeQvH-rqF5RA"
}
You can use the access token to access the send SMS API and the refresh token to renew the access
token when expired.
OAuth 2.0 Token Renew
This endpoint is used to renew the access token required to access the send SMS API, using the refresh
token provided at the login. The refresh token is sent in the header (Authorization: Bearer [refresh token]).
Request URL :: https://bsms.hutch.lk/api/token/accessToken
{
"accessToken":
"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJzdXBlckBteWxpbmV4LmNvbSIsInR5cGUiOiJhY2Nlc3NUb2tlbiI
sImV4cCI6MTYyOTIyMzM0NiwiaWF0IjoxNjI5MjIyNzQ2fQ.QefL26z2LKOeVX9awXjQajibL9MhzE4XjXqwa
Q-ypWSXYbsSptn6wHIHcROtbh5P34MTORpZh98yykBQ298Fkw"
}
If you receive HTTP error code 401 (Unauthorized) for the token renew API request, you should call the
login API to retrieve a fresh set of access and refresh tokens.
{
"campaignName": "Test campaign",
"mask": "Test",
"numbers": "94780000000",
"content": "Test message"
}
{
"serverRef": 32225
}
If you receive HTTP error code 401 (Unauthorized) for the send SMS API request, you should call the
token renew API to retrieve a fresh access token.
If the delivery report required need to enable the delivery Report Request field in the Body of send sms
as true
"mask": "Test",
"numbers": "94780000000",
"deliveryReportRequest": true,
function login(){
global $config_file;
$post_data = array("username"=>"test@test.com","password"=>"testtest");
$ch = curl_init('https://bsms.hutch.lk/api/login');
curl_setopt_array($ch, array(
'Content-Type: application/json',
'Accept: */*',
'X-API-VERSION: v1'
),
));
$response = curl_exec($ch);
die(curl_error($ch));
}
$responseData = json_decode($response, TRUE);
curl_close($ch);
//echo $responseData['published'];
$ch = curl_init('https://bsms.hutch.lk/api/sendsms');
curl_setopt_array($ch, array(
'Content-Type: application/json',
'Accept: */*',
'X-API-VERSION: v1',
),
));
$response = curl_exec($ch);
Sample VB6 Code ::
Option Explicit
Debug.Print sendSms("test", "Test", "947xxxxxxx", "This is a test message from the Bulk SMSC, using VB")
End Sub
Close
tokenFile = "E:\path\token.txt"
userName = "test@test.com"
password = "testpwd"
End Sub
Public Function sendSms(campaignName As String, mask As String, numbers As String, content As String) As String
init
ss = readTokenFile()
accessToken = ss(0)
refreshToken = ss(1)
Call login
ss = readTokenFile()
accessToken = ss(0)
refreshToken = ss(1)
Exit Function
End If
End If
End Function
Private Function callSmsApi(campaignName As String, mask As String, numbers As String, content As String) As String
URL = "https://bsms.hutch.lk/api/sendsms"
json = "{" _
& Chr(34) & "campaignName" & Chr(34) & ":" & Chr(34) & campaignName & Chr(34) & "," _
& Chr(34) & "mask" & Chr(34) & ":" & Chr(34) & mask & Chr(34) & "," _
& Chr(34) & "numbers" & Chr(34) & ":" & Chr(34) & numbers & Chr(34) & "," _
& Chr(34) & "content" & Chr(34) & ":" & Chr(34) & content & Chr(34) & _
"}"
Debug.Print json
With hCon
.Send json
callSmsApi = .ResponseText
End With
End Function
URL = "https://bsms.hutch.lk/api/login"
json = "{" _
& Chr(34) & "username" & Chr(34) & ":" & Chr(34) & userName & Chr(34) & "," _
& Chr(34) & "password" & Chr(34) & ":" & Chr(34) & password & Chr(34) & _
"}"
Debug.Print json
With hCon
.Send json
response = .ResponseText
End With
response = makePretty(response)
Debug.Print response
writeTokenFile response
End Sub
strFileContent = Input(LOF(1), 1)
Close #1
'Debug.Print strFileContent
a = Split(strFileContent, ",")
a(0) = strip(a(0))
a(1) = strip(a(1))
b = Split(a(0), ":")
ss(0) = b(1)
c = Split(a(1), ":")
ss(1) = c(1)
readTokenFile = ss
Exit Function
fileErr:
ss(0) = "error"
ss(1) = "error"
readTokenFile = ss
End Function
strip = x
End Function
makePretty = x
End Function
Close #2
End Function