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.

Remember to provide the authentication HTTP headers as described in the Authenticate using a session key and the Authenticate using a user tokeny sections.
All the query string parameters in URL must be UTF-8 URL Encoded.

Add a contact

Add a contact to the user’s addressbook.

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/contact

Body Fields

Parameter Type Description Required Default
email 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 “”
At least one between the `email` and the `phoneNumber` fields has to be provided

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
Copy code
# Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contact' -H 'Content-Type: application/json' \
-H 'user_key: {USER_KEY}' -H 'Session_key: {SESSION_KEY}' -d'
{
    "email": "{EMAIL}", 
    "phoneNumber": "{PHONENUMBER}", 
    "name": "{NAME}", 
    "surname": "{SURNAME}", 
    "gender": "{GENDER}", 
    "fax": "{FAX}", 
    "zip": "{ZIP}", 
    "address": "{ADDRESS}", 
    "city": "{CITY}", 
    "province": "{PROVINCE}", 
    "birthdate": "{BIRTHDATE}", 
    "groupIds": [
        "{GRP1}", 
        "{GRP2}"
    ]
}
'

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contact' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}' -d'
{
    "email": "{EMAIL}", 
    "phoneNumber": "{PHONENUMBER}", 
    "name": "{NAME}", 
    "surname": "{SURNAME}", 
    "gender": "{GENDER}", 
    "fax": "{FAX}", 
    "zip": "{ZIP}", 
    "address": "{ADDRESS}", 
    "city": "{CITY}", 
    "province": "{PROVINCE}", 
    "birthdate": "{BIRTHDATE}", 
    "groupIds": [
        "{GRP1}", 
        "{GRP2}"
    ]
}
'
On success, the above command returns the following response:
# The HTTP location header that points to the created contact:
Location': '/contact/AVvZEwZHHnl8wUZve6CT'
Copy code
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://app.gateway.smsend.it/API/v1.0/REST/contact");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setRequestProperty("user_key", "{USER_KEY}");

            // Use this when using Session Key authentication
            conn.setRequestProperty("Session_key", "{SESSION_KEY}");                  
            // When using Access Token authentication, use this instead:
            // conn.setRequestProperty("Access_token", "{ACCESS_TOKEN}");

            conn.setRequestMethod("POST");

            conn.setRequestProperty("Accept", "application/json");
            conn.setRequestProperty("Content-type", "application/json");
            conn.setDoOutput(true);

            String payload = "{" + 
              "    \"email\": \"{EMAIL}\", " + 
              "    \"phoneNumber\": \"{PHONENUMBER}\", " + 
              "    \"name\": \"{NAME}\", " + 
              "    \"surname\": \"{SURNAME}\", " + 
              "    \"gender\": \"{GENDER}\", " + 
              "    \"fax\": \"{FAX}\", " + 
              "    \"zip\": \"{ZIP}\", " + 
              "    \"address\": \"{ADDRESS}\", " + 
              "    \"city\": \"{CITY}\", " + 
              "    \"province\": \"{PROVINCE}\", " + 
              "    \"birthdate\": \"{BIRTHDATE}\", " + 
              "    \"groupIds\": [" + 
              "        \"{GRP1}\", " + 
              "        \"{GRP2}\"" + 
              "    ]" + 
              "}";

            OutputStream os = conn.getOutputStream();
            os.write(payload.getBytes());
            os.flush();

            if (conn.getResponseCode() != 201) {
                throw new RuntimeException("Failed : HTTP error code : "
                                           + conn.getResponseCode());
            }
            System.out.println("Success!");
            conn.disconnect();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
On success, the above command returns the following response:
# The HTTP location header that points to the created contact:
'Location': '/contact/AVvZEwZHHnl8wUZve6CT'
Copy code
<?php

$payload = '{' . 
  '    "email": "{EMAIL}", ' . 
  '    "phoneNumber": "{PHONENUMBER}", ' . 
  '    "name": "{NAME}", ' . 
  '    "surname": "{SURNAME}", ' . 
  '    "gender": "{GENDER}", ' . 
  '    "fax": "{FAX}", ' . 
  '    "zip": "{ZIP}", ' . 
  '    "address": "{ADDRESS}", ' . 
  '    "city": "{CITY}", ' . 
  '    "province": "{PROVINCE}", ' . 
  '    "birthdate": "{BIRTHDATE}", ' . 
  '    "groupIds": [' . 
  '        "{GRP1}", ' . 
  '        "{GRP2}"' . 
  '    ]' . 
  '}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/contact');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'user_key: {USER_KEY}',
    // Use this when using session key authentication
    'Session_key: {SESSION_KEY}',
    // When using Access Token authentication, use this instead:
    // 'Access_token: {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!');
}
else {
    echo('Success!');
}
?>
On success, the above command returns the following response:
# The HTTP location header that points to the created contact:
'Location': '/contact/AVvZEwZHHnl8wUZve6CT'
Copy code
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': '{USER_KEY}', 'Session_key' : '{SESSION_KEY}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': '{USER_KEY}', 'Access_token' : '{ACCESS_TOKEN}', 'Content-type' : 'application/json' }
payload = """{
    "email": "{EMAIL}", 
    "phoneNumber": "{PHONENUMBER}", 
    "name": "{NAME}", 
    "surname": "{SURNAME}", 
    "gender": "{GENDER}", 
    "fax": "{FAX}", 
    "zip": "{ZIP}", 
    "address": "{ADDRESS}", 
    "city": "{CITY}", 
    "province": "{PROVINCE}", 
    "birthdate": "{BIRTHDATE}", 
    "groupIds": [
        "{GRP1}", 
        "{GRP2}"
    ]
}"""

r = requests.post("https://app.gateway.smsend.it/API/v1.0/REST/contact", headers=headers, data=payload)

if r.status_code != 201:
    print("An error occurred, return code is: " + str(r.status_code))
else:
    print('Success!')
On success, the above command returns the following response:
# The HTTP location header that points to the created contact:
'Location': '/contact/AVvZEwZHHnl8wUZve6CT'
Copy code
// Uses https://github.com/request/request
// npm install [-g] request

var request = require('request');

request({
    url: 'https://app.gateway.smsend.it/API/v1.0/REST/contact',
    method: 'POST',
    headers: { 'user_key' : '{USER_KEY}', 'Session_key' : '{SESSION_KEY}' },

    json: true,
    body:     {
        "email": "{EMAIL}", 
        "phoneNumber": "{PHONENUMBER}", 
        "name": "{NAME}", 
        "surname": "{SURNAME}", 
        "gender": "{GENDER}", 
        "fax": "{FAX}", 
        "zip": "{ZIP}", 
        "address": "{ADDRESS}", 
        "city": "{CITY}", 
        "province": "{PROVINCE}", 
        "birthdate": "{BIRTHDATE}", 
        "groupIds": [
            "{GRP1}", 
            "{GRP2}"
        ]
    },

    callback: function (error, responseMeta, response) {
        if (!error && responseMeta.statusCode == 201) {
            console.log('Success!');
        }
        else {
            console.log('An error occurred..');
        }
    }
});
On success, the above command returns the following response:
# The HTTP location header that points to the created contact:
'Location': '/contact/AVvZEwZHHnl8wUZve6CT'
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/contact")
payload =     {
        "email": "{EMAIL}", 
        "phoneNumber": "{PHONENUMBER}", 
        "name": "{NAME}", 
        "surname": "{SURNAME}", 
        "gender": "{GENDER}", 
        "fax": "{FAX}", 
        "zip": "{ZIP}", 
        "address": "{ADDRESS}", 
        "city": "{CITY}", 
        "province": "{PROVINCE}", 
        "birthdate": "{BIRTHDATE}", 
        "groupIds": [
            "{GRP1}", 
            "{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'] = '{USER_KEY}'
request['Session_key'] = '{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.."
end
On success, the above command returns the following response:
# The HTTP location header that points to the created contact:
'Location': '/contact/AVvZEwZHHnl8wUZve6CT'
Copy code
using System;
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())
            {
                wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
                wb.Headers.Add("user_key", "{USER_KEY}");
                wb.Headers.Add("Session_key", "{SESSION_KEY}");

                String payload = "{" + 
                  "    \"email\": \"{EMAIL}\", " + 
                  "    \"phoneNumber\": \"{PHONENUMBER}\", " + 
                  "    \"name\": \"{NAME}\", " + 
                  "    \"surname\": \"{SURNAME}\", " + 
                  "    \"gender\": \"{GENDER}\", " + 
                  "    \"fax\": \"{FAX}\", " + 
                  "    \"zip\": \"{ZIP}\", " + 
                  "    \"address\": \"{ADDRESS}\", " + 
                  "    \"city\": \"{CITY}\", " + 
                  "    \"province\": \"{PROVINCE}\", " + 
                  "    \"birthdate\": \"{BIRTHDATE}\", " + 
                  "    \"groupIds\": [" + 
                  "        \"{GRP1}\", " + 
                  "        \"{GRP2}\"" + 
                  "    ]" + 
                  "}";

                String response = wb.UploadString("https://app.gateway.smsend.it/API/v1.0/REST/contact", "POST", payload)
                Console.WriteLine("Success!");
            }

        }
    }
}
On success, the above command returns the following response:
# The HTTP location header that points to the created contact:
'Location': '/contact/AVvZEwZHHnl8wUZve6CT'
Copy code
#!/usr/bin/env perl

use warnings;
use strict;
use LWP::UserAgent;

# Install using Cpan: "cpan JSON"
use JSON;

my $ua = LWP::UserAgent->new;

my $server_endpoint = "https://app.gateway.smsend.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" => "{EMAIL}", 
    "phoneNumber" => "{PHONENUMBER}", 
    "name" => "{NAME}", 
    "surname" => "{SURNAME}", 
    "gender" => "{GENDER}", 
    "fax" => "{FAX}", 
    "zip" => "{ZIP}", 
    "address" => "{ADDRESS}", 
    "city" => "{CITY}", 
    "province" => "{PROVINCE}", 
    "birthdate" => "{BIRTHDATE}", 
    "groupIds" => [
        "{GRP1}", 
        "{GRP2}"
    ]
};

$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
  $response = $resp->decoded_content;
  print "Success!";

}
On success, the above command returns the following response:
# The HTTP location header that points to the created contact:
'Location': '/contact/AVvZEwZHHnl8wUZve6CT'

Add multiple contacts

Add multiple contacts to the user’s addressbook.

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

https://app.gateway.smsend.it/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
At least one between the `email` and the `phoneNumber` fields has to be provided for each contact
If one or more contacts are badly formatted, no contacts will be saved, and the response will have http status 400

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
Copy code
# Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contacts' -H 'Content-Type: application/json' \
-H 'user_key: USER_KEY' -H 'Session_key: SESSION_KEY' -d'
{
    "contacts": [
        {
            "email": "EMAIL", 
            "phoneNumber": "PHONENUMBER", 
            "name": "NAME", 
            "surname": "SURNAME"
        }, 
        {
            "email": "EMAIL", 
            "phoneNumber": "PHONENUMBER", 
            "name": "NAME", 
            "surname": "SURNAME"
        }
    ], 
    "updateExistingContact": true
}
'

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contacts' -H 'Content-Type: application/json' \
 -H 'user_key: USER_KEY' -H 'Access_token: ACCESS_TOKEN' -d'
{
    "contacts": [
        {
            "email": "EMAIL", 
            "phoneNumber": "PHONENUMBER", 
            "name": "NAME", 
            "surname": "SURNAME"
        }, 
        {
            "email": "EMAIL", 
            "phoneNumber": "PHONENUMBER", 
            "name": "NAME", 
            "surname": "SURNAME"
        }
    ], 
    "updateExistingContact": true
}
'
On success, the above command returns the following response:
1
Copy code
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://app.gateway.smsend.it/API/v1.0/REST/contacts");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setRequestProperty("user_key", "USER_KEY");

            // Use this when using Session Key authentication
            conn.setRequestProperty("Session_key", "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\": \"EMAIL\", " + 
              "            \"phoneNumber\": \"PHONENUMBER\", " + 
              "            \"name\": \"NAME\", " + 
              "            \"surname\": \"SURNAME\"" + 
              "        }, " + 
              "        {" + 
              "            \"email\": \"EMAIL\", " + 
              "            \"phoneNumber\": \"PHONENUMBER\", " + 
              "            \"name\": \"NAME\", " + 
              "            \"surname\": \"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();
        }
    }
}
On success, the above command returns the following response:
1
Copy code
<?php

$payload = '{' . 
  '    "contacts": [' . 
  '        {' . 
  '            "email": "EMAIL", ' . 
  '            "phoneNumber": "PHONENUMBER", ' . 
  '            "name": "NAME", ' . 
  '            "surname": "SURNAME"' . 
  '        }, ' . 
  '        {' . 
  '            "email": "EMAIL", ' . 
  '            "phoneNumber": "PHONENUMBER", ' . 
  '            "name": "NAME", ' . 
  '            "surname": "SURNAME"' . 
  '        }' . 
  '    ], ' . 
  '    "updateExistingContact": true' . 
  '}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/contacts');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'user_key: USER_KEY',
    // Use this when using session key authentication
    'Session_key: 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!');
}
?>
On success, the above command returns the following response:
1
Copy code
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'USER_KEY', 'Session_key' : '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": "EMAIL", 
            "phoneNumber": "PHONENUMBER", 
            "name": "NAME", 
            "surname": "SURNAME"
        }, 
        {
            "email": "EMAIL", 
            "phoneNumber": "PHONENUMBER", 
            "name": "NAME", 
            "surname": "SURNAME"
        }
    ], 
    "updateExistingContact": true
}"""

r = requests.post("https://app.gateway.smsend.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!')
On success, the above command returns the following response:
1
Copy code
// Uses https://github.com/request/request
// npm install [-g] request

var request = require('request');

request({
    url: 'https://app.gateway.smsend.it/API/v1.0/REST/contacts',
    method: 'POST',
    headers: { 'user_key' : 'USER_KEY', 'Session_key' : 'SESSION_KEY' },

    json: true,
    body:     {
        "contacts": [
            {
                "email": "EMAIL", 
                "phoneNumber": "PHONENUMBER", 
                "name": "NAME", 
                "surname": "SURNAME"
            }, 
            {
                "email": "EMAIL", 
                "phoneNumber": "PHONENUMBER", 
                "name": "NAME", 
                "surname": "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)
        }
    }
});
On success, the above command returns the following response:
1
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/contacts")
payload =     {
        "contacts": [
            {
                "email": "EMAIL", 
                "phoneNumber": "PHONENUMBER", 
                "name": "NAME", 
                "surname": "SURNAME"
            }, 
            {
                "email": "EMAIL", 
                "phoneNumber": "PHONENUMBER", 
                "name": "NAME", 
                "surname": "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'] = 'USER_KEY'
request['Session_key'] = '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
On success, the above command returns the following response:
1
Copy code
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", "USER_KEY");
                    wb.Headers.Add("Session_key", "SESSION_KEY");

                String payload = "{" + 
                  "    \"contacts\": [" + 
                  "        {" + 
                  "            \"email\": \"EMAIL\", " + 
                  "            \"phoneNumber\": \"PHONENUMBER\", " + 
                  "            \"name\": \"NAME\", " + 
                  "            \"surname\": \"SURNAME\"" + 
                  "        }, " + 
                  "        {" + 
                  "            \"email\": \"EMAIL\", " + 
                  "            \"phoneNumber\": \"PHONENUMBER\", " + 
                  "            \"name\": \"NAME\", " + 
                  "            \"surname\": \"SURNAME\"" + 
                  "        }" + 
                  "    ], " + 
                  "    \"updateExistingContact\": true" + 
                  "}";

                    String response = wb.UploadString("https://app.gateway.smsend.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);
                }
            }
        }
    }
}
On success, the above command returns the following response:
1
Copy code
#!/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://app.gateway.smsend.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" => "EMAIL", 
            "phoneNumber" => "PHONENUMBER", 
            "name" => "NAME", 
            "surname" => "SURNAME"
        }, 
        {
            "email" => "EMAIL", 
            "phoneNumber" => "PHONENUMBER", 
            "name" => "NAME", 
            "surname" => "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:
1

Get a contact

Get a contact’s details

HTTP Headers

user_key / Session_key

HTTP Method

GET

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}

Parameters

Parameter Type Description Required Default
contactid 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 contactid was not found
Copy code
# Session Key example
curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}' -H 'Content-Type: application/json' \
-H 'user_key: {USER_KEY}' -H 'Session_key: {SESSION_KEY}' 

# Access token example
curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}' 
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
}
Copy code
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://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setRequestProperty("user_key", "{USER_KEY}");

            // Use this when using Session Key authentication
            conn.setRequestProperty("Session_key", "{SESSION_KEY}");                  
            // When using Access Token authentication, use this instead:
            // conn.setRequestProperty("Access_token", "{ACCESS_TOKEN}");

            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;
            }
            // 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();
        }
    }
}
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
}
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'user_key: {USER_KEY}',
    // Use this when using session key authentication
    'Session_key: {SESSION_KEY}',
    // When using Access Token authentication, use this instead:
    // 'Access_token: {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!');
}
else {

    $obj = json_decode($response);
    print_r($obj);
}
?>
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
}
Copy code
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': '{USER_KEY}', 'Session_key' : '{SESSION_KEY}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': '{USER_KEY}', 'Access_token' : '{ACCESS_TOKEN}', 'Content-type' : 'application/json' }

r = requests.get("https://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}", headers=headers)

if r.status_code != 200:
    print("An error occurred, return code is: " + str(r.status_code))
else:
    response = r.text

    obj = json.loads(response)
    print(unicode(obj))
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
}
Copy code
// Uses https://github.com/request/request
// npm install [-g] request

var request = require('request');

request({
    url: 'https://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}',
    method: 'GET',
    headers: { 'user_key' : '{USER_KEY}', 'Session_key' : '{SESSION_KEY}' },

    callback: function (error, responseMeta, response) {
        if (!error && responseMeta.statusCode == 200) {

        }
        else {
            console.log('An error occurred..');
        }
    }
});
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
}
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}")

# 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'] = '{USER_KEY}'
request['Session_key'] = '{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.."
end
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
}
Copy code
using System;
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())
            {
                wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
                wb.Headers.Add("user_key", "{USER_KEY}");
                wb.Headers.Add("Session_key", "{SESSION_KEY}");

                String response = wb.DownloadString("https://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}");

                dynamic obj = JsonConvert.DeserializeObject(response);
                Console.WriteLine(obj);
            }

        }
    }
}
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
}
Copy code
#!/usr/bin/env perl

use warnings;
use strict;
use LWP::UserAgent;

# Install using Cpan: "cpan JSON"
use JSON;

my $ua = LWP::UserAgent->new;

my $server_endpoint = "https://app.gateway.smsend.it/API/v1.0/REST/contact/{contactid}";

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) {
  $response = $resp->decoded_content;
  my $obj = from_json($response);

}
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
}

Registration of a contact to a list

Creates a new contact entry and adds it onto the specified campaign.

These APIs are intended to be used in external “User registration forms” where a user is invited to Opt-in by submitting an email address together with some other personal data (e.g. first name and last name)

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/list/{campaign_id}/contact?SendOptIn={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
email 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
Copy code
# Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/list/{campaign_id}/contact' -H 'Content-Type: application/json' \
-H 'user_key: {USER_KEY}' -H 'Session_key: {SESSION_KEY}' -d'
{
    "email": "{EMAIL}", 
    "phoneNumber": "{PHONE_NUMBER}"
}
'

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/list/{campaign_id}/contact' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}' -d'
{
    "email": "{EMAIL}", 
    "phoneNumber": "{PHONE_NUMBER}"
}
'
On success, the above command returns the following response:
""
Copy code
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://app.gateway.smsend.it/API/v1.0/REST/list/{campaign_id}/contact");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setRequestProperty("user_key", "{USER_KEY}");

            // Use this when using Session Key authentication
            conn.setRequestProperty("Session_key", "{SESSION_KEY}");                  
            // When using Access Token authentication, use this instead:
            // conn.setRequestProperty("Access_token", "{ACCESS_TOKEN}");

            conn.setRequestMethod("POST");

            conn.setRequestProperty("Accept", "application/json");
            conn.setRequestProperty("Content-type", "application/json");
            conn.setDoOutput(true);

            String payload = "{" + 
              "    \"email\": \"{EMAIL}\", " + 
              "    \"phoneNumber\": \"{PHONE_NUMBER}\"" + 
              "}";

            OutputStream os = conn.getOutputStream();
            os.write(payload.getBytes());
            os.flush();

            if (conn.getResponseCode() != 201) {
                throw new RuntimeException("Failed : HTTP error code : "
                                           + conn.getResponseCode());
            }
            System.out.println("Success!");
            conn.disconnect();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}
On success, the above command returns the following response:
""
Copy code
<?php

$payload = '{' . 
  '    "email": "{EMAIL}", ' . 
  '    "phoneNumber": "{PHONE_NUMBER}"' . 
  '}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/list/{campaign_id}/contact');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'user_key: {USER_KEY}',
    // Use this when using session key authentication
    'Session_key: {SESSION_KEY}',
    // When using Access Token authentication, use this instead:
    // 'Access_token: {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!');
}
else {
    echo('Success!');
}
?>
On success, the above command returns the following response:
""
Copy code
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': '{USER_KEY}', 'Session_key' : '{SESSION_KEY}', 'Content-type' : 'application/json' }
# When using Access Token authentication, use this instead:
# headers = { 'user_key': '{USER_KEY}', 'Access_token' : '{ACCESS_TOKEN}', 'Content-type' : 'application/json' }
payload = """{
    "email": "{EMAIL}", 
    "phoneNumber": "{PHONE_NUMBER}"
}"""

r = requests.post("https://app.gateway.smsend.it/API/v1.0/REST/list/{campaign_id}/contact", headers=headers, data=payload)

if r.status_code != 201:
    print("An error occurred, return code is: " + str(r.status_code))
else:
    print('Success!')
On success, the above command returns the following response:
""
Copy code
// Uses https://github.com/request/request
// npm install [-g] request

var request = require('request');

request({
    url: 'https://app.gateway.smsend.it/API/v1.0/REST/list/{campaign_id}/contact',
    method: 'POST',
    headers: { 'user_key' : '{USER_KEY}', 'Session_key' : '{SESSION_KEY}' },

    json: true,
    body:     {
        "email": "{EMAIL}", 
        "phoneNumber": "{PHONE_NUMBER}"
    },

    callback: function (error, responseMeta, response) {
        if (!error && responseMeta.statusCode == 201) {
            console.log('Success!');
        }
        else {
            console.log('An error occurred..');
        }
    }
});
On success, the above command returns the following response:
""
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/list/{campaign_id}/contact")
payload =     {
        "email": "{EMAIL}", 
        "phoneNumber": "{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'] = '{USER_KEY}'
request['Session_key'] = '{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.."
end
On success, the above command returns the following response:
""
Copy code
using System;
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())
            {
                wb.Headers.Set(HttpRequestHeader.ContentType, "application/json");
                wb.Headers.Add("user_key", "{USER_KEY}");
                wb.Headers.Add("Session_key", "{SESSION_KEY}");

                String payload = "{" + 
                  "    \"email\": \"{EMAIL}\", " + 
                  "    \"phoneNumber\": \"{PHONE_NUMBER}\"" + 
                  "}";

                String response = wb.UploadString("https://app.gateway.smsend.it/API/v1.0/REST/list/{campaign_id}/contact", "POST", payload)
                Console.WriteLine("Success!");
            }

        }
    }
}
On success, the above command returns the following response:
""
Copy code
#!/usr/bin/env perl

use warnings;
use strict;
use LWP::UserAgent;

# Install using Cpan: "cpan JSON"
use JSON;

my $ua = LWP::UserAgent->new;

my $server_endpoint = "https://app.gateway.smsend.it/API/v1.0/REST/list/{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" => "{EMAIL}", 
    "phoneNumber" => "{PHONE_NUMBER}"
};

$req->content(to_json($payload));
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 201) {
  $response = $resp->decoded_content;
  print "Success!";

}
On success, the above command returns the following response:
""

List contact’s custom fields

Returns the list of user’s defined custom fields

HTTP Headers

user_key / Session_key

HTTP Method

GET

HTTP Request

https://api.smsend.it/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
Copy code
# Session Key example
curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/contacts/fields' -H 'Content-Type: application/json' \
-H 'user_key: USER_KEY' -H 'Session_key: SESSION_KEY' 

# Access token example
curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/contacts/fields' -H 'Content-Type: application/json' \
 -H 'user_key: USER_KEY' -H 'Access_token: ACCESS_TOKEN'
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}"
  }
]
Copy code
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://app.gateway.smsend.it/API/v1.0/REST/contacts/fields");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setRequestProperty("user_key", "USER_KEY");

            // Use this when using Session Key authentication
            conn.setRequestProperty("Session_key", "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();
        }
    }
}
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}"
  }
]
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/contacts/fields');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'user_key: USER_KEY',
    // Use this when using session key authentication
    'Session_key: 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);
}
?>
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}"
  }
]
Copy code
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'USER_KEY', 'Session_key' : '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://app.gateway.smsend.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))
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}"
  }
]
Copy code
// Uses https://github.com/request/request
// npm install [-g] request

var request = require('request');

request({
    url: 'https://app.gateway.smsend.it/API/v1.0/REST/contacts/fields',
    method: 'GET',
    headers: { 'user_key' : 'USER_KEY', 'Session_key' : 'SESSION_KEY' },

    callback: function (error, responseMeta, response) {
        if (!error && responseMeta.statusCode == 200) {

        }
        else {
            console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
        }
    }
});
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}"
  }
]
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.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'] = 'USER_KEY'
request['Session_key'] = '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
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}"
  }
]
Copy code
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", "USER_KEY");
                    wb.Headers.Add("Session_key", "SESSION_KEY");

                    String response = wb.DownloadString("https://app.gateway.smsend.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);
                }
            }
        }
    }
}
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}"
  }
]
Copy code
#!/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://app.gateway.smsend.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}"
  }
]

Add contact to sms blacklist

Returns the result of operation

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist/CONTACT_ID

Parameters

Parameter Type Description Required Default
CONTACT_ID String The id of the contact that will be added Yes -

Returns

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
Copy code
# Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist/CONTACT_ID' -H 'Content-Type: application/json' \
-H 'user_key: USER_KEY' -H 'Session_key: SESSION_KEY' 

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist/CONTACT_ID' -H 'Content-Type: application/json' \
 -H 'user_key: USER_KEY' -H 'Access_token: ACCESS_TOKEN' 
'
On success, the above command returns the following response:
true
Copy code
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://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist/CONTACT_ID");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setRequestProperty("user_key", "USER_KEY");

            // Use this when using Session Key authentication
            conn.setRequestProperty("Session_key", "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();
        }
    }
}
On success, the above command returns the following response:
true
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist/CONTACT_ID');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'user_key: USER_KEY',
    // Use this when using session key authentication
    'Session_key: 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);
}
?>
On success, the above command returns the following response:
true
Copy code
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'USER_KEY', 'Session_key' : '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://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist/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))
On success, the above command returns the following response:
true
Copy code
// Uses https://github.com/request/request
// npm install [-g] request

var request = require('request');

request({
    url: 'https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist/CONTACT_ID',
    method: 'POST',
    headers: { 'user_key' : 'USER_KEY', 'Session_key' : 'SESSION_KEY' },

    callback: function (error, responseMeta, response) {
        if (!error && responseMeta.statusCode == 200) {

        }
        else {
            console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
        }
    }
});
On success, the above command returns the following response:
true
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist/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'] = 'USER_KEY'
request['Session_key'] = '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
On success, the above command returns the following response:
true
Copy code
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", "USER_KEY");
                    wb.Headers.Add("Session_key", "SESSION_KEY");

                    String response = wb.UploadString("https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist/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);
                }
            }
        }
    }
}
On success, the above command returns the following response:
true
Copy code
#!/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://app.gateway.smsend.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:
true

Add multiple contacts to sms blacklist

Add multiple contacts to the user’s blacklist.

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist_batch

Body Fields

Parameter Type Description Required Default
List(String) Array of contact ids Yes “”
If one or more contact ids aren’t found, no contacts will be put in blacklist, and the response will have http status 400

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
Copy code
# Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist_batch' -H 'Content-Type: application/json' \
-H 'user_key: USER_KEY' -H 'Session_key: SESSION_KEY' -d'
[
    "AV3vrSlPuGYfQz6BgjeI", 
    "BVvrSlPuGYfQz6BgjeI"
]
'

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist_batch' -H 'Content-Type: application/json' \
 -H 'user_key: USER_KEY' -H 'Access_token: ACCESS_TOKEN' -d'
[
    "AV3vrSlPuGYfQz6BgjeI", 
    "BVvrSlPuGYfQz6BgjeI"
]
'
On success, the above command returns the following response:
2
Copy code
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://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist_batch");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setRequestProperty("user_key", "USER_KEY");

            // Use this when using Session Key authentication
            conn.setRequestProperty("Session_key", "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();
        }
    }
}
On success, the above command returns the following response:
2
Copy code
<?php

$payload = '[' . 
  '    "AV3vrSlPuGYfQz6BgjeI", ' . 
  '    "BVvrSlPuGYfQz6BgjeI"' . 
  ']';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist_batch');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'user_key: USER_KEY',
    // Use this when using session key authentication
    'Session_key: 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!');
}
?>
On success, the above command returns the following response:
2
Copy code
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'USER_KEY', 'Session_key' : '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://app.gateway.smsend.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!')
On success, the above command returns the following response:
2
Copy code
// Uses https://github.com/request/request
// npm install [-g] request

var request = require('request');

request({
    url: 'https://app.gateway.smsend.it/API/v1.0/REST/contact/add_to_blacklist_batch',
    method: 'POST',
    headers: { 'user_key' : 'USER_KEY', 'Session_key' : '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)
        }
    }
});
On success, the above command returns the following response:
2
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.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'] = 'USER_KEY'
request['Session_key'] = '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
On success, the above command returns the following response:
2
Copy code
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", "USER_KEY");
                    wb.Headers.Add("Session_key", "SESSION_KEY");

                String payload = "[" + 
                  "    \"AV3vrSlPuGYfQz6BgjeI\", " + 
                  "    \"BVvrSlPuGYfQz6BgjeI\"" + 
                  "]";

                    String response = wb.UploadString("https://app.gateway.smsend.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);
                }
            }
        }
    }
}
On success, the above command returns the following response:
2
Copy code
#!/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://app.gateway.smsend.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 phone number to sms blacklist

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=PHONE_NUMBER

Parameters

Parameter Type Description Required Default
phoneNumber String The phone number that will be added to blacklist Yes -

Returns the result of operation

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
Copy code
# Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=PHONE_NUMBER' -H 'Content-Type: application/json' \
-H 'user_key: USER_KEY' -H 'Session_key: SESSION_KEY' 

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=PHONE_NUMBER' -H 'Content-Type: application/json' \
 -H 'user_key: USER_KEY' -H 'Access_token: ACCESS_TOKEN'
On success, the above command returns the following response:
true
Copy code
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://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=PHONE_NUMBER");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setRequestProperty("user_key", "USER_KEY");

            // Use this when using Session Key authentication
            conn.setRequestProperty("Session_key", "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();
        }
    }
}
On success, the above command returns the following response:
true
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=PHONE_NUMBER');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-type: application/json',
    'user_key: USER_KEY',
    // Use this when using session key authentication
    'Session_key: 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);
}
?>
On success, the above command returns the following response:
true
Copy code
# pip install requests
import requests
import json
# Use this when using Session Key authentication
headers = { 'user_key': 'USER_KEY', 'Session_key' : '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://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=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))
On success, the above command returns the following response:
true
Copy code
// Uses https://github.com/request/request
// npm install [-g] request

var request = require('request');

request({
    url: 'https://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=PHONE_NUMBER',
    method: 'POST',
    headers: { 'user_key' : 'USER_KEY', 'Session_key' : 'SESSION_KEY' },

    callback: function (error, responseMeta, response) {
        if (!error && responseMeta.statusCode == 200) {

        }
        else {
            console.log('Error! http code: ' + responseMeta.statusCode + ', body message: ' + response)
        }
    }
});
On success, the above command returns the following response:
true
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=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'] = 'USER_KEY'
request['Session_key'] = '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
On success, the above command returns the following response:
true
Copy code
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", "USER_KEY");
                    wb.Headers.Add("Session_key", "SESSION_KEY");

                    String response = wb.UploadString("https://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=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);
                }
            }
        }
    }
}
On success, the above command returns the following response:
true
Copy code
#!/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://app.gateway.smsend.it/API/v1.0/REST/contacts/add_to_blacklist?phoneNumber=".uri_escape("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