Send bulk SMS messaging campaigns and get status updates
For each Routee application you can enable a Callback, to receive Routee API responses for SMS or Campaign (Bulk) messages.
For the default values for each call to the API, you can read more here...
You can override defaults for a callback, by setting one callback url for a call.
In this guide, we will schedule a Bulk SMS message from MindPuzzle application to a list of recipients and get campaign status updates in our defined Application Callback URL.
HTTP REQUEST##
HEADERS
KEY | VALUE |
---|---|
Content-Type | application/json |
Authorization | Bearer {access_token} |
JSON BODY
{
"campaignCallback":{
"strategy":"OnCompletion",
"url":"http://www.yourserver.com/mindpuzzle/campaigns"
},
"callback": {
"strategy": "OnCompletion",
"url": "http://www.yourserver.com/message"
},
"body":"Welcome to MindPuzzle! Invite your friends and win special gifts. see more at http://my.link/url",
"campaignName":"Welcoming",
"to":[
"+30694xxxxxxxx",
"+35594xxxxxxxx",
"+44794xxxxxxxx",
"+30694xxxxxxxx",
"+22894xxxxxxxx",
"+32294xxxxxxxx"
],
"scheduledDate":"2017-01-23T09:00:01Z",
"from":"MindPuzzle"
}
Welcome to MindPuzzle! Invite your friends and win special gifts. See more at http://my.link/url
This message will be sent to 6 international recipients on Jan 23, 2017 at 09:00:01 UTC
Two callback URL's have been setup in MindPuzzle Application to receive status updates for message delivery and campaign completion.
The http://www.yourserver.com/mindpuzzle/campaigns URL will receive the final delivery status for the campaign.
The http://www.yourserver.com/message URL will receive final status updates for each recipient.
SAMPLE CODE##
curl --request POST \
--url https://connect.routee.net/sms/campaign \
--header 'authorization: Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4' \
--header 'content-type: application/json' \
--data '{
"campaignCallback":{
"strategy":"OnCompletion",
"url":"http://www.yourserver.com/mindpuzzle/campaigns"
},
"callback": {
"strategy": "OnCompletion",
"url": "http://www.yourserver.com/message"
}, "body":"Welcome to MindPuzzle! Invite your friends and win special gifts. see more in http://my.link/url", "campaignName":"Welcoming",
"to":[
"+30694xxxxxxxx",
"+35594xxxxxxxx",
"+44794xxxxxxxx",
"+30694xxxxxxxx",
"+22894xxxxxxxx",
"+32294xxxxxxxx"
], "scheduledDate":"2017-01-23T09:00:01Z", "from":"MindPuzzle"
}'
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType,
"{\"campaignCallback\":{\"strategy\":\"OnCompletion\",\"url\":\"http://www.yourserver.com/mindpuzzle/campaigns\"}, \"callback\": {\"strategy\": \"OnCompletion\", \"url\": \"http://www.yourserver.com/message\"},
\"body\":\"Welcome to MindPuzzle! Invite your friends and win special gifts. see more in http://my.link/url\", \"campaignName\":\"Welcoming\", \"to\":[\"+30694xxxxxxxx\", \"+35594xxxxxxxx\",\"+44794xxxxxxxx\",
\"+30694xxxxxxxx\",\"+22894xxxxxxxx\", \"+32294xxxxxxxx\" ], \"scheduledDate\":\"2017-01-23T09:00:01Z\", \"from\":\"MindPuzzle\"}");
Request request = new Request.Builder()
.url("https://connect.routee.net/sms/campaign")
.post(body)
.addHeader("authorization", "Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4")
.addHeader("content-type", "application/json")
.build();
Response response = client.newCall(request).execute();
var client = new RestClient("https://connect.routee.net/sms/campaign");
var request = new RestRequest(Method.POST);
request.AddHeader("content-type", "application/json");
request.AddHeader("authorization", "Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4");
request.AddParameter("application/json", "{\"campaignCallback\":{\"strategy\":\"OnCompletion\",\"url\":\"http://www.yourserver.com/mindpuzzle/campaigns\"}, \"callback\": {\"strategy\": \"OnCompletion\", \"url\": \"http://www.yourserver.com/message\"},
\"body\":\"Welcome to MindPuzzle! Invite your friends and win special gifts. see more in http://my.link/url\", \"campaignName\":\"Welcoming\", \"to\":[\"+30694xxxxxxxx\", \"+35594xxxxxxxx\",\"+44794xxxxxxxx\",
\"+30694xxxxxxxx\",\"+22894xxxxxxxx\", \"+32294xxxxxxxx\" ], \"scheduledDate\":\"2017-01-23T09:00:01Z\", \"from\":\"MindPuzzle\"}");
IRestResponse response = client.Execute(request);
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://connect.routee.net/sms/campaign",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"campaignCallback\":{\"strategy\":\"OnCompletion\",\"url\":\"http://www.yourserver.com/mindpuzzle/campaigns\"}, \"callback\": {\"strategy\": \"OnCompletion\", \"url\": \"http://www.yourserver.com/message\"},
\"body\":\"Welcome to MindPuzzle! Invite your friends and win special gifts. see more in http://my.link/url\", \"campaignName\":\"Welcoming\",
\"to\":[\"+30694xxxxxxxx\", \"+35594xxxxxxxx\",\"+44794xxxxxxxx\", \"+30694xxxxxxxx\",\"+22894xxxxxxxx\", \"+32294xxxxxxxx\" ], \"scheduledDate\":\"2017-01-23T09:00:01Z\", \"from\":\"MindPuzzle\"}",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
import http.client
conn = http.client.HTTPSConnection("connect.routee.net")
payload = "{\"campaignCallback\":{\"strategy\":\"OnCompletion\",\"url\":\"http://www.yourserver.com/mindpuzzle/campaigns\"}, \"callback\": {\"strategy\": \"OnCompletion\", \"url\": \"http://www.yourserver.com/message\"},
\"body\":\"Welcome to MindPuzzle! Invite your friends and win special gifts. see more in http://my.link/url\", \"campaignName\":\"Welcoming\", \"to\":[\"+30694xxxxxxxx\", \"+35594xxxxxxxx\",\"+44794xxxxxxxx\",
\"+30694xxxxxxxx\",\"+22894xxxxxxxx\", \"+32294xxxxxxxx\" ], \"scheduledDate\":\"2017-01-23T09:00:01Z\", \"from\":\"MindPuzzle\"}"
headers = {
'authorization': "Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4",
'content-type': "application/json"
}
conn.request("POST", "/sms/campaign", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
require 'uri'
require 'net/http'
url = URI("https://connect.routee.net/sms/campaign")
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"] = 'Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4'
request["content-type"] = 'application/json'
request.body = "{\"campaignCallback\":{\"strategy\":\"OnCompletion\",\"url\":\"http://www.yourserver.com/mindpuzzle/campaigns\"}, \"callback\": {\"strategy\": \"OnCompletion\", \"url\": \"http://www.yourserver.com/message\"},
\"body\":\"Welcome to MindPuzzle! Invite your friends and win special gifts. see more in http://my.link/url\", \"campaignName\":\"Welcoming\", \"to\":[\"+30694xxxxxxxx\", \"+35594xxxxxxxx\",\"+44794xxxxxxxx\",
\"+30694xxxxxxxx\",\"+22894xxxxxxxx\", \"+32294xxxxxxxx\" ], \"scheduledDate\":\"2017-01-23T09:00:01Z\", \"from\":\"MindPuzzle\"}"
response = http.request(request)
puts response.read_body
var settings = {
"async": true,
"crossDomain": true,
"url": "https://connect.routee.net/sms/campaign",
"method": "POST",
"headers": {
"authorization": "Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4",
"content-type": "application/json"
},
"processData": false,
"data": "{\"campaignCallback\":{\"strategy\":\"OnCompletion\",\"url\":\"http://www.yourserver.com/mindpuzzle/campaigns\"}, \"callback\": {\"strategy\": \"OnCompletion\", \"url\": \"http://www.yourserver.com/message\"},
\"body\":\"Welcome to MindPuzzle! Invite your friends and win special gifts. see more in http://my.link/url\", \"campaignName\":\"Welcoming\", \"to\":[\"+30694xxxxxxxx\", \"+35594xxxxxxxx\",\"+44794xxxxxxxx\",
\"+30694xxxxxxxx\",\"+22894xxxxxxxx\", \"+32294xxxxxxxx\" ], \"scheduledDate\":\"2017-01-23T09:00:01Z\", \"from\":\"MindPuzzle\"}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
#import <Foundation/Foundation.h>
NSDictionary *headers = @{ @"authorization": @"Bearer 12dc9fe4-7df4-4786-8d7a-a46d307687f4",
@"content-type": @"application/json" };
NSDictionary *parameters = @{ @"campaignCallback":@{@"strategy":@"OnCompletion",@"url":@"http://www.yourserver.com/mindpuzzle/campaigns"}, @"callback": @{@"strategy": @"OnCompletion", @"url": @"http://www.yourserver.com/message"},
@"body@":@"Welcome to MindPuzzle! Invite your friends and win special gifts. see more in http://my.link/url", @"campaignName":@"Welcoming", @"to":[@"+30694xxxxxxxx", @"+35594xxxxxxxx",@"+44794xxxxxxxx",
@"+30694xxxxxxxx",@"+22894xxxxxxxx", @"+32294xxxxxxxx" ], @"scheduledDate":@"2017-01-23T09:00:01Z", @"from@":@"MindPuzzle" };
NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://connect.routee.net/sms/campaign"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
Validation Error
If the HTTP response has 400 status code, with "code":"400005000", then your SMS campaign contains invalid data, specified in "errors" array.
008 errorCode indicates that some recipients are invalid (either a mobile number in "to" array, a contact, or inside a group).
In order to send your campaign, try to exclude these invalid recipients (remove them from the selected group, "to" or "contacts" array) and send again the HTTP request.
You can find the invalid numbers as "property" in "errors" array, with "errorCode":008.
To get more information for sending bulk SMS check out our Resource Reference
Updated over 6 years ago