0% found this document useful (0 votes)
49 views

SPRL Sample API Document

This document provides code samples for making API calls to send SMS messages using different programming languages including PHP, Java, C#, C, Python, Ruby, NodeJS, JavaScript, and cURL. The API allows sending promotional, transactional, and quick transactional SMS via a REST API in a secure and easy to integrate manner. Sample requests are shown to illustrate how to authenticate with a client key and send messages by specifying parameters like client ID, sender ID, mobile number, message text, and scheduling details.

Uploaded by

samsunga332029
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

SPRL Sample API Document

This document provides code samples for making API calls to send SMS messages using different programming languages including PHP, Java, C#, C, Python, Ruby, NodeJS, JavaScript, and cURL. The API allows sending promotional, transactional, and quick transactional SMS via a REST API in a secure and easy to integrate manner. Sample requests are shown to illustrate how to authenticate with a client key and send messages by specifying parameters like client ID, sender ID, mobile number, message text, and scheduling details.

Uploaded by

samsunga332029
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Phone : 080 49771424, +91 8088948172

Email : [email protected]

Authored by: SPRL Team

1
SMS API
API Calls in different languages

Our Bulk SMS API work with PHP, JAVA, C#, C, Python, Ruby, JavaScript, NodeJS, cURL,
etc. Secure, robust and easy to integrate APIs to send Promotional, Transactional &
Quick Transactional SMS via REST API. Check SMS API requests.

PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://insprl.com/api/sms/send-msg");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array( 'Authorization: {CLIENT_KEY}'
));
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(
array(
'client_id' => '{CLIENT_ID}',
'sender_id' => '{6_CHAR_SENDER_ID}',
'msgtype' => 'txn',
'mobile' => '9999999999',
'message' => 'Hi Customer, This is an alert Message',
'schedule_date' => '03-02-2020',
'schedule_time' => '13:20',
'unicode' => 0,
'flash' => 0,
'campaign_name' => 'My campaign 2020 Jan',
)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close ($ch);

2
JAVA
HttpResponse response = Unirest.post("https://insprl.com/api/sms/send-msg")
.header("Authorization", "{CLIENT_KEY}")
.header("Content-Type", "application/x-www-form-urlencoded")

.body("clientid={CLIENT_ID}&sender_id={6_CHAR_SENDER_ID}&mobile=9999999999&message=Hi%2
0Customer%20This%20is%20an%20alert%20Message&schedule_date=03-02-
2020&schedule_time=13:20&unicode=0&flash=0&campaign_name=My%20campaign%202020%20Ja
n")
.asString();

3
C#
var client = new RestClient("https://insprl.com/api/sms/send-msg");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddHeader("Authorization", "{CLIENT_KEY}");
request.AddParameter("clientid", "{CLIENT_ID}");
request.AddParameter("sender_id", "{6_CHAR_SENDER_ID}");
request.AddParameter("mobile", "9999999999");
request.AddParameter(message", "Hi Customer, This is an alert Message");
request.AddParameter(schedule_date", "03-02-2020");
request.AddParameter(schedule_time", "13:20");
request.AddParameter(unicode", "0");
request.AddParameter(flash", "0");
request.AddParameter("campaign_name", "My campaign 2020 Jan");
IRestResponse response = client.Execute(request);

4
C
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");


curl_easy_setopt(hnd, CURLOPT_URL, "https://insprl.com/api/sms/send-msg");

struct curl_slist *headers = NULL;


headers = curl_slist_append(headers, "content-type: application/x-www-form-urlencoded");
headers = curl_slist_append(headers, "Authorization: {CLIENT_KEY}");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS,
"clientid={CLIENT_ID}&sender_id={6_CHAR_SENDER_ID}&mobile=9999999999&message=Hi%20Cust
omer%20This%20is%20an%20alert%20Message&schedule_date=03-02-
2020&schedule_time=13:20&unicode=0&flash=0&campaign_name=My%20campaign%202020%20Ja
n");

CURLcode ret = curl_easy_perform(hnd);

5
Python
import requests

url = "https://insprl.com/api/sms/send-msg"

payload =
"clientid={CLIENT_ID}&sender_id={6_CHAR_SENDER_ID}&mobile=9999999999&message=Hi%20Cust
omer%20This%20is%20an%20alert%20Message&schedule_date=03-02-
2020&schedule_time=13:20&unicode=0&flash=0&campaign_name=My%20campaign%202020%20Ja
n"
headers = {
'Authorization': "{CLIENT_KEY}",
'Content-Type': "application/x-www-form-urlencoded",
'Cache-Control': "no-cache",
}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

6
Ruby
require 'uri'
require 'net/http'

url = URI("https://insprl.com/api/sms/send-msg")

http = Net::HTTP.new(url.host, url.port)


http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["Authorization"] = '{CLIENT_KEY}'
request.body =
"clientid={CLIENT_ID}&sender_id={6_CHAR_SENDER_ID}&mobile=9999999999&message=Hi
Customer This is an alert Message&schedule_date=03-02-
2020&schedule_time=13:20&unicode=0&flash=0&campaign_name=My campaign 2020 Jan"

response = http.request(request)
puts response.read_body

7
NodeJS
var unirest = require("unirest");

var req = unirest("POST", "https://insprl.com/api/sms/send-msg");

req.headers({
"Authorization": "{CLIENT_KEY}"
});

req.form({
"clientid": "{CLIENT_ID}",
"sender_id": "{6_CHAR_SENDER_ID}",
"mobile": "9999999999",=
"message": "Hi Customer, This is an alert Message",
"schedule_date": "03-02-2020",
"schedule_time": "13:20",
"unicode": "0",
"flash": "0",
"campaign_name": "My campaign 2020 Jan",
});

req.end(function (res) {
if (res.error) throw new Error(res.error);

console.log(res.body);
});

8
Javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "https://insprl.com/api/sms/send-msg",
"method": "POST",
"headers": {
"Authorization": "{CLIENT_KEY}",
},
"data": {
"clientid": "{CLIENT_ID}",
"sender_id": "{6_CHAR_SENDER_ID}",
"mobile": "9999999999",
"message": "Hi Customer, This is an alert Message",
"schedule_date": "03-02-2020",
"schedule_time": "13:20",
"unicode": "0",
"flash": "0",
"campaign_name": "My campaign 2020 Jan",
}
}

$.ajax(settings).done(function (response) {
console.log(response);
});

9
cURL
curl -X POST \
https://insprl.com/api/sms/send-msg \
-H 'Authorization: {CLIENT_KEY}' \
-d 'clientid={CLIENT_ID}&sender_id={6_CHAR_SENDER_ID}&mobile=9999999999&message=Hi
Customer This is an alert Message&schedule_date=03-02-
2020&schedule_time=13:20&unicode=0&flash=0&campaign_name=My campaign 2020 Jan'

Thank you!

Visit: www.insprl.com

10

You might also like