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'