SMSnet Rest API - Introduction
Welcome to the SMSnet API documentation!
The API is divided into subsections, which are briefly described below. For details about each section, please refer to the respective section.
Quick start: Full Examples: This section contains code examples that are ready to be copied and pasted in your favorite editor or IDE, and are ready to be executed! Just type in your username and password and you’re ready to go.
Authentication: This section describes how to authenticate requests to the SMSnet API. All API methods require authentication.
User: The following are utility functions regarding the Authenticated User (e.g. the user status, password reset, etc)
Contacts: This part of the API is used to manage contacts. A contact can be used both in SMS and Email sending, provided that a phone number and/or an email address are given.
Contacts Groups: This section describes how groups of contacts are created, updated and deleted. SMS messages and emails can be directly sent to groups of contacts.
TPOA: Here are described the methods to work with TPOA Aliases (Transmission Path Originating Address, i.e. the SMS Sender Alias). TPOA Aliases can be used only with some specific high quality SMS message types.
Sending SMS messages: This is the part of the API that allows to send SMS messages, to single recipients, saved contacts or groups of contacts.
SMS messages history: Used to retrieve the SMS messages sending history.
SMS Blacklist / Stop SMS: This section allow to insert and to retrieve the list of SMS blacklist / Stop SMS.
Subaccounting: If enabled as a superaccount, the user can create subaccounts that can be assigned to third-parties. Superaccounts may or may not share credits with their subaccounts.
Receiving SMS messages: The methods described in this section are used to retrieve the received SMS messages.
Email campaigns: This API exposes methods for creating and managing Email campaigns.
Two Factor authentication: This API provides the Two Factor Authentication via SMS.
Quick start: full examples
Send an SMS message: Full example
echo 'Full example not available for shell'
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
// This example requires Gson configured in the build path (for JSON support):
// https://github.com/google/gson
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Main {
public static final String BASEURL = "https://sms.smsnet.it/API/v1.0/REST/";
public static final String MESSAGE_HIGH_QUALITY = "N";
public static final String MESSAGE_MEDIUM_QUALITY = "L";
public static final String MESSAGE_LOW_QUALITY = "LL";
public static void main(String[] args) {
try {
String[] authKeys = login("UserParam{my_username}", "UserParam{my_password}");
SendSMSRequest sendSMS = new SendSMSRequest();
sendSMS.setMessage("Hello world!");
sendSMS.setMessageType(MESSAGE_HIGH_QUALITY);
sendSMS.addRecipient("+39123456789");
// Send it in 5 minutes!
sendSMS.setScheduledDeliveryTime(new Date(System.currentTimeMillis() + (60000L * 5L)));
sendSMS(authKeys, sendSMS);
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* This object is used to create an SMS message sending request.
* The JSon object is then automatically created starting from an instance
* of this class, using GSon.
*/
public static class SendSMSRequest {
/** The message body */
private String message;
/** The message type */
private String message_type = MESSAGE_HIGH_QUALITY;
/** Should the API return the remaining credits? */
private boolean returnCredits = false;
/** The list of recipients */
private List<String> recipient = new ArrayList<>();
/** The sender Alias (TPOA) */
private String sender = null;
/** Postpone the SMS message sending to the specified date */
private Date scheduled_delivery_time = null;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getMessageType() {
return message_type;
}
public void setMessageType(String messageType) {
this.message_type = messageType;
}
public boolean isReturnCredits() {
return returnCredits;
}
public void setReturnCredits(boolean returnCredits) {
this.returnCredits = returnCredits;
}
public List<String> getRecipient() {
return recipient;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public Date getScheduledDeliveryTime() {
return scheduled_delivery_time;
}
public void setScheduledDeliveryTime(Date scheduled_delivery_time) {
this.scheduled_delivery_time = scheduled_delivery_time;
}
public void addRecipient(String recipient) {
this.recipient.add(recipient);
}
}
/**
* This class represents the API Response. It is automatically created starting
* from the JSON object returned by the server, using GSon
*/
public static class SendSMSResponse {
private String result;
private String order_id;
private int total_sent;
private int remaining_credits;
private String internal_order_id;
public String getResult() {
return result;
}
public String getOrderId() {
return order_id;
}
public int getTotalSent() {
return total_sent;
}
public int getRemainingCredits() {
return remaining_credits;
}
public String getInternalOrderId() {
return internal_order_id;
}
public boolean isValid() {
return "OK".equals(result);
}
}
/**
* Authenticates the user given it's username and password.
* Returns the pair user_key, Session_key
* @param username The user username
* @param password The user password
* @return A list with 2 strings. Index 0 is the user_key, index 1 is the Session_key
* @throws IOException If an error occurs
*/
private static String[] login(String username, String password) throws IOException {
URL url = new URL(BASEURL + "/login?username=" + username + "&password=" + password);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
conn.disconnect();
String[] parts = response.split(";");
return parts;
}
/**
* Sends an SMS message
* @param authKeys The pair of user_key and Session_key
* @param sendSMS The SendSMS object
* @throws IOException If an error occurs
*/
private static boolean sendSMS(String[] authKeys, SendSMSRequest sendSMS) throws IOException {
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
URL url = new URL(BASEURL + "/sms");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// Sending an SMS requires authentication
conn.setRequestProperty("user_key", authKeys[0]);
conn.setRequestProperty("Session_key", authKeys[1]);
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = gson.toJson(sendSMS);
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
conn.disconnect();
SendSMSResponse responseObj = gson.fromJson(response, SendSMSResponse.class);
return responseObj.isValid();
}
}
<?php
define("BASEURL", "https://sms.smsnet.it/API/v1.0/REST/");
define("MESSAGE_HIGH_QUALITY", "N");
define("MESSAGE_MEDIUM_QUALITY", "L");
define("MESSAGE_LOW_QUALITY", "LL");
/**
* Authenticates the user given it's username and password.
* Returns the pair user_key, Session_key
*/
function login($username, $password) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, BASEURL .
'login?username=' . $username .
'&password=' . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
return null;
}
return explode(";", $response);
}
/**
* Sends an SMS message
*/
function sendSMS($auth, $sendSMS) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, BASEURL . 'sms');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: ' . $auth[0],
'Session_key: ' . $auth[1]
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($sendSMS));
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
return null;
}
return json_decode($response);
}
$auth = login('UserParam{my_username}', 'UserParam{my_password}');
$smsSent = sendSMS($auth, array(
"message" => "Hello world!",
"message_type" => MESSAGE_HIGH_QUALITY,
"returnCredits" => false,
"recipient" => array("+349123456789"),
"sender" => null, // Place here a custom sender if desired
"scheduled_delivery_time" => date('YmdHi', strtotime("+5 minutes")), // postpone by 5 minutes
));
if ($smsSent->result == "OK") {
echo 'SMS sent!';
}
?>
# pip install requests
import requests
import json
import sys
import datetime
BASEURL = "https://sms.smsnet.it/API/v1.0/REST/"
MESSAGE_HIGH_QUALITY = "N"
MESSAGE_MEDIUM_QUALITY = "L"
MESSAGE_LOW_QUALITY = "LL"
def json_serial(obj):
"""JSON serializer for objects not serializable by default json code"""
if isinstance(obj, datetime.datetime):
serial = obj.isoformat()
return serial
raise TypeError ("Type not serializable")
def login(username, password):
"""Authenticates the user given it's username and password. Returns a
couple (user_key, session_key)
"""
r = requests.get("%slogin?username=%s&password=%s"
% (BASEURL, username, password))
if r.status_code != 200:
return None
user_key, session_key = r.text.split(';')
return user_key, session_key
def sendSMS(auth, sendsms):
"""Sends an SMS"""
headers = { 'user_key': auth[0],
'Session_key': auth[1],
'Content-type' : 'application/json' }
r = requests.post("%ssms" % BASEURL,
headers=headers,
data=json.dumps(sendsms, default=json_serial))
if r.status_code != 201:
return None
return json.loads(r.text)
if __name__ == "__main__":
auth = login("UserParam{my_username}", "UserParam{my_password}")
if not auth:
print("Unable to login..")
sys.exit(-1)
sentSMS = sendSMS(auth,
{
"message" : "Hello world!",
"message_type" : MESSAGE_HIGH_QUALITY,
"returnCredits" : False,
"recipient": ["+349123456789",],
# Place here a custom sender if desired
"sender": None,
# Postpone the SMS sending by 5 minutes
"scheduled_delivery_time" : (datetime.datetime.now() +
datetime.timedelta(minutes=5))
})
if sentSMS['result'] == "OK":
print("SMS sent!")
var BASEURL = 'https://sms.smsnet.it/API/v1.0/REST/';
var MESSAGE_HIGH_QUALITY = "N";
var MESSAGE_MEDIUM_QUALITY = "L";
var MESSAGE_LOW_QUALITY = "LL";
var request = require('request');
/**
* Authenticates the user given it's username and password. Callback
* is called when completed. If error is false, then an authentication
* object is passed to the callback as second parameter.
*/
function login(username, password, callback) {
request({
url: BASEURL + 'login?username=' + username + '&password=' + password,
method: 'GET',
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
var auth = response.split(';');
callback(error, {
user_key : auth[0],
session_key : auth[1]
});
}
else {
callback(error);
}
}
});
}
/**
* Sends an SMS message
*/
function sendSMS(auth, sendsms, callback) {
request({
url: BASEURL + 'sms',
method: 'POST',
headers: { 'user_key' : auth.user_key, 'Session_key' : auth.session_key },
json: true,
body: sendsms,
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
callback(response.result !== 'OK', response);
}
else {
callback(false);
}
}
});
}
var smsData = {
"returnCredits": true,
"recipient": [
"+393471234567",
"+393471234568"
],
"scheduled_delivery_time": "20171223101010",
"message": "Hello world!",
"message_type": MESSAGE_HIGH_QUALITY
}
login('UserParam{my_username}', 'UserParam{my_password}',
function(error, auth) {
if (!error) {
sendSMS(auth, smsData,
function(error, data) {
if (error) {
console.log("An error occurred");
}
else {
console.log("SMS Sent!");
}
});
}
else {
console.log("Unable to login");
}
});
require 'net/http'
require 'uri'
require 'json'
BASEURL = "https://sms.smsnet.it/API/v1.0/REST/"
MESSAGE_HIGH_QUALITY = "N"
MESSAGE_MEDIUM_QUALITY = "L"
MESSAGE_LOW_QUALITY = "LL"
# Authenticates the user given it's username and password. Returns a
# couple (user_key, session_key)
def login(username, password)
uri = URI.parse(BASEURL + "login?username=" + username + "&password=" + password)
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
return responseData.body.split(';')
end
return None
end
# Sends an SMS
def sendSMS(auth, sendSMS)
uri = URI.parse(BASEURL + "sms")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = auth[0]
request['Session_key'] = auth[1]
request.body = sendSMS.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
return JSON.parse(responseData.body)
else
return None
end
end
####################
# Main
auth = login('UserParam{my_username}', 'UserParam{my_password}')
if not auth
puts "Unable to login"
else
response = sendSMS(auth,
{
"returnCredits": true,
"recipient": [
"+393471234567",
"+393471234568"
],
"message": "Hello world!",
"message_type": MESSAGE_HIGH_QUALITY,
})
if response['result'] == 'OK'
puts "SMS Sent!"
else
puts "An error occurred"
end
end
using System;
using System.Text;
using System.Net;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
public static String BASEURL = "https://sms.smsnet.it/API/v1.0/REST/";
public static String MESSAGE_HIGH_QUALITY = "N";
public static String MESSAGE_MEDIUM_QUALITY = "L";
public static String MESSAGE_LOW_QUALITY = "LL";
static void Main(string[] args)
{
String[] auth = authenticate("UserParam{my_username}", "UserParam{my_password}");
SendSMS sendSMSRequest = new SendSMS();
sendSMSRequest.message = "Hello World!";
sendSMSRequest.message_type = MESSAGE_HIGH_QUALITY;
sendSMSRequest.recipient = new String[] {"+39349123456789"};
// Send the SMS message at the given date (Optional)
sendSMSRequest.scheduled_delivery_time = new DateTime(2017, 8, 18, 13, 31, 00);
SMSSent smsSent = sendSMS(auth, sendSMSRequest);
if ("OK".Equals(smsSent.result)) {
Console.WriteLine("SMS successfully sent!");
}
}
/**
* Authenticates the user given it's username and
* password. Returns a couple (user_key, session_key)
*/
static String[] authenticate(String username, String password)
{
String[] auth = null;
using (var wb = new WebClient())
{
var response = wb.DownloadString(BASEURL +
"login?username=" + username +
"&password=" + password);
auth = response.Split(';');
}
return auth;
}
/**
* Sends an SMS
*/
static SMSSent sendSMS(String[] auth, SendSMS sendSMS)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", auth[0]);
wb.Headers.Add("Session_key", auth[1]);
String json = JsonConvert.SerializeObject(sendSMS);
var sentSMSBody =
wb.UploadString(BASEURL + "sms", "POST", json);
SMSSent sentSMSResponse =
JsonConvert.DeserializeObject<SMSSent>(sentSMSBody);
return sentSMSResponse;
}
}
}
/**
* This object is used to create an SMS message sending request.
* The JSon object is then automatically created starting from an
* instance of this class, using JSON.NET.
*/
class SendSMS
{
/** The message body */
public String message;
/** The message type */
public String message_type;
/** The sender Alias (TPOA) */
public String sender;
/** Postpone the SMS message sending to the specified date */
public DateTime? scheduled_delivery_time;
/** The list of recipients */
public String[] recipient;
/** Should the API return the remaining credits? */
public Boolean returnCredits = false;
}
/**
* This class represents the API Response. It is automatically created starting
* from the JSON object returned by the server, using GSon
*/
class SMSSent
{
/** The result of the SMS message sending */
public String result;
/** The order ID of the SMS message sending */
public String order_id;
/** The actual number of sent SMS messages */
public int total_sent;
/** The remaining credits */
public int remaining_credits;
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use LWP::UserAgent;
use constant BASEURL => "https://sms.smsnet.it/API/v1.0/REST/";
use constant MESSAGE_HIGH_QUALITY => "N";
use constant MESSAGE_MEDIUM_QUALITY => "L";
use constant MESSAGE_LOW_QUALITY => "LL";
sub authenticate($$$) {
my ($ua, $username, $password) = @_;
$username = uri_escape($username);
$password = uri_escape($password);
my $server_endpoint = BASEURL . "login?username=$username&password=$password";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content-type' => 'application/json');
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my ($user_key, $session_key) = $response =~ /(.*);(.*)/;
return [$user_key, $session_key];
}
}
sub send_sms($$$) {
my ($ua, $auth, $sendsms) = @_;
my $server_endpoint = BASEURL . "sms";
my $req = HTTP::Request->new(POST => $server_endpoint);
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header('Content_type' => 'application/json',
':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
$req->content(to_json($sendsms));
my $resp = $ua->request($req);
if ($resp->is_success) {
return from_json($resp->decoded_content);
}
}
my $ua = LWP::UserAgent->new;
my $auth = authenticate($ua, "UserParam{my_username}", "UserParam{my_password}");
die ("Unable to authenticate\n") unless ($auth);
my $sendsms = {
"message" => "Hello world!",
"message_type" => MESSAGE_HIGH_QUALITY,
"recipient" => ["+39349123456789"],
};
my $smssent = send_sms($ua, $auth, $sendsms);
print "SMS successfully sent!\n" if ($smssent->{"result"} eq "OK");
You can start by copying this example and you’ll be up and running for sending an SMS message to multiple recipients in just a few clicks!
Just change the UserParam{my_username} and UserParam{my_password} strings, add a valid
recipient list and execute the code!
The listed example authenticates the user using username and password with the Authentication API and then sends an SMS calling the Send SMS API.
Authentication API
Authentication methods
The following are the two available methods to authenticate a user, given a username and a password (registration required):
Using a temporary session key, which expires after a certain amount of time has passed with no performed API calls with that key.
Using an authentication token, which does not expire, except when an account is deactivated or suspended.
In both cases, the returned user_key, as well as the session key or the token, are required to be provided in the HTTP request headers in order to perform any API call after the login.
Authenticate using a session key
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/login?username=UserParam{my_username}&password=UserParam{my_password}' -H 'Content-Type: application/json'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/login?username=UserParam{my_username}&password=UserParam{my_password}' -H 'Content-Type: application/json'
# pip install requests
import requests
import json
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/login?username=UserParam{my_username}&password=UserParam{my_password}")
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
user_key, session_key = response.split(';')
print("user_key: " + user_key)
print("Session_key: " + session_key)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/login?username=UserParam{my_username}&password=UserParam{my_password}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
String[] parts = response.split(";");
String user_key = parts[0];
String session_key = parts[1];
System.out.println("user_key: " + user_key);
System.out.println("Session_key: " + session_key);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/login?username=UserParam{my_username}&password=UserParam{my_password}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$values = explode(";", $response);
echo('user_key: ' . $values[0]);
echo('Session_key: ' . $values[1]);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/login?username=UserParam{my_username}&password=UserParam{my_password}',
method: 'GET',
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
var arr = response.split(';');
console.log("user_key: " + arr[0]);
console.log("Session_key: " + arr[1]);
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/login?username=UserParam{my_username}&password=UserParam{my_password}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
user_key, session_key = response.split(';')
puts "user_key: " + user_key
puts "Session_key: " + session_key
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/login?username=UserParam{my_username}&password=UserParam{my_password}");
String[] auth = response.Split(';');
Console.WriteLine("user_key: " + auth[0]);
Console.WriteLine("Session_key: " + auth[1]);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/login?username=".uri_escape("UserParam{my_username}")."&password=".uri_escape("UserParam{my_password}")."";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my ($user_key, $session_key) = $response =~ /(.*);(.*)/;
print "user_key: $user_key\n";
print "Session_key: $session_key\n";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
USER_KEY;SESSION_KEY
Where USER_KEY is the user key and SESSION_KEY is the session key
The login with session key API lets you authenticate by using your username and password, and returns a token to be used for authenticating the next API calls. The following HTTP headers should be provided after the login:
user_key:UserParam{USER_KEY}
Session_key:UserParam{SESSION_KEY}
Where UserParam{USER_KEY} and UserParam{SESSION_KEY} are the values returned by the
login API.
HTTP Request
GET /API/v1.0/REST/login?username=UserParam{my_username}&password=UserParam{my_password}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| username | String | Your account’s username | Yes | - |
| password | String | Your account’s password | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | The user_key and the session_key |
| 404 | [Not found] Credentials are incorrect |
| 400 | Other errors, details are in the body |
Authenticate using a user token
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/token?username=UserParam{my_username}&password=UserParam{my_password}' -H 'Content-Type: application/json'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/token?username=UserParam{my_username}&password=UserParam{my_password}' -H 'Content-Type: application/json'
# pip install requests
import requests
import json
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/token?username=UserParam{my_username}&password=UserParam{my_password}")
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
user_key, access_token = response.split(';')
print("user_key: " + user_key)
print("Access_token: " + access_token)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/token?username=UserParam{my_username}&password=UserParam{my_password}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
String[] parts = response.split(";");
String user_key = parts[0];
String access_token = parts[1];
System.out.println("user_key: " + user_key);
System.out.println("Access_token: " + access_token);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/token?username=UserParam{my_username}&password=UserParam{my_password}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$values = explode(";", $response);
echo('user_key: ' . $values[0]);
echo('Access_token: ' . $values[1]);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/token?username=UserParam{my_username}&password=UserParam{my_password}',
method: 'GET',
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
var arr = response.split(';');
console.log("user_key: " + arr[0]);
console.log("Access_token: " + arr[1]);
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/token?username=UserParam{my_username}&password=UserParam{my_password}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
user_key, access_token = response.split(';')
puts "user_key: " + user_key
puts "Access_token: " + access_token
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/token?username=UserParam{my_username}&password=UserParam{my_password}");
String[] auth = response.Split(';');
Console.WriteLine("user_key: " + auth[0]);
Console.WriteLine("Access_token: " + auth[1]);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/token?username=".uri_escape("UserParam{my_username}")."&password=".uri_escape("UserParam{my_password}")."";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my ($user_key, $access_token) = $response =~ /(.*);(.*)/;
print "user_key: $user_key\n";
print "Access_token: $access_token\n";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
USER_KEY;ACCESS_TOKEN
Where USER_KEY is the user key and ACCESS_TOKEN is the access token
The login with token API lets you authenticate by using your username and password, and returns a token to be used for authenticating the next API calls. The following HTTP headers should be provided after the login:
user_key:UserParam{USER_KEY}
Access_token:UserParam{ACCESS_TOKEN}
Where UserParam{USER_KEY} and UserParam{ACCESS_TOKEN} are the values returned by the
login API.
HTTP Request
GET /API/v1.0/REST/token?username=UserParam{MY_USERNAME}&password=UserParam{MY_PASSWORD}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| username | String | Your account’s username | Yes | - |
| password | String | Your account’s password | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | The user_key and the access token |
| 404 | [Not found] Credentials are incorrect |
| 400 | Other errors, details are in the body |
User API
The following are utility functions regarding the Authenticated User (e.g. the user status, password reset, etc)
Dashboard
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/dashboard' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/dashboard' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/dashboard", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
print(response)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/dashboard");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
System.out.println(response);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/dashboard');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo($response);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/dashboard',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log(response);
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/dashboard")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts response
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/dashboard");
Console.WriteLine(response);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/dashboard";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
https://sms.smsnet.it/API/v1.0/REST//s/user/external-auth?k=07366A25DF70038A22B9D284AB13E856BD95C6227&action=FC07AD201AE372F378&action-params=7010AB
API used to retrieve the dashboard URL of the authenticated user
HTTP Request
GET /API/v1.0/REST/dashboard
Returns
| Code | Description |
|---|---|
| 200 | Returns the URL for the user’s dashboard |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 400 | Other errors, details are in the body |
Verify session
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/checksession' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/checksession' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/checksession", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
print("Is session valid: " + str(response == "true"))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/checksession");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
System.out.println("Is session valid: " + ("true".equals(response)));
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/checksession');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Is session valid: ' . ($response === "true"));
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/checksession',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Is session valid: ' + (response == "true"));
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/checksession")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Is session valid " + response
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/checksession");
Console.WriteLine("Is session valid: " + response);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/checksession";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
"true" or "false"
Checks whether the user session is still active and valid (without renewal).
HTTP Request
GET /API/v1.0/REST/checksession
Returns
| Code | Description |
|---|---|
| 200 | String “true” if the session is valid, “false” otherwise. |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 400 | Other errors, details are in the body |
Reset password
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/pwdreset?password=UserParam{new_password}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/pwdreset?password=UserParam{new_password}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/pwdreset?password=UserParam{new_password}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
print("Password changed: " + str(response == "true"))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/pwdreset?password=UserParam{new_password}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
System.out.println("Password changed: " + ("true".equals(response)));
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/pwdreset?password=UserParam{new_password}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Password changed: ' . ($response === "true"));
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/pwdreset?password=UserParam{new_password}',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Password changed: ' + (response == "true"));
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/pwdreset?password=UserParam{new_password}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Password changed " + response
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/pwdreset?password=UserParam{new_password}", "POST", null);
Console.WriteLine("Password changed: " + response);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/pwdreset?password=".uri_escape("UserParam{new_password}")."";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
"true" or "false"
Changes the authenticated user’s password
HTTP Request
POST /API/v1.0/REST/pwdreset?password=UserParam{PWD}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| password | String | The new user password | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | String “true” on success, “false” otherwise |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] User key does not exist |
User status
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/status' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/status' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/status", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/status");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/status');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/status',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/status")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/status");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/status";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"money": null,
"sms": [
{
"type": "LL",
"quantity": 16079
},
{
"type": "L",
"quantity": 11815
},
{
"type": "N",
"quantity": 10407
},
{
"type": "EE",
"quantity": 10387
}
],
"email": {
"bandwidth": 2000.0,
"purchased": "2015-01-16",
"billing": "EMAILPERHOUR",
"expiry": "2016-01-17"
},
"landing": null
}
Used to retrieve the credits and other information of the user identified by the id.
HTTP Request
GET /API/v1.0/REST/status?getMoney=UserParam{value}&typeAliases=UserParam{value}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| getMoney | String “true” or “false” | Add user current money to response | No | “false” |
| typeAliases | String “true” or “false” | Returns the actual names for the message types instead of the internal ID. This is not done by default only because of retrocompatibility issues. | No, but suggested | “false” |
Returns
| Code | Description |
|---|---|
| 200 | A Json object representing the user status |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] Credentials are incorrect |
Contacts API
This part of the API is used to manage contacts. A contact can be used both in SMS and Email sending, provided that a phone number and/or an email address are given.
Add a contact
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contact' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}",
"gender": "UserParam{GENDER}",
"fax": "UserParam{FAX}",
"zip": "UserParam{ZIP}",
"address": "UserParam{ADDRESS}",
"city": "UserParam{CITY}",
"province": "UserParam{PROVINCE}",
"birthdate": "UserParam{BIRTHDATE}",
"groupIds": [
"UserParam{GRP1}",
"UserParam{GRP2}"
]
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contact' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}",
"gender": "UserParam{GENDER}",
"fax": "UserParam{FAX}",
"zip": "UserParam{ZIP}",
"address": "UserParam{ADDRESS}",
"city": "UserParam{CITY}",
"province": "UserParam{PROVINCE}",
"birthdate": "UserParam{BIRTHDATE}",
"groupIds": [
"UserParam{GRP1}",
"UserParam{GRP2}"
]
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}",
"gender": "UserParam{GENDER}",
"fax": "UserParam{FAX}",
"zip": "UserParam{ZIP}",
"address": "UserParam{ADDRESS}",
"city": "UserParam{CITY}",
"province": "UserParam{PROVINCE}",
"birthdate": "UserParam{BIRTHDATE}",
"groupIds": [
"UserParam{GRP1}",
"UserParam{GRP2}"
]
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/contact", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/contact");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"email\": \"UserParam{EMAIL}\", " +
" \"phoneNumber\": \"UserParam{PHONENUMBER}\", " +
" \"name\": \"UserParam{NAME}\", " +
" \"surname\": \"UserParam{SURNAME}\", " +
" \"gender\": \"UserParam{GENDER}\", " +
" \"fax\": \"UserParam{FAX}\", " +
" \"zip\": \"UserParam{ZIP}\", " +
" \"address\": \"UserParam{ADDRESS}\", " +
" \"city\": \"UserParam{CITY}\", " +
" \"province\": \"UserParam{PROVINCE}\", " +
" \"birthdate\": \"UserParam{BIRTHDATE}\", " +
" \"groupIds\": [" +
" \"UserParam{GRP1}\", " +
" \"UserParam{GRP2}\"" +
" ]" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "email": "UserParam{EMAIL}", ' .
' "phoneNumber": "UserParam{PHONENUMBER}", ' .
' "name": "UserParam{NAME}", ' .
' "surname": "UserParam{SURNAME}", ' .
' "gender": "UserParam{GENDER}", ' .
' "fax": "UserParam{FAX}", ' .
' "zip": "UserParam{ZIP}", ' .
' "address": "UserParam{ADDRESS}", ' .
' "city": "UserParam{CITY}", ' .
' "province": "UserParam{PROVINCE}", ' .
' "birthdate": "UserParam{BIRTHDATE}", ' .
' "groupIds": [' .
' "UserParam{GRP1}", ' .
' "UserParam{GRP2}"' .
' ]' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/contact');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/contact',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}",
"gender": "UserParam{GENDER}",
"fax": "UserParam{FAX}",
"zip": "UserParam{ZIP}",
"address": "UserParam{ADDRESS}",
"city": "UserParam{CITY}",
"province": "UserParam{PROVINCE}",
"birthdate": "UserParam{BIRTHDATE}",
"groupIds": [
"UserParam{GRP1}",
"UserParam{GRP2}"
]
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/contact")
payload = {
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}",
"gender": "UserParam{GENDER}",
"fax": "UserParam{FAX}",
"zip": "UserParam{ZIP}",
"address": "UserParam{ADDRESS}",
"city": "UserParam{CITY}",
"province": "UserParam{PROVINCE}",
"birthdate": "UserParam{BIRTHDATE}",
"groupIds": [
"UserParam{GRP1}",
"UserParam{GRP2}"
]
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"email\": \"UserParam{EMAIL}\", " +
" \"phoneNumber\": \"UserParam{PHONENUMBER}\", " +
" \"name\": \"UserParam{NAME}\", " +
" \"surname\": \"UserParam{SURNAME}\", " +
" \"gender\": \"UserParam{GENDER}\", " +
" \"fax\": \"UserParam{FAX}\", " +
" \"zip\": \"UserParam{ZIP}\", " +
" \"address\": \"UserParam{ADDRESS}\", " +
" \"city\": \"UserParam{CITY}\", " +
" \"province\": \"UserParam{PROVINCE}\", " +
" \"birthdate\": \"UserParam{BIRTHDATE}\", " +
" \"groupIds\": [" +
" \"UserParam{GRP1}\", " +
" \"UserParam{GRP2}\"" +
" ]" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/contact", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/contact";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"email" => "UserParam{EMAIL}",
"phoneNumber" => "UserParam{PHONENUMBER}",
"name" => "UserParam{NAME}",
"surname" => "UserParam{SURNAME}",
"gender" => "UserParam{GENDER}",
"fax" => "UserParam{FAX}",
"zip" => "UserParam{ZIP}",
"address" => "UserParam{ADDRESS}",
"city" => "UserParam{CITY}",
"province" => "UserParam{PROVINCE}",
"birthdate" => "UserParam{BIRTHDATE}",
"groupIds" => [
"UserParam{GRP1}",
"UserParam{GRP2}"
]
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the created contact:
'Location': '/contact/AVvZEwZHHnl8wUZve6CT'
Add a contact to the user’s addressbook.
HTTP Request
POST /API/v1.0/REST/contact
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| String (A valid email) | The email of the contact | Yes | - | |
| phoneNumber | String (A non empty string) | The phone number of the contact | Yes | “” |
| name | String (max 40 chars) | The first name of the contact | No | “” |
| surname | String (max 40 chars) | The last name of the contact | No | “” |
| gender | String (“m” or “f”) | The gender of the contact | No | “” |
| fax | String (max 32 chars) | The Fax number of the contact | No | “” |
| address | String (max 256 chars) | The address of the contact | No | “” |
| city | String (max 32 chars) | The city of the contact | No | “” |
| province | String (max 32 chars) | The province of the contact | No | “” |
| birthdate | String [ddMMyy, yyyyMMdd, ddMMyyHHmm, yyyyMMddHHmmss, yyyy-MM-dd HH:mm, yyyy-MM-dd HH:mm.0] | The birth date of the contact | No | “” |
| promotiondate | String [ddMMyy, yyyyMMdd, ddMMyyHHmm, yyyyMMddHHmmss, yyyy-MM-dd HH:mm, yyyy-MM-dd HH:mm.0] | An additional date field | No | “” |
| rememberdate | String [ddMMyy, yyyyMMdd, ddMMyyHHmm, yyyyMMddHHmmss, yyyy-MM-dd HH:mm, yyyy-MM-dd HH:mm.0] | An additional date field | No | “” |
| zip | String (max 16 chars) | The ZIP code of the contact | No | “” |
| groupIds | List(String) | The groups (Ids) in which the contact will be added | No | [] |
| custom1 | String | Custom field 1 | No | “” |
| custom2 | String | Custom field 2 | No | “” |
| custom3 | String | Custom field 3 | No | “” |
| custom4 | String | Custom field 4 | No | “” |
| custom5 | String | Custom field 5 | No | “” |
| custom6 | String | Custom field 6 | No | “” |
| custom7 | String | Custom field 7 | No | “” |
| custom8 | String | Custom field 8 | No | “” |
| custom9 | String | Custom field 9 | No | “” |
| custom10 | String | Custom field 10 | No | “” |
Returns
| Code | Description |
|---|---|
| 201 | Empty string, and the HTTP Location header containing the path of the newly created contact |
| 400 | Campaign not active or not found, no email provided, group not owned or a generic error. Details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Add multiple contacts
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contacts' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"contacts": [
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
},
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
}
],
"updateExistingContact": true
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contacts' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"contacts": [
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
},
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
}
],
"updateExistingContact": true
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"contacts": [
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
},
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
}
],
"updateExistingContact": true
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/contacts", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/contacts");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"contacts\": [" +
" {" +
" \"email\": \"UserParam{EMAIL}\", " +
" \"phoneNumber\": \"UserParam{PHONENUMBER}\", " +
" \"name\": \"UserParam{NAME}\", " +
" \"surname\": \"UserParam{SURNAME}\"" +
" }, " +
" {" +
" \"email\": \"UserParam{EMAIL}\", " +
" \"phoneNumber\": \"UserParam{PHONENUMBER}\", " +
" \"name\": \"UserParam{NAME}\", " +
" \"surname\": \"UserParam{SURNAME}\"" +
" }" +
" ], " +
" \"updateExistingContact\": true" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "contacts": [' .
' {' .
' "email": "UserParam{EMAIL}", ' .
' "phoneNumber": "UserParam{PHONENUMBER}", ' .
' "name": "UserParam{NAME}", ' .
' "surname": "UserParam{SURNAME}"' .
' }, ' .
' {' .
' "email": "UserParam{EMAIL}", ' .
' "phoneNumber": "UserParam{PHONENUMBER}", ' .
' "name": "UserParam{NAME}", ' .
' "surname": "UserParam{SURNAME}"' .
' }' .
' ], ' .
' "updateExistingContact": true' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/contacts');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/contacts',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"contacts": [
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
},
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
}
],
"updateExistingContact": true
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/contacts")
payload = {
"contacts": [
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
},
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONENUMBER}",
"name": "UserParam{NAME}",
"surname": "UserParam{SURNAME}"
}
],
"updateExistingContact": true
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"contacts\": [" +
" {" +
" \"email\": \"UserParam{EMAIL}\", " +
" \"phoneNumber\": \"UserParam{PHONENUMBER}\", " +
" \"name\": \"UserParam{NAME}\", " +
" \"surname\": \"UserParam{SURNAME}\"" +
" }, " +
" {" +
" \"email\": \"UserParam{EMAIL}\", " +
" \"phoneNumber\": \"UserParam{PHONENUMBER}\", " +
" \"name\": \"UserParam{NAME}\", " +
" \"surname\": \"UserParam{SURNAME}\"" +
" }" +
" ], " +
" \"updateExistingContact\": true" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/contacts", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/contacts";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"contacts" => [
{
"email" => "UserParam{EMAIL}",
"phoneNumber" => "UserParam{PHONENUMBER}",
"name" => "UserParam{NAME}",
"surname" => "UserParam{SURNAME}"
},
{
"email" => "UserParam{EMAIL}",
"phoneNumber" => "UserParam{PHONENUMBER}",
"name" => "UserParam{NAME}",
"surname" => "UserParam{SURNAME}"
}
],
"updateExistingContact" => true
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
2
Add multiple contacts to the user’s addressbook.
HTTP Request
POST /API/v1.0/REST/contacts
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| contacts | Json array of Contacts | Array of Json object, formatted as ADD a contact | Yes | “” |
| updateExistingContact | boolean | True to update existing contacts in case of clash, false to drop and insert them | No | false |
| keepExistingGroupsAndCampaigns | boolean | True to keep all old contact groups associations and campaigns subscription | No | false |
Returns
| Code | Description |
|---|---|
| 200 | Number of contacts correctly created |
| 400 | Campaign not active or not found, no email provided, group not owned or a generic error. Details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get a contact
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/contact/UserParam{contact_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/contact/UserParam{contact_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/contact/UserParam{contact_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/contact/UserParam{contact_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/contact/UserParam{contact_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/contact/UserParam{contact_id}',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/contact/UserParam{contact_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/contact/UserParam{contact_id}");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/contact/UserParam{contact_id}";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"email":"alessandro.magno@macedonia.com",
"phoneNumber":"+39349123456789",
"name": "Alessandro",
"surname": "Magno",
"groupIds":[ ],
"gender":"m",
"fax":null,
"address":null,
"city":null,
"province":null,
"birthdate":"2017-05-11",
"zip":null
}
Get a contact’s details
HTTP Request
GET /API/v1.0/REST/contact/UserParam{contact_id}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| CONTACT_ID | String | The contact ID | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | The contact’s details |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The given CONTACT_ID was not found |
Registration of a contact to a list
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/contact' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONE_NUMBER}"
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/contact' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONE_NUMBER}"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONE_NUMBER}"
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/contact", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/contact");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"email\": \"UserParam{EMAIL}\", " +
" \"phoneNumber\": \"UserParam{PHONE_NUMBER}\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "email": "UserParam{EMAIL}", ' .
' "phoneNumber": "UserParam{PHONE_NUMBER}"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/contact');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/contact',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONE_NUMBER}"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/contact")
payload = {
"email": "UserParam{EMAIL}",
"phoneNumber": "UserParam{PHONE_NUMBER}"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"email\": \"UserParam{EMAIL}\", " +
" \"phoneNumber\": \"UserParam{PHONE_NUMBER}\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/contact", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/contact";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"email" => "UserParam{EMAIL}",
"phoneNumber" => "UserParam{PHONE_NUMBER}"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
""
Creates a new contact entry and adds it onto the specified campaign.
HTTP Request
POST /API/v1.0/REST/list/UserParam{campaign_id}/contact?SendOptIn=UserParam{value}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| campaign_id | Int | The campaign in which the contact will be added | Yes | - |
| SendOptIn | String, “true” or “false” | Send an Opt-In email to the contact’s email | No | “false” |
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| String | The email of the contact | Yes | - | |
| phoneNumber | String | The phone number of the contact | No | “” |
| name | String | The first name of the contact | No | “” |
| surname | String | The last name of the contact | No | “” |
| gender | String | The gender of the contact | No | “” |
| fax | String | The Fax number of the contact | No | “” |
| address | String | The address of the contact | No | “” |
| city | String | The city of the contact | No | “” |
| province | String | The province of the contact | No | “” |
| birthdate | String [ddMMyy, yyyyMMdd, ddMMyyHHmm, yyyyMMddHHmmss, yyyy-MM-dd HH:mm, yyyy-MM-dd HH:mm.0] | The birth date of the contact | No | “” |
| zip | String | The ZIP code of the contact | No | “” |
| groupIds | List(String) | The groups (Ids) in which the contact will be added | No | [] |
Returns
| Code | Description |
|---|---|
| 201 | The contact has been added and the HTTP Location Header returns its URL. |
| 400 | Campaign not active or not found, no email provided, group not owned or a generic error. Details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
List contact’s custom fields
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/contacts/fields' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/contacts/fields' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/contacts/fields", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/contacts/fields");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/contacts/fields');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/contacts/fields',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/contacts/fields")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/contacts/fields");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/contacts/fields";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
[
{
"idField": "{CUSTOM_KEY}",
"placeholder": "%{PLACEHOLDER_NAME}%",
"label": "{LABEL_OR_KEY_TO_BE_DISPLAYED}",
"dataType": "{STRING|INTEGER|DATE|EMAIL|BOOLEAN}"
}
]
Returns the list of user’s defined custom fields
HTTP Request
GET /API/v1.0/REST/contacts/fields
Returns
| Code | Description |
|---|---|
| 200 | Successful request |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
Add contact to sms blacklist
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}", "POST", null);
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
true
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| CONTACT_ID | String | The id of the contact that will be added | Yes | - |
Returns the result of operation
HTTP Request
POST /API/v1.0/REST/contact/add_to_blacklist/UserParam{contact_id}
Returns
| Code | Description |
|---|---|
| 200 | Successful request |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | Contact not found |
Add multiple contacts to sms blacklist
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist_batch' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
[
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
]
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist_batch' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
[
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
]
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """[
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
]"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist_batch", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist_batch");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "[" +
" \"AV3vrSlPuGYfQz6BgjeI\", " +
" \"BVvrSlPuGYfQz6BgjeI\"" +
"]";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '[' .
' "AV3vrSlPuGYfQz6BgjeI", ' .
' "BVvrSlPuGYfQz6BgjeI"' .
']';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist_batch');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist_batch',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: [
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
],
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist_batch")
payload = [
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
]
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "[" +
" \"AV3vrSlPuGYfQz6BgjeI\", " +
" \"BVvrSlPuGYfQz6BgjeI\"" +
"]";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist_batch", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/contact/add_to_blacklist_batch";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = [
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
];
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
2
Add multiple contacts to the user’s blacklist.
HTTP Request
POST /API/v1.0/REST/contact/add_to_blacklist_batch
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| — | List(String) | Array of contact ids | Yes | “” |
Returns
| Code | Description |
|---|---|
| 200 | Number of contacts correctly put in blacklist |
| 400 | Some of the contactsId specified were wrong |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Add phone number to sms blacklist
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=UserParam{phone_number}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=UserParam{phone_number}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=UserParam{phone_number}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=UserParam{phone_number}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=UserParam{phone_number}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=UserParam{phone_number}',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=UserParam{phone_number}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=UserParam{phone_number}", "POST", null);
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=".uri_escape("UserParam{phone_number}")."";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
true
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| phoneNumber | String | The phone number that will be added to blacklist | Yes | - |
Returns the result of operation
HTTP Request
POST /API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=UserParam{phone_number}
Returns
| Code | Description |
|---|---|
| 200 | Successful request |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
Contacts groups API
This section describes how groups of contacts are created, updated and deleted. SMS messages and emails can be directly sent to groups of contacts.
Create a contacts group
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/group' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/group' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/group", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/group");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"name\": \"UserParam{NAME}\", " +
" \"description\": \"UserParam{DESCRIPTION}\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "name": "UserParam{NAME}", ' .
' "description": "UserParam{DESCRIPTION}"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/group');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/group',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/group")
payload = {
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"name\": \"UserParam{NAME}\", " +
" \"description\": \"UserParam{DESCRIPTION}\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/group", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/group";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"name" => "UserParam{NAME}",
"description" => "UserParam{DESCRIPTION}"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the created group:
'Location': '/group/{group_id}'
Creates an empty group of contacts given a name and a description.
HTTP Request
POST /API/v1.0/REST/group
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| name | String | The name of the group | Yes | - |
| description | String | The description of the group | Yes | - |
Returns
| Code | Description |
|---|---|
| 201 | An empty string, and the HTTP Location header containing the path to the newly created group |
| 400 | If the group name is invalid, or other errors, with a code error |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] If the requesting user does not exist. |
Modify an existing contacts group
# Session Key example
curl -XPUT 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
}
'
# Access token example
curl -XPUT 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
}"""
r = requests.put("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("PUT");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"name\": \"UserParam{NAME}\", " +
" \"description\": \"UserParam{DESCRIPTION}\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "name": "UserParam{NAME}", ' .
' "description": "UserParam{DESCRIPTION}"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}',
method: 'PUT',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}")
payload = {
"name": "UserParam{NAME}",
"description": "UserParam{DESCRIPTION}"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Put.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"name\": \"UserParam{NAME}\", " +
" \"description\": \"UserParam{DESCRIPTION}\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}", "PUT", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}";
my $req = HTTP::Request->new(PUT => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"name" => "UserParam{NAME}",
"description" => "UserParam{DESCRIPTION}"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the modified group:
'Location': '/group/{group_id}'
Updates a given contacts group
HTTP Request
PUT /API/v1.0/REST/group/UserParam{group_id}
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| name | String | The name of the group | Yes | - |
| description | String | The description of the group | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | An empty string, and the HTTP Location header containing the path to the updated group |
| 400 | If the given group_id is invalid, if the address book is locked, if the group name is invalid, or other errors, with a code error |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] If the requesting user does not exist. |
Delete a contacts group
# Session Key example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{groupid}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{groupid}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.delete("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{groupid}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{groupid}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("DELETE");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{groupid}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{groupid}',
method: 'DELETE',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{groupid}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
wb.UploadValues("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{groupid}", "DELETE", new NameValueCollection());
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/group/UserParam{groupid}";
my $req = HTTP::Request->new(DELETE => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
""
Deletes the contacts group identified by the given ID.
HTTP Request
GET /API/v1.0/REST/group/UserParam{group_id}?deletecontacts=UserParam{del}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| group_id | Int | The group ID to be deleted | Yes | - |
| deletecontacts | String “true” or “false” | If “true”, also deletes all contacts in the group | No | “false” |
Returns
| Code | Description |
|---|---|
| 200 | An empty string |
| 400 | If the given group_id is invalid, if the address book is locked, if the group name is invalid, or other errors, with a code error |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] Credentials are incorrect |
List contacts groups
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/groups' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/groups' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/groups", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/groups");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/groups');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/groups',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/groups")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/groups");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/groups";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"groups":[ "// The list of groups"
{
"id_group": (string), "// The ID of a group in the list"
"group_name": (string), "// The group name"
"group_description": (string) "// The group description"
},
{...} "// Other groups in the list (omitted..)"
],
"pageNumber": (int), "// Paging: The page number"
"pageSize": (int), "// Paging: The page size"
"Total": (int) "// Paging: The total number of groups"
}
Returns the list of existing contacts groups, paginated.
HTTP Request
GET /API/v1.0/REST/groups?pageNumber=UserParam{page}&pageSize=UserParam{size}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| pageNumber | int | The page number | No | 1 |
| pageSize | int | The page size | No | 5 |
Returns
| Code | Description |
|---|---|
| 200 | The paginated list of contacts groups, as a Json Object |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Add a contact to a group
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}", "POST", null);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the contact:
'Location': '/contact/UserParam{contact_id}'
Adds the specified contact in the specified contacts group.
HTTP Request
POST /API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| group_id | Int | The Contacts Group ID | Yes | - |
| contact_id | Int | The Contact ID | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | An empty string, and the HTTP Location header containing the URL of the contact |
| 400 | If contact_id is invalid, if the addressbook is locked or other. Details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Remove a contact from a group
# Session Key example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.delete("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("DELETE");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}',
method: 'DELETE',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
wb.UploadValues("https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}", "DELETE", new NameValueCollection());
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}";
my $req = HTTP::Request->new(DELETE => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the contact:
'Location': '/contact/{contact_id}'
Removes the specified contact from the specified contacts group.
HTTP Request
DELETE /API/v1.0/REST/group/UserParam{group_id}/contact/UserParam{contact_id}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| group_id | Int | The Contacts Group ID | Yes | - |
| contact_id | Int | The Contact ID | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | An empty string, and the HTTP Location header containing the URL of the contact |
| 400 | If contact_id is invalid, if the addressbook is locked or other. Details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
TPOA API
The TPOA (Transmission Path Originating Address) API is used to deal with TPOA entries (i.e. “SMS Sender aliases”) of the user.
Create a new alias
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/alias' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"alias": {
"alias": "MY ALIAS",
"company-name": "company name",
"contact-name": "name",
"contact-surname": "surname",
"cod-fiscale": "02367940224",
"vat-number": "02367940224",
"contact-address": "address",
"contact-city": "city",
"contact-pcode": "pcode",
"contact-type": "WEB",
"contact-info": "www.www.it"
}
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/alias' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"alias": {
"alias": "MY ALIAS",
"company-name": "company name",
"contact-name": "name",
"contact-surname": "surname",
"cod-fiscale": "02367940224",
"vat-number": "02367940224",
"contact-address": "address",
"contact-city": "city",
"contact-pcode": "pcode",
"contact-type": "WEB",
"contact-info": "www.www.it"
}
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"alias": {
"alias": "MY ALIAS",
"company-name": "company name",
"contact-name": "name",
"contact-surname": "surname",
"cod-fiscale": "02367940224",
"vat-number": "02367940224",
"contact-address": "address",
"contact-city": "city",
"contact-pcode": "pcode",
"contact-type": "WEB",
"contact-info": "www.www.it"
}
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/alias", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/alias");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"alias\": {" +
" \"alias\": \"MY ALIAS\", " +
" \"company-name\": \"company name\", " +
" \"contact-name\": \"name\", " +
" \"contact-surname\": \"surname\", " +
" \"cod-fiscale\": \"02367940224\", " +
" \"vat-number\": \"02367940224\", " +
" \"contact-address\": \"address\", " +
" \"contact-city\": \"city\", " +
" \"contact-pcode\": \"pcode\", " +
" \"contact-type\": \"WEB\", " +
" \"contact-info\": \"www.www.it\"" +
" }" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "alias": {' .
' "alias": "MY ALIAS", ' .
' "company-name": "company name", ' .
' "contact-name": "name", ' .
' "contact-surname": "surname", ' .
' "cod-fiscale": "02367940224", ' .
' "vat-number": "02367940224", ' .
' "contact-address": "address", ' .
' "contact-city": "city", ' .
' "contact-pcode": "pcode", ' .
' "contact-type": "WEB", ' .
' "contact-info": "www.www.it"' .
' }' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/alias');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/alias',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"alias": {
"alias": "MY ALIAS",
"company-name": "company name",
"contact-name": "name",
"contact-surname": "surname",
"cod-fiscale": "02367940224",
"vat-number": "02367940224",
"contact-address": "address",
"contact-city": "city",
"contact-pcode": "pcode",
"contact-type": "WEB",
"contact-info": "www.www.it"
}
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/alias")
payload = {
"alias": {
"alias": "MY ALIAS",
"company-name": "company name",
"contact-name": "name",
"contact-surname": "surname",
"cod-fiscale": "02367940224",
"vat-number": "02367940224",
"contact-address": "address",
"contact-city": "city",
"contact-pcode": "pcode",
"contact-type": "WEB",
"contact-info": "www.www.it"
}
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"alias\": {" +
" \"alias\": \"MY ALIAS\", " +
" \"company-name\": \"company name\", " +
" \"contact-name\": \"name\", " +
" \"contact-surname\": \"surname\", " +
" \"cod-fiscale\": \"02367940224\", " +
" \"vat-number\": \"02367940224\", " +
" \"contact-address\": \"address\", " +
" \"contact-city\": \"city\", " +
" \"contact-pcode\": \"pcode\", " +
" \"contact-type\": \"WEB\", " +
" \"contact-info\": \"www.www.it\"" +
" }" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/alias", "POST", payload);
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/alias";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"alias" => {
"alias" => "MY ALIAS",
"company-name" => "company name",
"contact-name" => "name",
"contact-surname" => "surname",
"cod-fiscale" => "02367940224",
"vat-number" => "02367940224",
"contact-address" => "address",
"contact-city" => "city",
"contact-pcode" => "pcode",
"contact-type" => "WEB",
"contact-info" => "www.www.it"
}
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response, plus the HTTP Location header pointing to the created alias
{
"result": "OK"
}
If getAlias is true instead, the following is returned:
{
"result": "OK",
"string": "MY ALIAS"
}
Creates a new TPOA Alias.
HTTP Request
POST /API/v1.0/REST/alias
Body Fields
The body must contain a Json with a JsonObject field named alias that contains all the alias info:
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| alias | String | The sender that will be shown on SMS | Yes | |
| company-name | String | The name of company associated to this alias | Yes | |
| contact-name | String | The name of physical person rappresenting the company | Yes | |
| contact-surname | String | The surname of physical person rappresenting the company | Yes | |
| cod-fiscale | String | The fiscal code of company | Yes | |
| vat-number | String | The vat number of company | Yes | |
| contact-address | String | The address of company | Yes | |
| contact-city | String | The city of company | Yes | |
| contact-pcode | String | The ZIP/Postal-code/CAP code of company | Yes | |
| contact-type | String enum(SERVICE_PHONE, MAIN_PHONE, FAX, EMAIL, PEC, WEB) | The type of contact referred to contact-info | Yes | |
| contact-info | String | The value of contact | Yes |
Returns
| Code | Description |
|---|---|
| 200 | Successful request |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get all aliases
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/alias' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/alias' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/alias", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/alias");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/alias');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/alias',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/alias")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/alias");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/alias";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"alias": [
{
"contact-surname": "Dallago",
"notification-time": "20140704124747",
"cod-fiscale": "01843020221",
"alias-state": 3,
"contact-city": "Trento",
"id-alias": 36,
"contact-pcode": "38122",
"vat-number": "01843020221",
"alias": "Alias123",
"company-name": "SMSnet",
"contact-type": "FAX",
"contact-info": "024113727142",
"contact-name": "Stefano",
"is-numeric": false,
"contact-address": "Via Segantini 23"
},
{
"contact-surname": "Dallago",
"notification-time": "20161123155102",
"cod-fiscale": "01843020221",
"alias-state": 2,
"contact-city": "Trento",
"id-alias": 662,
"contact-pcode": "38122",
"vat-number": "03843020821",
"alias": "Alias234",
"company-name": "SMSnet",
"contact-type": "FAX",
"contact-info": "04317378142",
"contact-name": "Stefano",
"is-numeric": false,
"contact-address": "Via Segantini 23"
}
],
"total": 2,
"pageNumber": 1,
"result": "OK",
"pageSize": 10
}
Returns a paginated list of the user’s TPOA aliases.
HTTP Request
GET /API/v1.0/REST/alias?pageNumber=UserParam{page}&pageSize=UserParam{size}&hide-not-approved=UserParam{value}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| pageNumber | Int | Return the given results page | No | 1 |
| pageSize | Int | The number of results in a page | No | 10 |
| hide-not-approved | Bool | Show or hide not-yet-approved aliases | No | false |
Returns
| Code | Description |
|---|---|
| 200 | The paginated list of the user’s TPOA aliases |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
The alias-state attribute in the returned objects represents the
status of the TPOA confirmation process. It can be one of the following:
| alias-state | Description |
|---|---|
| 0 | Unconfirmed |
| 1 | Confirmed by SMSnet |
| 2 | Confirmed by AGCOM |
| 3 | Blocked by SMSnet |
| 4 | Blocked by AGCOM |
| 9 | The Alias has been pre-confirmed by SMSnet |
Get a specific alias
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result":"OK",
"alias":{
"id-alias":35,
"alias":"+393458922223",
"notification-time":"20140704141759",
"alias-state":3,
"is-numeric":true,
"company-name":"aCompany",
"contact-name":null,
"contact-surname":null,
"cod-fiscale":"",
"vat-number":"",
"contact-address":null,
"contact-city":null,
"contact-pcode":null,
"contact-type":"123456789",
"contact-info":""
}
}
Returns the data of the given TPOA Alias ID.
HTTP Request
GET /API/v1.0/REST/alias/UserParam{alias_id}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| alias_id | Int | The alias ID | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | The requested TPOA Alias data |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The alias was not found |
The alias-state attribute in the returned object represents the
status of the TPOA confirmation process. It can be one of the following:
| alias-state | Description |
|---|---|
| 0 | Unconfirmed |
| 1 | Confirmed by SMSnet |
| 2 | Confirmed by AGCOM |
| 3 | Blocked by SMSnet |
| 4 | Blocked by AGCOM |
| 9 | The Alias has been pre-confirmed by SMSnet |
Remove an alias
# Session Key example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.delete("https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("DELETE");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}',
method: 'DELETE',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
wb.UploadValues("https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}", "DELETE", new NameValueCollection());
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/alias/UserParam{alias_id}";
my $req = HTTP::Request->new(DELETE => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result": "OK"
}
Deletes the given TPOA Alias.
HTTP Request
DELETE /API/v1.0/REST/alias/UserParam{alias_id}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| alias_id | Int | The alias ID | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | Alias successfully deleted |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The alias was not found |
SMS Send API
This is the part of the API that allows to send SMS messages, to single recipients, saved contacts or groups of contacts.
Send an SMS message
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/sms' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"+393471234567",
"+393471234568"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/sms' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"+393471234567",
"+393471234568"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"+393471234567",
"+393471234568"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/sms", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/sms");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"message_type\": \"UserParam{MESSAGE_TYPE}\", " +
" \"message\": \"Hello world!\", " +
" \"recipient\": [" +
" \"+393471234567\", " +
" \"+393471234568\"" +
" ], " +
" \"sender\": \"MySender\", " +
" \"scheduled_delivery_time\": \"20161223101010\", " +
" \"order_id\": \"123456789\", " +
" \"returnCredits\": true" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "message_type": "UserParam{MESSAGE_TYPE}", ' .
' "message": "Hello world!", ' .
' "recipient": [' .
' "+393471234567", ' .
' "+393471234568"' .
' ], ' .
' "sender": "MySender", ' .
' "scheduled_delivery_time": "20161223101010", ' .
' "order_id": "123456789", ' .
' "returnCredits": true' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/sms');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/sms',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"+393471234567",
"+393471234568"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/sms")
payload = {
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"+393471234567",
"+393471234568"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"message_type\": \"UserParam{MESSAGE_TYPE}\", " +
" \"message\": \"Hello world!\", " +
" \"recipient\": [" +
" \"+393471234567\", " +
" \"+393471234568\"" +
" ], " +
" \"sender\": \"MySender\", " +
" \"scheduled_delivery_time\": \"20161223101010\", " +
" \"order_id\": \"123456789\", " +
" \"returnCredits\": true" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/sms", "POST", payload);
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/sms";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"message_type" => "UserParam{MESSAGE_TYPE}",
"message" => "Hello world!",
"recipient" => [
"+393471234567",
"+393471234568"
],
"sender" => "MySender",
"scheduled_delivery_time" => "20161223101010",
"order_id" => "123456789",
"returnCredits" => true
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result" : "OK", "//OK or errors"
"order_id" : "123456789",
"total_sent" : 2 "//SMS sent or credits used"
}
Sends an SMS message to a given list of recipients.
Landing Pages URLs
It is possible to include a link to a published Landing Page by
specifying the id_landing parameter and by adding the following
placeholder in the message body: %PAGESLINK____________%.
Landing pages must be first created and published in your user
panel, since you will need id_landing to send it.
A list of published landing pages can be retrieved by using the Landing Pages APIs
Short URLs
When including URLs in the message, it may be convinient to use short URLs to limit the number of characters used in the SMS message.
Our API can automatically generate a short link starting from a long one, and add it in the message.
To use this feature, use the %SHORT_LINK% placeholder in the
message body, that will be replaced with the generated short link, and
the respective short_link_url parameter, that should be set to a
valid URL. For shortlink dns personalization please contact
us at servizio.clienti@smsnet.it
Sender Alias
Alphanumeric aliases require to be registered first, and need to be approved both from Us and AGCOM.
Aliases can be used only with high-quality message types.
HTTP Request
POST /API/v1.0/REST/sms
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| message_type | String (“N” for High quality with reception notification, “L” for Medium Quality, “LL” For Low Cost) | The type of SMS. | Yes | - |
| message | String (max 1000 chars with “gsm” encoding, 450 with “ucs2” encoding) | The body of the message. *Message max length could be 160 chars when using low-quality SMSs | Yes | - |
| recipient | List(String) | A list of recipents phone numbers | Yes | - |
| sender | String | The Sender name. If the message type allows a custom TPOA and the field is left empty, the user’s preferred TPOA is used. Must be empty if the message type does not allow a custom TPOA | No | “” |
| scheduled_delivery_time | String [ddMMyy, yyyyMMdd, ddMMyyHHmm, yyyyMMddHHmmss, yyyy-MM-dd HH:mm, yyyy-MM-dd HH:mm.0] | The messages will be sent at the given scheduled time | No | null |
| scheduled_delivery_timezone | Timezone(IANA time zone) | Optional timezone applied to scheduled_delivery_time date |
No | - |
| order_id | String (max 32 chars, accepts only any letters, numbers, underscore, dot and dash) | Specifies a custom order ID | No | Generated UUID |
| returnCredits | Bool | Returns the number of credits used instead of the number of messages. i.e. when message is more than 160 chars long more than one credit is used | No | “false” |
| returnRemaining | Bool | Returs the number of remaining SMSs | No | false |
| allowInvalidRecipients | Bool | Sending to an invalid recipient does not block the operation | No | false |
| encoding | String (“gsm” or “ucs2”) | The SMS encoding. Use UCS2 for non standard character sets | No | “gsm” |
| id_landing | int | The id of the published page. Also add the %PAGESLINK____________% placeholder in the message body |
No | - |
| campaign_name | String | The campaign name | No | - |
| short_link_url | String | The url where the short link redirects. Also add the %SHORT_LINK% placeholder in the message body |
No | - |
Returns
| Code | Description |
|---|---|
| 201 | SMSs have been scheduled for delivery. |
| 400 | Invalid input. Details are in the response body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Send a parametric SMS message
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/paramsms' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello ${name}, welcome to ${nation}",
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true,
"allowInvalidRecipients": false,
"returnRemaining": true,
"recipients": {
"0": {
"recipient": "+393471234567",
"name": "Mark",
"nation": "Germany"
},
"1": {
"recipient": "+393477654321",
"name": "John",
"nation": "Alabama"
}
}
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/paramsms' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello ${name}, welcome to ${nation}",
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true,
"allowInvalidRecipients": false,
"returnRemaining": true,
"recipients": {
"0": {
"recipient": "+393471234567",
"name": "Mark",
"nation": "Germany"
},
"1": {
"recipient": "+393477654321",
"name": "John",
"nation": "Alabama"
}
}
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello ${name}, welcome to ${nation}",
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true,
"allowInvalidRecipients": false,
"returnRemaining": true,
"recipients": {
"0": {
"recipient": "+393471234567",
"name": "Mark",
"nation": "Germany"
},
"1": {
"recipient": "+393477654321",
"name": "John",
"nation": "Alabama"
}
}
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/paramsms", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/paramsms");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"message_type\": \"UserParam{MESSAGE_TYPE}\", " +
" \"message\": \"Hello ${name}, welcome to ${nation}\", " +
" \"sender\": \"MySender\", " +
" \"scheduled_delivery_time\": \"20161223101010\", " +
" \"order_id\": \"123456789\", " +
" \"returnCredits\": true, " +
" \"allowInvalidRecipients\": false, " +
" \"returnRemaining\": true, " +
" \"recipients\": {" +
" \"0\": {" +
" \"recipient\": \"+393471234567\", " +
" \"name\": \"Mark\", " +
" \"nation\": \"Germany\"" +
" }, " +
" \"1\": {" +
" \"recipient\": \"+393477654321\", " +
" \"name\": \"John\", " +
" \"nation\": \"Alabama\"" +
" }" +
" }" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "message_type": "UserParam{MESSAGE_TYPE}", ' .
' "message": "Hello ${name}, welcome to ${nation}", ' .
' "sender": "MySender", ' .
' "scheduled_delivery_time": "20161223101010", ' .
' "order_id": "123456789", ' .
' "returnCredits": true, ' .
' "allowInvalidRecipients": false, ' .
' "returnRemaining": true, ' .
' "recipients": {' .
' "0": {' .
' "recipient": "+393471234567", ' .
' "name": "Mark", ' .
' "nation": "Germany"' .
' }, ' .
' "1": {' .
' "recipient": "+393477654321", ' .
' "name": "John", ' .
' "nation": "Alabama"' .
' }' .
' }' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/paramsms');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/paramsms',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello ${name}, welcome to ${nation}",
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true,
"allowInvalidRecipients": false,
"returnRemaining": true,
"recipients": {
"0": {
"recipient": "+393471234567",
"name": "Mark",
"nation": "Germany"
},
"1": {
"recipient": "+393477654321",
"name": "John",
"nation": "Alabama"
}
}
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/paramsms")
payload = {
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello ${name}, welcome to ${nation}",
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true,
"allowInvalidRecipients": false,
"returnRemaining": true,
"recipients": {
"0": {
"recipient": "+393471234567",
"name": "Mark",
"nation": "Germany"
},
"1": {
"recipient": "+393477654321",
"name": "John",
"nation": "Alabama"
}
}
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"message_type\": \"UserParam{MESSAGE_TYPE}\", " +
" \"message\": \"Hello ${name}, welcome to ${nation}\", " +
" \"sender\": \"MySender\", " +
" \"scheduled_delivery_time\": \"20161223101010\", " +
" \"order_id\": \"123456789\", " +
" \"returnCredits\": true, " +
" \"allowInvalidRecipients\": false, " +
" \"returnRemaining\": true, " +
" \"recipients\": {" +
" \"0\": {" +
" \"recipient\": \"+393471234567\", " +
" \"name\": \"Mark\", " +
" \"nation\": \"Germany\"" +
" }, " +
" \"1\": {" +
" \"recipient\": \"+393477654321\", " +
" \"name\": \"John\", " +
" \"nation\": \"Alabama\"" +
" }" +
" }" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/paramsms", "POST", payload);
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/paramsms";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"message_type" => "UserParam{MESSAGE_TYPE}",
"message" => "Hello ${name}, welcome to ${nation}",
"sender" => "MySender",
"scheduled_delivery_time" => "20161223101010",
"order_id" => "123456789",
"returnCredits" => true,
"allowInvalidRecipients" => false,
"returnRemaining" => true,
"recipients" => {
"0" => {
"recipient" => "+393471234567",
"name" => "Mark",
"nation" => "Germany"
},
"1" => {
"recipient" => "+393477654321",
"name" => "John",
"nation" => "Alabama"
}
}
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result" : "OK", "//OK or errors"
"order_id" : "123456789",
"total_sent" : 2 "//SMS sent or credits used"
}
Sends a parametric SMS message to a given list of recipients. With this API it is possible to put placeholders in the message body, and then, for each recipient, specify the values that will replace the placeholders in the message body, for that particular recipient message.
Placeholders are in the form ${ParameterName}
Landing Pages URLs
It is possible to include a link to a published Landing Page by
specifying the id_landing parameter and by adding the following
placeholder in the message body: %PAGESLINK____________%.
Landing pages must be first created and published in your user
panel, since you will need id_landing to send it.
A list of published landing pages can be retrieved by using the Landing Pages APIs
Short URLs
When including URLs in the message, it may be convinient to use short URLs to limit the number of characters used in the SMS message.
Our API can automatically generate a short link starting from a long one, and add it in the message.
To use this feature, use the %SHORT_LINK% placeholder in the
message body, that will be replaced with the generated short link, and
the respective short_link_url parameter, that should be set to a
valid URL. For shortlink dns personalization please contact
us at servizio.clienti@smsnet.it
Sender Alias
Alphanumeric aliases require to be registered first, and need to be approved both from Us and AGCOM.
Aliases can be used only with high-quality message types.
HTTP Request
POST /API/v1.0/REST/paramsms
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| message_type | String (“N” for High quality with reception notification, “L” for Medium Quality, “LL” For Low Cost) | The type of SMS. | Yes | - |
| message | String (max 1000 chars with “gsm” encoding, 450 with “ucs2” encoding) | The body of the message. *Message max length could be 160 chars when using low-quality SMSs | Yes | - |
| recipients | Map(String, Map(String, String)) | A map of recipents and relative parameters | Yes | - |
| sender | String | The Sender name. If the message type allows a custom TPOA and the field is left empty, the user’s preferred TPOA is used. Must be empty if the message type does not allow a custom TPOA | No | “” |
| scheduled_delivery_time | String [ddMMyy, yyyyMMdd, ddMMyyHHmm, yyyyMMddHHmmss, yyyy-MM-dd HH:mm, yyyy-MM-dd HH:mm.0] | The messages will be sent at the given scheduled time | No | null |
| scheduled_delivery_timezone | Timezone(IANA time zone) | Optional timezone applied to scheduled_delivery_time date |
No | - |
| order_id | String (max 32 chars, accepts only any letters, numbers, underscore, dot and dash) | Specifies a custom order ID | No | Generated UUID |
| returnCredits | Bool | Returns the number of credits used instead of the number of messages. i.e. when message is more than 160 chars long more than one credit is used | No | false |
| returnRemaining | Bool | Returs the number of remaining SMSs | No | false |
| allowInvalidRecipients | Bool | Sending to an invalid recipient does not block the operation | No | false |
| encoding | String (“gsm” or “ucs2”) | The SMS encoding. Use UCS2 for non standard character sets | No | “gsm” |
| id_landing | int | The id of the published page. Also add the %PAGESLINK____________% placeholder in the message body |
No | - |
| campaign_name | String | The campaign name | No | - |
| short_link_url | String | The url where the short link redirects. Also add the %SHORT_LINK% placeholder in the message body |
No | - |
Returns
| Code | Description |
|---|---|
| 200 | SMS have been successfully sent. The order ID and some other informations are returned |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Send an SMS message to a group
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/smstogroups' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"group1",
"group2"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/smstogroups' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"group1",
"group2"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"group1",
"group2"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/smstogroups", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/smstogroups");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"message_type\": \"UserParam{MESSAGE_TYPE}\", " +
" \"message\": \"Hello world!\", " +
" \"recipient\": [" +
" \"group1\", " +
" \"group2\"" +
" ], " +
" \"sender\": \"MySender\", " +
" \"scheduled_delivery_time\": \"20161223101010\", " +
" \"order_id\": \"123456789\", " +
" \"returnCredits\": true" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "message_type": "UserParam{MESSAGE_TYPE}", ' .
' "message": "Hello world!", ' .
' "recipient": [' .
' "group1", ' .
' "group2"' .
' ], ' .
' "sender": "MySender", ' .
' "scheduled_delivery_time": "20161223101010", ' .
' "order_id": "123456789", ' .
' "returnCredits": true' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/smstogroups');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/smstogroups',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"group1",
"group2"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/smstogroups")
payload = {
"message_type": "UserParam{MESSAGE_TYPE}",
"message": "Hello world!",
"recipient": [
"group1",
"group2"
],
"sender": "MySender",
"scheduled_delivery_time": "20161223101010",
"order_id": "123456789",
"returnCredits": true
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"message_type\": \"UserParam{MESSAGE_TYPE}\", " +
" \"message\": \"Hello world!\", " +
" \"recipient\": [" +
" \"group1\", " +
" \"group2\"" +
" ], " +
" \"sender\": \"MySender\", " +
" \"scheduled_delivery_time\": \"20161223101010\", " +
" \"order_id\": \"123456789\", " +
" \"returnCredits\": true" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/smstogroups", "POST", payload);
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/smstogroups";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"message_type" => "UserParam{MESSAGE_TYPE}",
"message" => "Hello world!",
"recipient" => [
"group1",
"group2"
],
"sender" => "MySender",
"scheduled_delivery_time" => "20161223101010",
"order_id" => "123456789",
"returnCredits" => true
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result" : "OK", "//OK or errors"
"order_id" : "123456789",
"total_sent" : 2 "//SMS sent or credits used"
}
Send an SMS message to a set of contacts groups.
Landing Pages URLs
It is possible to include a link to a published Landing Page by
specifying the id_landing parameter and by adding the following
placeholder in the message body: %PAGESLINK____________%.
Landing pages must be first created and published in your user
panel, since you will need id_landing to send it.
A list of published landing pages can be retrieved by using the Landing Pages APIs
Short URLs
When including URLs in the message, it may be convinient to use short URLs to limit the number of characters used in the SMS message.
Our API can automatically generate a short link starting from a long one, and add it in the message.
To use this feature, use the %SHORT_LINK% placeholder in the
message body, that will be replaced with the generated short link, and
the respective short_link_url parameter, that should be set to a
valid URL. For shortlink dns personalization please contact
us at servizio.clienti@smsnet.it
Sender Alias
Alphanumeric aliases require to be registered first, and need to be approved both from Us and AGCOM.
Aliases can be used only with high-quality message types.
HTTP Request
POST /API/v1.0/REST/smstogroups
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| message_type | String (“N” for High quality with reception notification, “L” for Medium Quality, “LL” For Low Cost) | The type of SMS. | Yes | - |
| message | String (max 1000 chars with “gsm” encoding, 450 with “ucs2” encoding) | The body of the message. *Message max length could be 160 chars when using low-quality SMSs | Yes | - |
| recipient | List(String) | A list of contact group names | Yes | - |
| sender | String | The Sender name. If the message type allows a custom TPOA and the field is left empty, the user’s preferred TPOA is used. Must be empty if the message type does not allow a custom TPOA | No | “” |
| scheduled_delivery_time | String [ddMMyy, yyyyMMdd, ddMMyyHHmm, yyyyMMddHHmmss, yyyy-MM-dd HH:mm, yyyy-MM-dd HH:mm.0] | The messages will be sent at the given scheduled time | No | null |
| scheduled_delivery_timezone | Timezone(IANA time zone) | Optional timezone applied to scheduled_delivery_time date |
No | - |
| order_id | String (max 32 chars, accepts only any letters, numbers, underscore, dot and dash) | Specifies a custom order ID | No | Generated UUID |
| returnCredits | Bool | Returns the number of credits used instead of the number of messages. i.e. when message is more than 160 chars long more than one credit is used | No | “false” |
| returnRemaining | Bool | Returs the number of remaining SMSs | No | false |
| allowInvalidRecipients | Bool | Sending to an invalid recipient does not block the operation | No | false |
| encoding | String (“gsm” or “ucs2”) | The SMS encoding. Use UCS2 for non standard character sets | No | “gsm” |
| id_landing | int | The id of the published page. Also add the %PAGESLINK____________% placeholder in the message body |
No | - |
| campaign_name | String | The campaign name | No | - |
| short_link_url | String | The url where the short link redirects. Also add the %SHORT_LINK% placeholder in the message body |
No | - |
Returns
| Code | Description |
|---|---|
| 200 | Successful request |
| 400 | Groups could not be found, or other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get SMS message state
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"recipient_number": 1,
"result": "OK",
"recipients": [
{
"status": "WAITING",
"destination": "+393471234567",
"delivery_date": "20180307175609"
}
]
}
Get informations on the SMS delivery status of the given order_id.
HTTP Request
GET /API/v1.0/REST/sms/UserParam{order_id}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| order_id | String | The order ID | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | A Json object representing the status of the given SMS order. |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The order_id was not found |
Possible returned statuses are:
| Status | Value |
|---|---|
| WAITING | “WAITING” |
| SENT_TO_SMSC | “SENT” |
| WAITING_DELIVERY | “WAIT4DLVR” |
| SENT | “SENT” |
| DELIVERY_RECEIVED | “DLVRD” |
| TOO_MANY_SMS_FROM_USER | “TOOM4USER” |
| TOO_MANY_SMS_FOR_NUMBER | “TOOM4NUM” |
| ERROR | “ERROR” |
| TIMEOUT | “TIMEOUT” |
| UNPARSABLE_RCPT | “UNKNRCPT” |
| UNKNOWN_PREFIX | “UNKNPFX” |
| SENT_IN_DEMO_MODE | “DEMO” |
| WAITING_DELAYED | “SCHEDULED” |
| INVALID_DESTINATION | “INVALIDDST” |
| NUMBER_BLACKLISTED | “BLACKLISTED” |
| NUMBER_USER_BLACKLISTED | “BLACKLISTED” |
| SMSC_REJECTED | “KO” |
| INVALID_CONTENTS | “INVALIDCONTENTS” |
Delete a scheduled message
# Session Key example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.delete("https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("DELETE");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}',
method: 'DELETE',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
wb.UploadValues("https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}", "DELETE", new NameValueCollection());
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/sms/UserParam{order_id}";
my $req = HTTP::Request->new(DELETE => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{"result":"OK"}
Deletes the SMS delivery process of the given order_id.
HTTP Request
DELETE /API/v1.0/REST/sms/UserParam{order_id}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| order_id | String | The order id | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | Scheduled Message sending |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The given order_id was not found, or the message sending could not be removed (e.g. Message status is not “SCHEDULED”) |
SMS History API
This API is used to retrieve the SMS messages sending history.
Get sent SMS messages history
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/smshistory?from=UserParam{date}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/smshistory?from=UserParam{date}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/smshistory?from=UserParam{date}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/smshistory?from=UserParam{date}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/smshistory?from=UserParam{date}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/smshistory?from=UserParam{date}',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/smshistory?from=UserParam{date}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/smshistory?from=UserParam{date}");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/smshistory?from=".uri_escape("UserParam{date}")."";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"total": 1, "// The total number of results"
"pageNumber": 1, "// The returned page number"
"result": "OK", "// The status of the request"
"pageSize": 10, "// The page size"
"smshistory": [ "// The SMS history"
{
"order_id" : "XYZABCQWERTY", "// The order ID"
"create_time" : "yyyyMMddHHmmss", "// When the order was created"
"schedule_time" : "yyyyMMddHHmmss", "// When the sending is scheduled"
"message_type" : "GP", "// The message type"
"sender" : "MySender", "// The sender's alias"
"num_recipients" : 2 "// The number of recipients"
},
{
...
}
]
}
Returns the user’s SMS messages history
HTTP Request
GET /API/v1.0/REST/smshistory?from=UserParam{fromdate}&to=UserParam{todate}&pageNumber=UserParam{page}&pageSize=UserParam{size}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| from | Date(yyyyMMddHHmmss) | Return results from the given date | Yes | - |
| to | Date(yyyyMMddHHmmss) | Return results up to the given date | No | now |
| timezone | Timezone(IANA time zone) | Optional timezone applied to from or to dates |
No | - |
| pageNumber | Int | Return the given results page | No | 1 |
| pageSize | Int | The number of results in a page | No | 10 |
Returns
| Code | Description |
|---|---|
| 200 | A paginated list of the SMS history filtered as specified by the from and to dates. |
| 400 | from parameter not specified, or an error in the from, to or timezone date format. Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
SMS Blacklist / Stop SMS
This is the part of the API that allow to insert and to retrieve the list of SMS blacklist / Stop SMS. The SMS blacklist contains the phone numbers to which you don’t want to send any SMS. If the Stop SMS Service is active, any person who receive an SMS can add their phone number to the blacklist.
Add Phone Number to Blacklist
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?phoneNumber=UserParam{phoneNumber}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?phoneNumber=UserParam{phoneNumber}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?phoneNumber=UserParam{phoneNumber}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?phoneNumber=UserParam{phoneNumber}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?phoneNumber=UserParam{phoneNumber}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?phoneNumber=UserParam{phoneNumber}',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?phoneNumber=UserParam{phoneNumber}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?phoneNumber=UserParam{phoneNumber}", "POST", null);
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?phoneNumber=".uri_escape("UserParam{phoneNumber}")."";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
true
Add Phone Number to SMS Blacklist The Phone number will no longer receive an SMS from the user requesting the addition to the blacklist.
HTTP Request
POST /API/v1.0/REST/blacklist/sms
Query params
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| phoneNumber | String | The phone number of the user. The format must be +1111111111 or 001111111111 | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | The phone number is succesfully added. |
| 400 | [Bad request] Invalid recipient. |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Add multiple numbers to sms blacklist
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/blacklist/smsbatch' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
[
"+3934015546",
"+3934025546"
]
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/blacklist/smsbatch' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
[
"+3934015546",
"+3934025546"
]
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """[
"+3934015546",
"+3934025546"
]"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/blacklist/smsbatch", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/blacklist/smsbatch");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "[" +
" \"+3934015546\", " +
" \"+3934025546\"" +
"]";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '[' .
' "+3934015546", ' .
' "+3934025546"' .
']';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/blacklist/smsbatch');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/blacklist/smsbatch',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: [
"+3934015546",
"+3934025546"
],
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/blacklist/smsbatch")
payload = [
"+3934015546",
"+3934025546"
]
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "[" +
" \"+3934015546\", " +
" \"+3934025546\"" +
"]";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/blacklist/smsbatch", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/blacklist/smsbatch";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = [
"+3934015546",
"+3934025546"
];
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
2
Add multiple numbers to the user’s blacklist.
HTTP Request
POST /API/v1.0/REST/blacklist/smsbatch
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| — | List(String) | Array of phone numbers | Yes | “” |
Returns
| Code | Description |
|---|---|
| 200 | Number of phone numbers correctly put in blacklist |
| 400 | Some of the phone numbers specified were badly formatted |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Retrieve list of phone numbers in blacklist
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?from=UserParam{from}&to=UserParam{to}&origins=UserParam{origins}&pageNumber=UserParam{pageNumber}&pageSize=UserParam{pageSize}&number=UserParam{number}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?from=UserParam{from}&to=UserParam{to}&origins=UserParam{origins}&pageNumber=UserParam{pageNumber}&pageSize=UserParam{pageSize}&number=UserParam{number}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?from=UserParam{from}&to=UserParam{to}&origins=UserParam{origins}&pageNumber=UserParam{pageNumber}&pageSize=UserParam{pageSize}&number=UserParam{number}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?from=UserParam{from}&to=UserParam{to}&origins=UserParam{origins}&pageNumber=UserParam{pageNumber}&pageSize=UserParam{pageSize}&number=UserParam{number}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?from=UserParam{from}&to=UserParam{to}&origins=UserParam{origins}&pageNumber=UserParam{pageNumber}&pageSize=UserParam{pageSize}&number=UserParam{number}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?from=UserParam{from}&to=UserParam{to}&origins=UserParam{origins}&pageNumber=UserParam{pageNumber}&pageSize=UserParam{pageSize}&number=UserParam{number}',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?from=UserParam{from}&to=UserParam{to}&origins=UserParam{origins}&pageNumber=UserParam{pageNumber}&pageSize=UserParam{pageSize}&number=UserParam{number}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?from=UserParam{from}&to=UserParam{to}&origins=UserParam{origins}&pageNumber=UserParam{pageNumber}&pageSize=UserParam{pageSize}&number=UserParam{number}");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/blacklist/sms?from=".uri_escape("UserParam{from}")."&to=".uri_escape("UserParam{to}")."&origins=".uri_escape("UserParam{origins}")."&pageNumber=".uri_escape("UserParam{pageNumber}")."&pageSize=".uri_escape("UserParam{pageSize}")."&number=".uri_escape("UserParam{number}")."";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"totalElements": 3, "// The total number of results"
"totalPages": 1, "// The total pages of results"
"last": true, "// Is last page"
"first": true, "// Is first page"
"size": 10, "// Page size"
"number": 0, "// Page number"
"sort": null, "// Sort"
"numberOfElements": 3, "// Number of element in page"
"content": [
{
"number": "+39123456789", "// The complete phone number"
"idNation": "ita", "// The nation of phone number"
"rcptPrefix": "123", "// The operator prefix"
"rcptNumber": "456789", "// The number"
"origin": "API", "// Origin of insert (API, WEB, STOPSMS)"
"insertTime": "2018-10-10 08:00:00" "// The datetime of insert in blacklist"
},
{
...
}
]
}
Retrieve the paginated list of Phone numbers in SMS Blacklist
HTTP Request
GET /API/v1.0/REST/blacklist/sms
Query params
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| from | Date(yyyy-MM-dd HH:mm:ss) | Return results from the given date | No | - |
| to | Date(yyyy-MM-dd HH:mm:ss) | Return results up to the given date | No | - |
| timezone | Timezone(IANA time zone) | Optional timezone applied to from or to dates |
No | - |
| number | String | Return results that contains this phone number or part of it. | No | - |
| origins | String | List of origins(API, WEB, STOPSMS) separated by ‘,’ used for filter the results | No | - |
| pageNumber | String | Return the given results page | No | - |
| pageSize | String | The number of results in a page | No | - |
Returns
| Code | Description |
|---|---|
| 200 | A paginated list of phone number in blacklist. |
| 400 | Some of the parameters specified were badly formatted |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Received SMS API
This API allows to query the received SMS messages on the owned SIMs.
Get new received messages
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/newsrsmsmessage' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/newsrsmsmessage' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/newsrsmsmessage", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/newsrsmsmessage");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/newsrsmsmessage');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/newsrsmsmessage',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/newsrsmsmessage")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/newsrsmsmessage");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/newsrsmsmessage";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result": "OK",
"srsmshistory": [
{
"id_message": "31",
"id_sim": "+393400000001",
"sender": "+393356242290",
"message": "sadasd",
"sms_date": "20160503102231",
"keyword": "qwe"
},
{
"id_message": "29",
"id_sim": "+393400000001",
"sender": "+393356242290",
"message": "sadasd",
"sms_date": "20160503102231",
"keyword": "qwe"
}
]
}
Returns the list of received messages on the given sim_id since the
last call of this method, or the beginning of time if it’s the first
call. The list is limited to max. 100 entries.
HTTP Request
For all SIMs, use:
GET /API/v1.0/REST/newsrsmsmessage?limit=UserParam{limit}
For one or more specific SIMs, use:
GET /API/v1.0/REST/newsrsmsmessage/UserParam{id_sim}?limit=UserParam{limit}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| id_sim | String(PhoneNumber) | The phone number where you enabled the service of reception, in international format (+393471234567 or 00393471234567). If no SIM is specified, returns the new messages for all enabled SIMs. It is possible to specify more numbers, separated by comma | No | All SIMs |
| limit | Int (max 100) | The max. number of entries returned | No | 100 |
Returns
| Code | Description |
|---|---|
| 200 | The list of received SMS messages since the last call of this method. |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get the received SMS messages
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/srsmshistory?from=UserParam{from_date}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/srsmshistory?from=UserParam{from_date}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/srsmshistory?from=UserParam{from_date}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/srsmshistory?from=UserParam{from_date}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/srsmshistory?from=UserParam{from_date}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/srsmshistory?from=UserParam{from_date}',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/srsmshistory?from=UserParam{from_date}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/srsmshistory?from=UserParam{from_date}");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/srsmshistory?from=".uri_escape("UserParam{from_date}")."";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result": "OK",
"srsmshistory": [
{
"id_message": "2",
"id_sim": "+393400000001",
"sender": "+393356242290",
"message": "abcde",
"sms_date": "20160503102231",
"keyword": ""
}
],
"pageNumber": 1,
"pageSize": 10,
"total": 1
}
Get the paginated list of received SMS messages.
HTTP Request
For all SIMs, use:
GET /API/v1.0/REST/srsmshistory?from=UserParam{fromdate}&to=UserParam{todate}&pageNumber=UserParam{page}&pageSize=UserParam{size}
For one or more specific SIMs, use:
GET /API/v1.0/REST/srsmshistory/{id_sim}?from={fromdate}&to={todate}&pageNumber={page}&pageSize={size}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| id_sim | String(PhoneNumber) | The phone number where you enabled the service of reception, in international format (+393471234567 or 00393471234567). If no SIM is specified, returns the new messages for all enabled SIMs. It is possible to specify more numbers, separated by comma | No | All SIMs |
| from | Date(yyyyMMddHHmmss) | Return results from the given date | Yes | - |
| to | Date(yyyyMMddHHmmss) | Return results up to the given date | No | now |
| timezone | Timezone(IANA time zone) | Optional timezone applied to from or to dates |
No | - |
| pageNumber | Int | Return the given results page | No | 1 |
| pageSize | Int | The number of results in a page | No | 10 |
Returns
| Code | Description |
|---|---|
| 200 | The paginated list of received SMS messages. |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get the received SMS messages after a specified message.
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result": "OK",
"srsmshistory": [
{
"id_message": "6",
"id_sim": "+393400000000",
"sender": "+393356242290",
"message": "abcdef",
"sms_date": "20160503102231",
"keyword": ""
},
{
"id_message": "7",
"id_sim": "+393400000000",
"sender": "+393356242290",
"message": "abcdef",
"sms_date": "20160503102231",
"keyword": ""
},
{
"id_message": "8",
"id_sim": "+393400000000",
"sender": "+393356242290",
"message": "abcdef",
"sms_date": "20160503102231",
"keyword": ""
}
]
}
Returns a list (limited to max. 100 entries) of SMS messages received
after the given SMS message ID id_message, for the given SIM id_sim.
HTTP Request
GET /API/v1.0/REST/srsmshistory/UserParam{id_sim}/UserParam{id_message}?limit=UserParam{limit}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| id_sim | String (Phone number) | The phone number where you enabled the service of reception, in international format (+393471234567 or 00393471234567) | Yes | - |
| id_message | Int | The reference message ID | Yes | - |
| limit | Int (max. 100) | The max. number of entries in the returned list | No | 100 |
Returns
| Code | Description |
|---|---|
| 200 | The list of received SMS messages after the given message. |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get the MO received messages.
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/mosmshistory' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/mosmshistory' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/mosmshistory", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/mosmshistory");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/mosmshistory');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/mosmshistory',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/mosmshistory")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/mosmshistory");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/mosmshistory";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
{
"result": "OK",
"srsmshistory": [
{
"id_message": "6",
"id_sim": "SMS STOP",
"sender": "+393356242290",
"message": "STOP asd",
"sms_date": "20160503102231",
"keyword": ""
},
{
"id_message": "7",
"id_sim": "SMS STOP",
"sender": "+393356242290",
"message": "STOP abcdef",
"sms_date": "20160503102231",
"keyword": ""
}
]
}
This feature is available only for French customers!.
Returns a list (limited to max. 100 entries) of MO messages received for the give type which could be STOP or CONTACT or OTHER;
type is a mandatory parameter, the other are optional.
HTTP Request
GET /API/v1.0/REST/mosmshistory?type=UserParam{type}&from=UserParam{fromdate}&to=UserParam{todate}&pageNumber=UserParam{page}&pageSize=UserParam{size}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| type | String (“STOP” or “CONTACT” or “OTHER”) | Type of the MO and could be one of STOP, CONTACT or OTHER | Yes | - |
| from | Date(yyyyMMddHHmmss) | Return results from the given date | No | - |
| to | Date(yyyyMMddHHmmss) | Return results up to the given date | No | - |
| timezone | Timezone(IANA time zone) | Optional timezone applied to from or to dates |
No | - |
| pageNumber | Int | Return the given results page | No | 1 |
| pageSize | Int | The number of results in a page | No | 10 |
Returns
| Code | Description |
|---|---|
| 200 | The list of received MO messages of type, with the specified time constraints (if any) and paging |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided, ot if the user is not French |
| 404 | [Not found] The User_key was not found |
Landing pages API
This is the part of the API that regards the Landing Pages service.
List the published landing pages
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/landings' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/landings' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/landings", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/landings");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/landings');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/landings',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/landings")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/landings");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/landings";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result": "OK",
"landings": [
{
"id_landing": 18,
"name": "agoodpage",
"description": "Test page",
"long_description": null,
"created": 1513066300000,
"modified": 1513067151000,
"html_title": null
},
{
"id_landing": 19,
"name": "anicepage",
"description": "A nice page",
"long_description": null,
"created": 1513067137000,
"modified": 1513067563000,
"html_title": null
}
]
}
Returns the list of published landing pages of the user.
HTTP Request
POST /API/v1.0/REST/landings
Returns
| Code | Description |
|---|---|
| 200 | A list of landing pages of the user |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Email Campaign API
This API exposes methods for creating and managing Email campaigns.
Emails can be sent to a list, that is used for contacts
subscription. A list allows contacts to subscribe to it, and also
defines some basic email sending settings, such as:
- Name of the list
- Language
- Sender’s name and email
- Reply-to email
- Customized Opt-in email
An Email campaign is a sending of an email to a certain list.
Create a new list
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/list", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/list");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"title\": \"MyNewList\", " +
" \"id_language\": \"ita\", " +
" \"email_sender\": \"ema@il.com\", " +
" \"reply_to\": \"ema@il.com\", " +
" \"company_name\": \"MyCompany\", " +
" \"company_address\": \"My Company Address\", " +
" \"company_url\": \"www.mycompany.com\", " +
" \"company_phone\": \"+34123456789\", " +
" \"company_fax\": \"+341234567810\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "title": "MyNewList", ' .
' "id_language": "ita", ' .
' "email_sender": "ema@il.com", ' .
' "reply_to": "ema@il.com", ' .
' "company_name": "MyCompany", ' .
' "company_address": "My Company Address", ' .
' "company_url": "www.mycompany.com", ' .
' "company_phone": "+34123456789", ' .
' "company_fax": "+341234567810"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/list');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/list',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/list")
payload = {
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"title\": \"MyNewList\", " +
" \"id_language\": \"ita\", " +
" \"email_sender\": \"ema@il.com\", " +
" \"reply_to\": \"ema@il.com\", " +
" \"company_name\": \"MyCompany\", " +
" \"company_address\": \"My Company Address\", " +
" \"company_url\": \"www.mycompany.com\", " +
" \"company_phone\": \"+34123456789\", " +
" \"company_fax\": \"+341234567810\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/list", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/list";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"title" => "MyNewList",
"id_language" => "ita",
"email_sender" => "ema@il.com",
"reply_to" => "ema@il.com",
"company_name" => "MyCompany",
"company_address" => "My Company Address",
"company_url" => "www.mycompany.com",
"company_phone" => "+34123456789",
"company_fax" => "+341234567810"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the created list:
'Location': '/list/{list_id}'
Create a new sending list.
HTTP Request
POST /API/v1.0/REST/list
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| title | String | The list name | Yes | - |
| id_language | String (e.g. “ita”) | The list default language | Yes | - |
| email_sender | a valid email | The sender’s email address | Yes | - |
| reply_to | a valid email | The email to be used for the ‘reply_to’ email field | Yes | - |
| company_name | String | The company name | Yes | - |
| company_address | String | The company address | Yes | - |
| company_url | String | The company website URL | Yes | - |
| company_phone | String | The company phone number | Yes | - |
| company_fax | String | The company FAX number | Yes | - |
Returns
| Code | Description |
|---|---|
| 201 | List created, The HTTP location header that points to the created list |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Modify a list
# Session Key example
curl -XPUT 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
}
'
# Access token example
curl -XPUT 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
}"""
r = requests.put("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}", headers=headers, data=payload)
if r.status_code != 204:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("PUT");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"title\": \"MyNewList\", " +
" \"id_language\": \"ita\", " +
" \"email_sender\": \"ema@il.com\", " +
" \"reply_to\": \"ema@il.com\", " +
" \"company_name\": \"MyCompany\", " +
" \"company_address\": \"My Company Address\", " +
" \"company_url\": \"www.mycompany.com\", " +
" \"company_phone\": \"+34123456789\", " +
" \"company_fax\": \"+341234567810\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 204) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "title": "MyNewList", ' .
' "id_language": "ita", ' .
' "email_sender": "ema@il.com", ' .
' "reply_to": "ema@il.com", ' .
' "company_name": "MyCompany", ' .
' "company_address": "My Company Address", ' .
' "company_url": "www.mycompany.com", ' .
' "company_phone": "+34123456789", ' .
' "company_fax": "+341234567810"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 204) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}',
method: 'PUT',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 204) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}")
payload = {
"title": "MyNewList",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Put.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "204"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"title\": \"MyNewList\", " +
" \"id_language\": \"ita\", " +
" \"email_sender\": \"ema@il.com\", " +
" \"reply_to\": \"ema@il.com\", " +
" \"company_name\": \"MyCompany\", " +
" \"company_address\": \"My Company Address\", " +
" \"company_url\": \"www.mycompany.com\", " +
" \"company_phone\": \"+34123456789\", " +
" \"company_fax\": \"+341234567810\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}", "PUT", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}";
my $req = HTTP::Request->new(PUT => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"title" => "MyNewList",
"id_language" => "ita",
"email_sender" => "ema@il.com",
"reply_to" => "ema@il.com",
"company_name" => "MyCompany",
"company_address" => "My Company Address",
"company_url" => "www.mycompany.com",
"company_phone" => "+34123456789",
"company_fax" => "+341234567810"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 204) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the updated list:
'Location': '/list/{list_id}'
Updates a sending list.
HTTP Request
PUT /API/v1.0/REST/list/UserParam{list_id}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| list_id | Int | The ID of the list to modify | Yes | - |
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| title | String | The list name | No | - |
| id_language | String (e.g. “ita”) | The list default language | No | - |
| email_sender | a valid email | The sender’s email address | No | - |
| reply_to | a valid email | The email to be used for the ‘reply_to’ email field | No | - |
| company_name | String | The company name | No | - |
| company_address | String | The company address | No | - |
| company_url | String | The company website URL | No | - |
| company_phone | String | The company phone number | No | - |
| company_fax | String | The company FAX number | No | - |
| status | Int | The list status (0 = Active, 1 = Archived, 2 = To Be Activated) | No | - |
Returns
| Code | Description |
|---|---|
| 204 | List updated, The HTTP location header that points to the created list |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get list of campaigns by statuses
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/list' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/list' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/list", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/list");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/list');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/list',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/list")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/list");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/list";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
[{
"id_campaign": 10,
"title": "MyList1",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810",
"status": "ACTIVE",
"create_date": "2018-02-27 15:30:56"
},
{
"id_campaign": 11,
"title": "MyList2",
"id_language": "ita",
"email_sender": "ema@il.com",
"reply_to": "ema@il.com",
"company_name": "MyCompany",
"company_address": "My Company Address",
"company_url": "www.mycompany.com",
"company_phone": "+34123456789",
"company_fax": "+341234567810",
"status": "ACTIVE",
"create_date": "2018-02-27 15:31:06"
}]
Get list of campaigns by statuses. If statuses is not specified by default return only ACTIVE campaign.
HTTP Request
GET /API/v1.0/REST/list?statuses=UserParam(statuses)
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| statuses | String | List of campaign statuses separated by comma (ACTIVE, ARCHIVED, TO_ACTIVATE) | No | ACTIVE |
Returns
| Code | Description |
|---|---|
| 200 | List of campaign |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
Add a contacts group to a list of distribution
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}", "POST", null);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
Add all contacts of the given group to the given list of distribution. Emails can be only sent to contacts that belong to a distribution list.
HTTP Request
POST /API/v1.0/REST/list/UserParam{list_id}/group/UserParam{group_id}?sendoptin=UserParam{send}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| list_id | Int | The list ID | Yes | - |
| group_id | String | The group ID | Yes | - |
| sendoptin | Bool | Send the Opt-in email to the group’s contacts | No | false |
Returns
| Code | Description |
|---|---|
| 200 | The group has been added to the list |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Create a new email draft
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/issue' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"title": "New title",
"subject": "Hello world!",
"share_social": false,
"web_analytics": "www.google.it?a=b",
"text_content": "Test email",
"html_content": "<body><table><tr><td>Hello world!</td></tr><table></body>",
"attachments": [
{
"file_name": "attach1.pdf",
"file_content_base64": "ABAAC2"
},
{
"file_name": "attach2.pdf",
"file_content_base64": "PBAAC2"
}
]
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/issue' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"title": "New title",
"subject": "Hello world!",
"share_social": false,
"web_analytics": "www.google.it?a=b",
"text_content": "Test email",
"html_content": "<body><table><tr><td>Hello world!</td></tr><table></body>",
"attachments": [
{
"file_name": "attach1.pdf",
"file_content_base64": "ABAAC2"
},
{
"file_name": "attach2.pdf",
"file_content_base64": "PBAAC2"
}
]
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"title": "New title",
"subject": "Hello world!",
"share_social": false,
"web_analytics": "www.google.it?a=b",
"text_content": "Test email",
"html_content": "<body><table><tr><td>Hello world!</td></tr><table></body>",
"attachments": [
{
"file_name": "attach1.pdf",
"file_content_base64": "ABAAC2"
},
{
"file_name": "attach2.pdf",
"file_content_base64": "PBAAC2"
}
]
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/issue", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/issue");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"title\": \"New title\", " +
" \"subject\": \"Hello world!\", " +
" \"share_social\": false, " +
" \"web_analytics\": \"www.google.it?a=b\", " +
" \"text_content\": \"Test email\", " +
" \"html_content\": \"<body><table><tr><td>Hello world!</td></tr><table></body>\", " +
" \"attachments\": [" +
" {" +
" \"file_name\": \"attach1.pdf\", " +
" \"file_content_base64\": \"ABAAC2\"" +
" }, " +
" {" +
" \"file_name\": \"attach2.pdf\", " +
" \"file_content_base64\": \"PBAAC2\"" +
" }" +
" ]" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "title": "New title", ' .
' "subject": "Hello world!", ' .
' "share_social": false, ' .
' "web_analytics": "www.google.it?a=b", ' .
' "text_content": "Test email", ' .
' "html_content": "<body><table><tr><td>Hello world!</td></tr><table></body>", ' .
' "attachments": [' .
' {' .
' "file_name": "attach1.pdf", ' .
' "file_content_base64": "ABAAC2"' .
' }, ' .
' {' .
' "file_name": "attach2.pdf", ' .
' "file_content_base64": "PBAAC2"' .
' }' .
' ]' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/issue');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/issue',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"title": "New title",
"subject": "Hello world!",
"share_social": false,
"web_analytics": "www.google.it?a=b",
"text_content": "Test email",
"html_content": "<body><table><tr><td>Hello world!</td></tr><table></body>",
"attachments": [
{
"file_name": "attach1.pdf",
"file_content_base64": "ABAAC2"
},
{
"file_name": "attach2.pdf",
"file_content_base64": "PBAAC2"
}
]
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/issue")
payload = {
"title": "New title",
"subject": "Hello world!",
"share_social": false,
"web_analytics": "www.google.it?a=b",
"text_content": "Test email",
"html_content": "<body><table><tr><td>Hello world!</td></tr><table></body>",
"attachments": [
{
"file_name": "attach1.pdf",
"file_content_base64": "ABAAC2"
},
{
"file_name": "attach2.pdf",
"file_content_base64": "PBAAC2"
}
]
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"title\": \"New title\", " +
" \"subject\": \"Hello world!\", " +
" \"share_social\": false, " +
" \"web_analytics\": \"www.google.it?a=b\", " +
" \"text_content\": \"Test email\", " +
" \"html_content\": \"<body><table><tr><td>Hello world!</td></tr><table></body>\", " +
" \"attachments\": [" +
" {" +
" \"file_name\": \"attach1.pdf\", " +
" \"file_content_base64\": \"ABAAC2\"" +
" }, " +
" {" +
" \"file_name\": \"attach2.pdf\", " +
" \"file_content_base64\": \"PBAAC2\"" +
" }" +
" ]" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/issue", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/list/UserParam{list_id}/issue";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"title" => "New title",
"subject" => "Hello world!",
"share_social" => false,
"web_analytics" => "www.google.it?a=b",
"text_content" => "Test email",
"html_content" => "<body><table><tr><td>Hello world!</td></tr><table></body>",
"attachments" => [
{
"file_name" => "attach1.pdf",
"file_content_base64" => "ABAAC2"
},
{
"file_name" => "attach2.pdf",
"file_content_base64" => "PBAAC2"
}
]
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
# The HTTP location header that points to the created issue:
'Location': '/issue/{issue_id}'
Creates a new email draft. Every email draft must be associated to a distribution list.
HTTP Request
POST /API/v1.0/REST/list/UserParam{list_id}/issue
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| list_id | Int | The list where to send the emails | Yes | - |
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| title | String | The issue title | Yes | - |
| subject | String | The subject for the issue | Yes | - |
| share_social | Bool | Adds the social share buttons | Yes | - |
| web_analytics | String | The WebAnalytics tracing code | No | - |
| text_content | String | The Email text body | Yes | - |
| html_content | String | The Email HTML body | Yes | - |
| attachments | List(Attachment) | The list of attachments (can be empty) | Yes | - |
| Attachment.file_name | String | The file name of the attachment | Yes | - |
| Attachment.file_content_base64 | String | The base64-encoded attachment | Yes | - |
Returns
| Code | Description |
|---|---|
| 201 | Issue created, the HTTP Location header points to the created issue |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Create new issue using a specified template
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/template/UserParam{template}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"name": "New title",
"subject": "Hello World!!"
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/template/UserParam{template}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"name": "New title",
"subject": "Hello World!!"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"name": "New title",
"subject": "Hello World!!"
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/template/UserParam{template}", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/template/UserParam{template}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"name\": \"New title\", " +
" \"subject\": \"Hello World!!\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "name": "New title", ' .
' "subject": "Hello World!!"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/template/UserParam{template}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/template/UserParam{template}',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"name": "New title",
"subject": "Hello World!!"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/template/UserParam{template}")
payload = {
"name": "New title",
"subject": "Hello World!!"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"name\": \"New title\", " +
" \"subject\": \"Hello World!!\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/template/UserParam{template}", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/template/UserParam{template}";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"name" => "New title",
"subject" => "Hello World!!"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
# The HTTP location header that points to the created issue:
'Location': ' /list/{campaignId}/issue/{issue_id}'
Creates a new issue starting from the specified template.
HTTP Request
POST /API/v1.0/REST/list/UserParam{campaignId}/issue/template/UserParam{template}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| campaignId | Int | The list where to send the emails | Yes | - |
| template | Int | The template, previously created, to do the send | Yes | - |
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| name | String | The name/title of the issue | Yes | - |
| subject | String | The subject used in the issue | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | Successful request |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
| 500 | The issue can’t be created |
Send an issue to preloaded contacts
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/UserParam{id_issue}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"contactIds": [
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
],
"scheduleTime": "2017-08-17 12:30:00"
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/UserParam{id_issue}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"contactIds": [
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
],
"scheduleTime": "2017-08-17 12:30:00"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"contactIds": [
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
],
"scheduleTime": "2017-08-17 12:30:00"
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/UserParam{id_issue}", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/UserParam{id_issue}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"contactIds\": [" +
" \"AV3vrSlPuGYfQz6BgjeI\", " +
" \"BVvrSlPuGYfQz6BgjeI\"" +
" ], " +
" \"scheduleTime\": \"2017-08-17 12:30:00\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "contactIds": [' .
' "AV3vrSlPuGYfQz6BgjeI", ' .
' "BVvrSlPuGYfQz6BgjeI"' .
' ], ' .
' "scheduleTime": "2017-08-17 12:30:00"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/UserParam{id_issue}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/UserParam{id_issue}',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"contactIds": [
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
],
"scheduleTime": "2017-08-17 12:30:00"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/UserParam{id_issue}")
payload = {
"contactIds": [
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
],
"scheduleTime": "2017-08-17 12:30:00"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"contactIds\": [" +
" \"AV3vrSlPuGYfQz6BgjeI\", " +
" \"BVvrSlPuGYfQz6BgjeI\"" +
" ], " +
" \"scheduleTime\": \"2017-08-17 12:30:00\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/UserParam{id_issue}", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/list/UserParam{campaign_id}/issue/UserParam{id_issue}";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"contactIds" => [
"AV3vrSlPuGYfQz6BgjeI",
"BVvrSlPuGYfQz6BgjeI"
],
"scheduleTime" => "2017-08-17 12:30:00"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
Schedule an issue to be sent to a specified list of contacts Ids at a given time.
HTTP Request
POST /API/v1.0/REST/list/UserParam{campaignId}/issue/UserParam{idIssue}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| campaignId | Int | The campaign where to send the emails | Yes | - |
| idIssue | Int | The mailing to send | Yes | - |
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| contactIds | String[] | The list of contact Ids of the recipients | Yes | - |
| scheduleTime | String | When send the mailing in format yyyy-MM-dd hh:mm:ss | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | Successful request |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
| 500 | The issue can’t be sent or the contacts Ids array is empty |
Subaccount API
If enabled as a superaccount, the user can create subaccounts that can be assigned to third-parties. Superaccounts may or may not share credits with their subaccounts.
Get the list of subaccounts
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/subaccounts' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/subaccounts' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/subaccounts", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccounts");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccounts');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccounts',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccounts")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/subaccounts");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccounts";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result": "OK",
"pageNumber": 1,
"pageSize": 10,
"total": 2,
"subaccount": [
{
"activation-time": "20160823",
"active": true,
"address": "via viotta",
"allowtpoavalidation": true,
"cell": "+393385958233",
"city": "Città ",
"fiscal-code": "PRRFCC92L09L488E",
"pa-code": null,
"company": false,
"company-name": null,
"create-time": "20160823",
"credit-eat-mode": 2,
"credits-sum": "€ 0,000",
"default-message-type": "SI",
"default-nation": "ita",
"dfeu": true,
"email": "prova@prova.pr",
"fax": "0461757575",
"foreign": false,
"id-user": 5,
"invoicing-email": null,
"language": "ita",
"legal-agreement-time": "20160823",
"legalAgreementVersion": 0,
"login": "logon",
"max-subaccounts": -1,
"name": "nome",
"num-cell-for-test-sms": "+393385958233",
"partner": false,
"partner-code": null,
"phone": "0461757575",
"piva": null,
"preferred-tpoa": "+393385958233",
"private": true,
"province": "Trento",
"referral": false,
"shop_cart_check": true,
"split-payment": false,
"subaccount": true,
"subaccount-types": 0,
"super-account-name": "",
"superaccount": false,
"surname": "asdasd",
"use24": true,
"user-nation": "ita",
"zip-code": "38010",
"credits": [
{
"id": "N",
"qty": 10
},
{
"id": "L",
"qty": 10
},
{
"id": "LL",
"qty": 10
},
{
"id": "EE",
"qty": 10
}
]
}
]
}
Returns the list of subaccounts of the authenticated user.
HTTP Request
GET /API/v1.0/REST/subaccounts?pageNumber=UserParam{page}&pageSize=UserParam{size}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| pageNumber | Int | Return the given results page | No | 1 |
| pageSize | Int | The number of results in a page | No | 10 |
Returns
| Code | Description |
|---|---|
| 200 | The paginated list of subaccounts of the authenticated user |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
The “credits” and “credits-sum” fields will be populated only in the case in which the subaccount has “credit-eat-mode” = 2
Create a subaccount
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/subaccount' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/subaccount' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/subaccount", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccount");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"address\": \"via xxx\", " +
" \"cell\": \"+393393939393\", " +
" \"city\": \"myCity\", " +
" \"fiscal-code\": \"BRGRJM87J89JH907E\", " +
" \"company\": true, " +
" \"company-name\": \"myCompany\", " +
" \"credit-eat-mode\": 1, " +
" \"dfeu\": true, " +
" \"email\": \"em@a.il\", " +
" \"fax\": \"0461686868\", " +
" \"invoicing-email\": \"em@a.il\", " +
" \"language\": \"ita\", " +
" \"login\": \"myLogin\", " +
" \"name\": \"myNome\", " +
" \"num-cell-for-test-sms\": \"+393393939393\", " +
" \"password\": \"myPassword\", " +
" \"phone\": \"0461656565\", " +
" \"piva\": \"104456015145\", " +
" \"province\": \"TN\", " +
" \"superaccount\": false, " +
" \"surname\": \"mySurname\", " +
" \"use24\": true, " +
" \"zip-code\": \"38010\", " +
" \"id-subaccount-profile\": 1" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "address": "via xxx", ' .
' "cell": "+393393939393", ' .
' "city": "myCity", ' .
' "fiscal-code": "BRGRJM87J89JH907E", ' .
' "company": true, ' .
' "company-name": "myCompany", ' .
' "credit-eat-mode": 1, ' .
' "dfeu": true, ' .
' "email": "em@a.il", ' .
' "fax": "0461686868", ' .
' "invoicing-email": "em@a.il", ' .
' "language": "ita", ' .
' "login": "myLogin", ' .
' "name": "myNome", ' .
' "num-cell-for-test-sms": "+393393939393", ' .
' "password": "myPassword", ' .
' "phone": "0461656565", ' .
' "piva": "104456015145", ' .
' "province": "TN", ' .
' "superaccount": false, ' .
' "surname": "mySurname", ' .
' "use24": true, ' .
' "zip-code": "38010", ' .
' "id-subaccount-profile": 1' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccount');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccount',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccount")
payload = {
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"address\": \"via xxx\", " +
" \"cell\": \"+393393939393\", " +
" \"city\": \"myCity\", " +
" \"fiscal-code\": \"BRGRJM87J89JH907E\", " +
" \"company\": true, " +
" \"company-name\": \"myCompany\", " +
" \"credit-eat-mode\": 1, " +
" \"dfeu\": true, " +
" \"email\": \"em@a.il\", " +
" \"fax\": \"0461686868\", " +
" \"invoicing-email\": \"em@a.il\", " +
" \"language\": \"ita\", " +
" \"login\": \"myLogin\", " +
" \"name\": \"myNome\", " +
" \"num-cell-for-test-sms\": \"+393393939393\", " +
" \"password\": \"myPassword\", " +
" \"phone\": \"0461656565\", " +
" \"piva\": \"104456015145\", " +
" \"province\": \"TN\", " +
" \"superaccount\": false, " +
" \"surname\": \"mySurname\", " +
" \"use24\": true, " +
" \"zip-code\": \"38010\", " +
" \"id-subaccount-profile\": 1" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/subaccount", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccount";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"address" => "via xxx",
"cell" => "+393393939393",
"city" => "myCity",
"fiscal-code" => "BRGRJM87J89JH907E",
"company" => true,
"company-name" => "myCompany",
"credit-eat-mode" => 1,
"dfeu" => true,
"email" => "em@a.il",
"fax" => "0461686868",
"invoicing-email" => "em@a.il",
"language" => "ita",
"login" => "myLogin",
"name" => "myNome",
"num-cell-for-test-sms" => "+393393939393",
"password" => "myPassword",
"phone" => "0461656565",
"piva" => "104456015145",
"province" => "TN",
"superaccount" => false,
"surname" => "mySurname",
"use24" => true,
"zip-code" => "38010",
"id-subaccount-profile" => 1
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the created subaccount:
'Location': '/subaccount/18107'
Creates a new subaccount for the authenticated user, which has to be a superaccount.
HTTP Request
POST /API/v1.0/REST/subaccount
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| address | String | The subaccount address | Yes | - |
| cell | String | The subaccount mobile phone number | Yes | - |
| city | String | The subaccount city | Yes | - |
| company | Bool | Is the subaccount a company? | No | true |
| company-name | String | The company name | Yes (if company=true) | - |
| credit-eat-mode | Int (0, 1, 2) | Tells from who credits are scaled. 0 = own credits, 1 = superaccount credits, 2 = own credits and superaccount ones | Yes | - |
| dfeu | Bool | Use the Date Format in EUropean format | No | true |
| String (a valid Email) | The subaccount email | Yes | - | |
| fax | String | The subaccount FAX number | No | “” |
| invoicing-email | String (a valid Email) | If provided, invoices will be sent here instead of the default email | No | “” |
| language | String | The subaccount language. If none, defaults to the one of the superaccount | No | to the one of the superaccount |
| login | String | The subaccount login username (must not contain any spaces) | Yes | - |
| name | String | The subaccount owner first name | Yes | - |
| num-cell-for-test-sms | String (Phone number) | A phone number where test SMS messages will be sent | No | “” |
| password | String | The subaccount password (min 8 chars, max 16 chars) | No | If null, will be autogenerated |
| phone | String (PhoneNumber) | The subaccount phone number | No | “” |
| piva | String | The subaccount VAT number (P.Iva in Italy) | Yes (if company=true) | |
| province | String | The subaccount province | Yes | - |
| superaccount | Bool | The subaccount is a superaccount itself (i.e. it can create his own subaccounts) | No | false |
| surname | String | The subaccount last name | Yes | - |
| use24 | Bool | Use the 24 hour format for time | No | true |
| zip-code | String | The subaccount ZIP Code | Yes | - |
| id-subaccount-profile | Int | Specifying a custom subaccount profile allows a superaccount to narrow down the subaccount enabled features (e.g. Only send SMS messages, or even further, only send a specific type of SMS message) | No | The default profile |
Returns
| Code | Description |
|---|---|
| 200 | Success, returns an empty response with the HTTP Location header pointing to the created subaccount |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Edit subaccount
# Session Key example
curl -XPUT 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
}
'
# Access token example
curl -XPUT 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
}"""
r = requests.put("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("PUT");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"address\": \"via xxx\", " +
" \"cell\": \"+393393939393\", " +
" \"city\": \"myCity\", " +
" \"fiscal-code\": \"BRGRJM87J89JH907E\", " +
" \"company\": true, " +
" \"company-name\": \"myCompany\", " +
" \"credit-eat-mode\": 1, " +
" \"dfeu\": true, " +
" \"email\": \"em@a.il\", " +
" \"fax\": \"0461686868\", " +
" \"invoicing-email\": \"em@a.il\", " +
" \"language\": \"ita\", " +
" \"login\": \"myLogin\", " +
" \"name\": \"myNome\", " +
" \"num-cell-for-test-sms\": \"+393393939393\", " +
" \"password\": \"myPassword\", " +
" \"phone\": \"0461656565\", " +
" \"piva\": \"104456015145\", " +
" \"province\": \"TN\", " +
" \"superaccount\": false, " +
" \"surname\": \"mySurname\", " +
" \"use24\": true, " +
" \"zip-code\": \"38010\", " +
" \"id-subaccount-profile\": 1" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "address": "via xxx", ' .
' "cell": "+393393939393", ' .
' "city": "myCity", ' .
' "fiscal-code": "BRGRJM87J89JH907E", ' .
' "company": true, ' .
' "company-name": "myCompany", ' .
' "credit-eat-mode": 1, ' .
' "dfeu": true, ' .
' "email": "em@a.il", ' .
' "fax": "0461686868", ' .
' "invoicing-email": "em@a.il", ' .
' "language": "ita", ' .
' "login": "myLogin", ' .
' "name": "myNome", ' .
' "num-cell-for-test-sms": "+393393939393", ' .
' "password": "myPassword", ' .
' "phone": "0461656565", ' .
' "piva": "104456015145", ' .
' "province": "TN", ' .
' "superaccount": false, ' .
' "surname": "mySurname", ' .
' "use24": true, ' .
' "zip-code": "38010", ' .
' "id-subaccount-profile": 1' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}',
method: 'PUT',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}")
payload = {
"address": "via xxx",
"cell": "+393393939393",
"city": "myCity",
"fiscal-code": "BRGRJM87J89JH907E",
"company": true,
"company-name": "myCompany",
"credit-eat-mode": 1,
"dfeu": true,
"email": "em@a.il",
"fax": "0461686868",
"invoicing-email": "em@a.il",
"language": "ita",
"login": "myLogin",
"name": "myNome",
"num-cell-for-test-sms": "+393393939393",
"password": "myPassword",
"phone": "0461656565",
"piva": "104456015145",
"province": "TN",
"superaccount": false,
"surname": "mySurname",
"use24": true,
"zip-code": "38010",
"id-subaccount-profile": 1
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Put.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"address\": \"via xxx\", " +
" \"cell\": \"+393393939393\", " +
" \"city\": \"myCity\", " +
" \"fiscal-code\": \"BRGRJM87J89JH907E\", " +
" \"company\": true, " +
" \"company-name\": \"myCompany\", " +
" \"credit-eat-mode\": 1, " +
" \"dfeu\": true, " +
" \"email\": \"em@a.il\", " +
" \"fax\": \"0461686868\", " +
" \"invoicing-email\": \"em@a.il\", " +
" \"language\": \"ita\", " +
" \"login\": \"myLogin\", " +
" \"name\": \"myNome\", " +
" \"num-cell-for-test-sms\": \"+393393939393\", " +
" \"password\": \"myPassword\", " +
" \"phone\": \"0461656565\", " +
" \"piva\": \"104456015145\", " +
" \"province\": \"TN\", " +
" \"superaccount\": false, " +
" \"surname\": \"mySurname\", " +
" \"use24\": true, " +
" \"zip-code\": \"38010\", " +
" \"id-subaccount-profile\": 1" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}", "PUT", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}";
my $req = HTTP::Request->new(PUT => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"address" => "via xxx",
"cell" => "+393393939393",
"city" => "myCity",
"fiscal-code" => "BRGRJM87J89JH907E",
"company" => true,
"company-name" => "myCompany",
"credit-eat-mode" => 1,
"dfeu" => true,
"email" => "em@a.il",
"fax" => "0461686868",
"invoicing-email" => "em@a.il",
"language" => "ita",
"login" => "myLogin",
"name" => "myNome",
"num-cell-for-test-sms" => "+393393939393",
"password" => "myPassword",
"phone" => "0461656565",
"piva" => "104456015145",
"province" => "TN",
"superaccount" => false,
"surname" => "mySurname",
"use24" => true,
"zip-code" => "38010",
"id-subaccount-profile" => 1
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the edited subaccount:
'Location': '/subaccount/18107'
Edits the subaccount identified by the given subaccount_id. Calling
user must be a superaccount.
HTTP Request
PUT /API/v1.0/REST/subaccount/UserParam{subaccount_id}?lock-subaccount=UserParam{value}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| subaccount_id | Int | The subaccount ID | Yes | - |
| lock-subaccount | Bool | Activate or deactivate the subaccount | No | false |
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| address | String | The subaccount address | Yes | - |
| cell | String | The subaccount mobile phone number | Yes | - |
| city | String | The subaccount city | Yes | - |
| company | Bool | Is the subaccount a company? | No | true |
| company-name | String | The company name | Yes (if company=true) | - |
| credit-eat-mode | Int (0, 1, 2) | Tells from who credits are scaled. 0 = own credits, 1 = superaccount credits, 2 = own credits and superaccount ones | Yes | - |
| dfeu | Bool | Use the Date Format in EUropean format | No | true |
| String (a valid Email) | The subaccount email | Yes | - | |
| fax | String | The subaccount FAX number | No | “” |
| invoicing-email | String (a valid Email) | If provided, invoices will be sent here instead of the default email | No | “” |
| language | String | The subaccount language. If none, defaults to the one of the superaccount | No | to the one of the superaccount |
| login | String | The subaccount login username (Must not contain any spaces) | Yes | - |
| name | String | The subaccount owner first name | Yes | - |
| num-cell-for-test-sms | String (Phone number) | A phone number where test SMS messages will be sent | No | “” |
| password | String | The subaccount password (min 8 chars, max 16 chars) | No | If null, will be autogenerated |
| phone | String (PhoneNumber) | The subaccount phone number | No | “” |
| piva | String | The subaccount VAT number (P.Iva in Italy) | Yes (if company=true) | |
| province | String | The subaccount province | Yes | - |
| superaccount | Bool | The subaccount is a superaccount itself (i.e. it can create his own subaccounts) | No | false |
| surname | String | The subaccount last name | Yes | - |
| use24 | Bool | Use the 24 hour format for time | No | true |
| zip-code | String | The subaccount ZIP Code | Yes | - |
| id-subaccount-profile | Int | Specifying a custom subaccount profile allows a superaccount to narrow down the subaccount enabled features (e.g. Only send SMS messages, or even further, only send a specific type of SMS message) | No | The default profile |
Returns
| Code | Description |
|---|---|
| 200 | Success, returns an empty response with the HTTP Location header pointing to the created subaccount |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Change subaccount password
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"passwd": "password"
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"passwd": "password"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"passwd": "password"
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"passwd\": \"password\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "passwd": "password"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"passwd": "password"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd")
payload = {
"passwd": "password"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"passwd\": \"password\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"passwd" => "password"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'change password' URL:
'Location': '/subaccount/{subaccount_id}/changepwd'
Change a subaccount’s password
HTTP Request
POST /API/v1.0/REST/subaccount/UserParam{subaccount_id}/changepwd
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| subaccount_id | Int | The subaccount ID | Yes | - |
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| passwd | String | The subaccount password (min 8 chars, max 16 chars) | Yes | - |
Returns
| Code | Description |
|---|---|
| 201 | Password correctly changed. HTTP Location header pointing to the change password URL. |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get subaccount
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"activation-time": "20160823",
"active": true,
"address": "via",
"allowtpoavalidation": true,
"cell": "+393385958233",
"city": "Città ",
"fiscal-code": "FDFWEE92L45L458E",
"pa-code": null,
"company": false,
"company-name": null,
"create-time": "20160823",
"credit-eat-mode": 2,
"credits-sum": "€ 0,000",
"default-message-type": "SI",
"default-nation": "ita",
"dfeu": true,
"email": "prova@prova.pr",
"fax": "0461657575",
"foreign": false,
"id-user": 5,
"invoicing-email": null,
"language": "ita",
"legal-agreement-time": "20160823",
"legalAgreementVersion": 0,
"login": "logon",
"max-subaccounts": -1,
"name": "nome",
"num-cell-for-test-sms": "+393385958233",
"partner": false,
"partner-code": null,
"phone": "0461657575",
"piva": null,
"preferred-tpoa": "+393385958233",
"private": true,
"province": "Trento",
"referral": false,
"shop_cart_check": true,
"split-payment": false,
"subaccount": true,
"subaccount-types": 0,
"super-account-name": "",
"superaccount": false,
"surname": "asdasd",
"use24": true,
"user-nation": "ita",
"zip-code": "38010",
"credits": [
{
"id": "N",
"qty": 0
},
{
"id": "L",
"qty": 0
},
{
"id": "LL",
"qty": 0
},
{
"id": "EE",
"qty": 0
}
]
}
Get a subaccount’s details
HTTP Request
GET /API/v1.0/REST/subaccount/UserParam{subaccount_id}
Returns
| Code | Description |
|---|---|
| 200 | Successful request |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
The “credits” and “credits-sum” fields will be populated only in the case in which the subaccount has “credit-eat-mode” = 2.
Move credits from/to subaccount
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"credits": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"amount": 5,
"super-to-sub": true
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"amount": 50,
"super-to-sub": true
}
]
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"credits": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"amount": 5,
"super-to-sub": true
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"amount": 50,
"super-to-sub": true
}
]
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"credits": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"amount": 5,
"super-to-sub": true
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"amount": 50,
"super-to-sub": true
}
]
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit", headers=headers, data=payload)
if r.status_code != 201:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"credits\": [" +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_1}\", " +
" \"amount\": 5, " +
" \"super-to-sub\": true" +
" }, " +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_2}\", " +
" \"amount\": 50, " +
" \"super-to-sub\": true" +
" }" +
" ]" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 201) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "credits": [' .
' {' .
' "message-type": "UserParam{MESSAGE_TYPE_1}", ' .
' "amount": 5, ' .
' "super-to-sub": true' .
' }, ' .
' {' .
' "message-type": "UserParam{MESSAGE_TYPE_2}", ' .
' "amount": 50, ' .
' "super-to-sub": true' .
' }' .
' ]' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 201) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"credits": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"amount": 5,
"super-to-sub": true
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"amount": 50,
"super-to-sub": true
}
]
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 201) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit")
payload = {
"credits": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"amount": 5,
"super-to-sub": true
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"amount": 50,
"super-to-sub": true
}
]
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "201"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"credits\": [" +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_1}\", " +
" \"amount\": 5, " +
" \"super-to-sub\": true" +
" }, " +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_2}\", " +
" \"amount\": 50, " +
" \"super-to-sub\": true" +
" }" +
" ]" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"credits" => [
{
"message-type" => "UserParam{MESSAGE_TYPE_1}",
"amount" => 5,
"super-to-sub" => true
},
{
"message-type" => "UserParam{MESSAGE_TYPE_2}",
"amount" => 50,
"super-to-sub" => true
}
]
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP Location header points to the API to recover credits:
'Location': '/subaccount/{subaccount_id}/credit'
Transfers credits between a superaccount and a subaccount. The
subaccount must be enabled to have its own credits (i.e. subaccount
credit-eat-mode is 0 or 2)
HTTP Request
POST /API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| subaccount_id | Int | The subaccount ID | Yes | - |
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| credits | List(Credit) | The list of credits to move | Yes | - |
| Credit.message-type | String | The message type (“N” for High quality with reception notification, “L” for Medium Quality, “LL” For Low Cost) | Yes | - |
| Credit.amount | Int | The number of credits to transfer | ||
| Credit.super-to-sub | Bool | The transfer direction. true for superaccount to subaccount, false for subaccount to superaccount | Yes | - |
Returns
| Code | Description |
|---|---|
| 201 | Credits were successfully moved. The HTTP Location header points to the API to recover credits |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get subaccount available credits
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result": "OK",
"credits": [
{
"message-type": "GP",
"amount": 20
},
{
"message-type": "SI",
"amount": 150
}
]
}
Returns the available credits of the given subaccount
HTTP Request
GET /API/v1.0/REST/subaccount/UserParam{subaccount_id}/credit
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| subaccount_id | Int or String | The subaccount ID or Login | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | Successful request, returns a JSON object with the available credits details |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Get a subaccount’s purchases
# Session Key example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XGET 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.get("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("GET");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase',
method: 'GET',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String response = wb.DownloadString("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase");
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase";
my $req = HTTP::Request->new(GET => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"result": "OK",
"purchases": [
{
"super-to-sub": false,
"amount": 37,
"create-time": "20160826104539",
"id_purchase": 20,
"price": 37,
"available": 0,
"message-types": [
{
"message-type": "N",
"unit-price": 1.2
},
{
"message-type": "LL",
"unit-price": 0.8
}
]
},
{
"super-to-sub": true,
"amount": 37,
"create-time": "20160826103027",
"id_purchase": 20,
"price": 37,
"available": 0,
"message-types": [
{
"message-type": "N",
"unit-price": 1.2
},
{
"message-type": "LL",
"unit-price": 0.8
}
]
}
],
"pageNumber": 1,
"pageSize": 10,
"total": 2
}
Returns the paginated list of purchases made by a subaccount. Caller must be a superaccount.
HTTP Request
GET /API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase?pageNumber=UserParam{page}&pageSize=UserParam{size}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| subaccount_id | Int or String | The subaccount ID or Login | Yes | - |
| pageNumber | Int | Return the given results page | No | 1 |
| pageSize | Int | The number of results in a page | No | 10 |
Returns
| Code | Description |
|---|---|
| 200 | The paginated list of the subaccount’s purchases |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Create a subaccount purchase
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"purchases": [
{
"super-to-sub": true,
"price": 25.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.1
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.7
}
]
},
{
"super-to-sub": true,
"price": 37.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.2
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.8
}
]
}
]
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"purchases": [
{
"super-to-sub": true,
"price": 25.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.1
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.7
}
]
},
{
"super-to-sub": true,
"price": 37.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.2
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.8
}
]
}
]
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"purchases": [
{
"super-to-sub": true,
"price": 25.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.1
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.7
}
]
},
{
"super-to-sub": true,
"price": 37.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.2
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.8
}
]
}
]
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"purchases\": [" +
" {" +
" \"super-to-sub\": true, " +
" \"price\": 25.0, " +
" \"message-types\": [" +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_1}\", " +
" \"unit-price\": 1.1" +
" }, " +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_2}\", " +
" \"unit-price\": 0.7" +
" }" +
" ]" +
" }, " +
" {" +
" \"super-to-sub\": true, " +
" \"price\": 37.0, " +
" \"message-types\": [" +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_1}\", " +
" \"unit-price\": 1.2" +
" }, " +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_2}\", " +
" \"unit-price\": 0.8" +
" }" +
" ]" +
" }" +
" ]" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "purchases": [' .
' {' .
' "super-to-sub": true, ' .
' "price": 25.0, ' .
' "message-types": [' .
' {' .
' "message-type": "UserParam{MESSAGE_TYPE_1}", ' .
' "unit-price": 1.1' .
' }, ' .
' {' .
' "message-type": "UserParam{MESSAGE_TYPE_2}", ' .
' "unit-price": 0.7' .
' }' .
' ]' .
' }, ' .
' {' .
' "super-to-sub": true, ' .
' "price": 37.0, ' .
' "message-types": [' .
' {' .
' "message-type": "UserParam{MESSAGE_TYPE_1}", ' .
' "unit-price": 1.2' .
' }, ' .
' {' .
' "message-type": "UserParam{MESSAGE_TYPE_2}", ' .
' "unit-price": 0.8' .
' }' .
' ]' .
' }' .
' ]' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"purchases": [
{
"super-to-sub": true,
"price": 25.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.1
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.7
}
]
},
{
"super-to-sub": true,
"price": 37.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.2
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.8
}
]
}
]
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase")
payload = {
"purchases": [
{
"super-to-sub": true,
"price": 25.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.1
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.7
}
]
},
{
"super-to-sub": true,
"price": 37.0,
"message-types": [
{
"message-type": "UserParam{MESSAGE_TYPE_1}",
"unit-price": 1.2
},
{
"message-type": "UserParam{MESSAGE_TYPE_2}",
"unit-price": 0.8
}
]
}
]
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"purchases\": [" +
" {" +
" \"super-to-sub\": true, " +
" \"price\": 25.0, " +
" \"message-types\": [" +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_1}\", " +
" \"unit-price\": 1.1" +
" }, " +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_2}\", " +
" \"unit-price\": 0.7" +
" }" +
" ]" +
" }, " +
" {" +
" \"super-to-sub\": true, " +
" \"price\": 37.0, " +
" \"message-types\": [" +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_1}\", " +
" \"unit-price\": 1.2" +
" }, " +
" {" +
" \"message-type\": \"UserParam{MESSAGE_TYPE_2}\", " +
" \"unit-price\": 0.8" +
" }" +
" ]" +
" }" +
" ]" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase", "POST", payload);
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"purchases" => [
{
"super-to-sub" => true,
"price" => 25.0,
"message-types" => [
{
"message-type" => "UserParam{MESSAGE_TYPE_1}",
"unit-price" => 1.1
},
{
"message-type" => "UserParam{MESSAGE_TYPE_2}",
"unit-price" => 0.7
}
]
},
{
"super-to-sub" => true,
"price" => 37.0,
"message-types" => [
{
"message-type" => "UserParam{MESSAGE_TYPE_1}",
"unit-price" => 1.2
},
{
"message-type" => "UserParam{MESSAGE_TYPE_2}",
"unit-price" => 0.8
}
]
}
]
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'create purchase' URL:
'Location': '/subaccount/{subaccount_id}/purchase'
Creates one or more purchases for the given subaccount. Subaccount
credit-eat-mode must be 2. Caller must be a superaccount.
HTTP Request
POST /API/v1.0/REST/subaccount/UserParam{subaccount}/purchase
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| subaccount_id | Int or String | The subaccount ID or Login | Yes | - |
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| purchases | List(Purchase) | The list of purchases to be created | Yes | - |
| Purchase.message-types | List(MessageType) | The purchase’s message types | Yes | - |
| Purchase.price | Float | The quantity of purchased credits | Yes | - |
| MessageType.message-type | String | The message type (“N” for High quality with reception notification, “L” for Medium Quality, “LL” For Low Cost) | Yes | - |
| MessageType.unit-price | Float | The cost for the subaccount of a unit of the respective message-type | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | Successful request. The HTTP location header that points to the subaccount ‘create purchase’ URL |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Delete a subaccount’s purchase
# Session Key example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}'
# Access token example
curl -XDELETE 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
r = requests.delete("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}", headers=headers)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
print('Success!')
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("DELETE");
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
System.out.println("Success!");
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
echo('Success!');
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}',
method: 'DELETE',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
console.log('Success!');
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}")
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Delete.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
puts "Success!"
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
wb.UploadValues("https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}", "DELETE", new NameValueCollection());
Console.WriteLine("Success!");
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}";
my $req = HTTP::Request->new(DELETE => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
print "Success!";
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{"result":"OK"}
Deletes a purchase of the given subaccount. Caller must be a
superaccount, and the Subaccount’s credit-eat-mode should be 2.
HTTP Request
DELETE /API/v1.0/REST/subaccount/UserParam{subaccount_id}/purchase/UserParam{purchase_id}
Parameters
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| subaccount_id | Int or String | The subaccount ID or Login | Yes | - |
| purchase_id | Int | The purchase ID | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | Successful request, purchase successfully deleted |
| 400 | Other errors, details are in the body |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Two Factor Authentication API
This is the part of the API that provides the Two Factor Authentication. The flow of 2FA is:
The User specifies his number in your App.
Your App sends a 2FA request via API.
The platform sends a text message to the specified recipient.
User receives the PIN via text message
User enters the PIN in your App.
Your App sends the 2FA verify via API and receives the authorization or an invalid pin error.
The text message is sent with the highest quality on a preferred route, to guarantee a quick delivery.
Request a 2FA Pin
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/2fa/request' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"recipient": "+393471234567"
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/2fa/request' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"recipient": "+393471234567"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"recipient": "+393471234567"
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/2fa/request", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/2fa/request");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"recipient\": \"+393471234567\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "recipient": "+393471234567"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/2fa/request');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/2fa/request',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"recipient": "+393471234567"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/2fa/request")
payload = {
"recipient": "+393471234567"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"recipient\": \"+393471234567\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/2fa/request", "POST", payload);
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/2fa/request";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"recipient" => "+393471234567"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"status": "OK"
}
On failure, the above command returns the following response:
{
"status": "ERROR",
"error": "Error cause"
}
Request a Two Factor Authentication via text message. This method generates a pin and sends it via text message to the user.
HTTP Request
POST /API/v1.0/REST/2fa/request
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| recipient | String | The phone number of the user. The format must be +1111111111 or 001111111111 | Yes | - |
| senderName | String | The sender name or number for the text message | No | Preferred Sender Name |
| expiry | Integer | The expiration time of the PIN, in minutes | No | 60 |
| messageBody | String | The message body. PIN position in the text can be specified using the %PIN% placeholder. If the placeholder is not provided the pin will be added at the end of message body. | No | A default message body per language. |
Returns
| Code | Description |
|---|---|
| 200 | Pin has been successfully sent via text message. |
| 400 | [Bad request] Invalid recipient, senderName, expiry, or sending errors like not enough credit. |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |
Verify a 2FA Pin
# Session Key example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/2fa/request' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Session_key: UserParam{session_key}' -d'
{
"recipient": "+393471234567",
"pin": "12345"
}
'
# Access token example
curl -XPOST 'https://sms.smsnet.it/API/v1.0/REST/2fa/request' -H 'Content-Type: application/json' \
-H 'user_key: UserParam{user_key}' -H 'Access_token: UserParam{access_token}' -d'
{
"recipient": "+393471234567",
"pin": "12345"
}
'
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': 'UserParam{user_key}', 'Access_token' : 'UserParam{access_token}', 'Content-type' : 'application/json' }
payload = """{
"recipient": "+393471234567",
"pin": "12345"
}"""
r = requests.post("https://sms.smsnet.it/API/v1.0/REST/2fa/request", headers=headers, data=payload)
if r.status_code != 200:
print("Error! http code: " + str(r.status_code) + ", body message: " + str(r.content))
else:
response = r.text
obj = json.loads(response)
print(unicode(obj))
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.io.OutputStream;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("https://sms.smsnet.it/API/v1.0/REST/2fa/request");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("user_key", "UserParam{user_key}");
// Use this when using Session Key authentication
conn.setRequestProperty("Session_key", "UserParam{session_key}");
// When using Access Token authentication, use this instead:
// conn.setRequestProperty("Access_token", "UserParam{access_token}");
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Content-type", "application/json");
conn.setDoOutput(true);
String payload = "{" +
" \"recipient\": \"+393471234567\", " +
" \"pin\": \"12345\"" +
"}";
OutputStream os = conn.getOutputStream();
os.write(payload.getBytes());
os.flush();
if (conn.getResponseCode() != 200) {
// Print the possible error contained in body response
String error = "";
String output;
BufferedReader errorbuffer = new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"));
while ((output = errorbuffer.readLine()) != null) {
error += output;
}
System.out.println("Error! HTTP error code : " + conn.getResponseCode() +
", Body message : " + error);
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
String response = "";
String output;
while ((output = br.readLine()) != null) {
response += output;
}
// You can parse the response using Google GSON or similar.
// MyObject should be a class that reflect the JSON
// structure of the response
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
MyObject responseObj = gson.fromJson(response, MyObject.class);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
<?php
$payload = '{' .
' "recipient": "+393471234567", ' .
' "pin": "12345"' .
'}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sms.smsnet.it/API/v1.0/REST/2fa/request');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'user_key: UserParam{user_key}',
// Use this when using session key authentication
'Session_key: UserParam{session_key}',
// When using Access Token authentication, use this instead:
// 'Access_token: UserParam{access_token}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if ($info['http_code'] != 200) {
echo('Error! http code: ' . $info['http_code'] . ', body message: ' . $response);
}
else {
$obj = json_decode($response);
print_r($obj);
}
?>
// Uses https://github.com/request/request
// npm install [-g] request
var request = require('request');
request({
url: 'https://sms.smsnet.it/API/v1.0/REST/2fa/request',
method: 'POST',
headers: { 'user_key' : 'UserParam{user_key}', 'Session_key' : 'UserParam{session_key}' },
json: true,
body: {
"recipient": "+393471234567",
"pin": "12345"
},
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
}
else {
console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
}
}
});
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse("https://sms.smsnet.it/API/v1.0/REST/2fa/request")
payload = {
"recipient": "+393471234567",
"pin": "12345"
}
# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = 'UserParam{user_key}'
request['Session_key'] = 'UserParam{session_key}'
request.body = payload.to_json
# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
obj = JSON.parse(response)
puts obj
else
puts "Error! http code: " + responseData.code + ", body message: " + responseData.body
end
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Collections.Specialized;
// We are using JSON.NET (http://www.newtonsoft.com/json)
using Newtonsoft.Json;
/*
* The following code has been compiled and tested using the MONO
* project.
*
* To compile using MONO:
* mcs -r:Newtonsoft.Json.dll example.cs
*/
namespace RestApplication
{
class Program
{
static void Main(string[] args)
{
using (var wb = new WebClient())
{
// Setting the encoding is required when sending UTF8 characters!
wb.Encoding = System.Text.Encoding.UTF8;
try {
wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
wb.Headers.Add("user_key", "UserParam{user_key}");
wb.Headers.Add("Session_key", "UserParam{session_key}");
String payload = "{" +
" \"recipient\": \"+393471234567\", " +
" \"pin\": \"12345\"" +
"}";
String response = wb.UploadString("https://sms.smsnet.it/API/v1.0/REST/2fa/request", "POST", payload);
dynamic obj = JsonConvert.DeserializeObject(response);
Console.WriteLine(obj);
} catch (WebException ex) {
var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
var errorResponse = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
Console.WriteLine("Error!, http code: " + statusCode + ", body message: ");
Console.WriteLine(errorResponse);
}
}
}
}
}
#!/usr/bin/env perl
use warnings;
use strict;
use LWP::UserAgent;
# Install using Cpan: "cpan JSON URI"
use JSON;
use URI::Escape;
my $ua = LWP::UserAgent->new;
my $server_endpoint = "https://sms.smsnet.it/API/v1.0/REST/2fa/request";
my $req = HTTP::Request->new(POST => $server_endpoint);
$req->header('Content_type' => 'application/json');
# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
':Session_key' => $auth->[1]);
my $payload = {
"recipient" => "+393471234567",
"pin" => "12345"
};
$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
my $response = $resp->decoded_content;
my $obj = from_json($response);
} else {
my $error = $resp->decoded_content;
my $code = $resp->code;
print "Error!, http code: $code, body message: $error ";
}
On success, the above command returns the following response:
{
"status": "OK"
}
On wrong pin, the above command returns the following response:
{
"status": "ERROR",
"error": "Wrong pin",
"triesRemaining": 2
}
On failure, the above command returns the following response:
{
"status": "ERROR",
"error": "Error cause"
}
Verify that the pin inserted by the user is valid.
HTTP Request
POST /API/v1.0/REST/2fa/verify
Body Fields
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
| recipient | String | The phone number of the user. The format must be +1111111111 or 001111111111 | Yes | - |
| pin | String | The pin inserted by the user | Yes | - |
Returns
| Code | Description |
|---|---|
| 200 | If status is OK the 2FA is valid, if status is ERROR the passed pin is wrong and the response includes the number of tries remaining. |
| 400 | [Bad request] Invalid recipient |
| 401 | [Unauthorized] User_key, Token or Session_key are invalid or not provided |
| 404 | [Not found] The User_key was not found |