Authentication API

Authentication methods

The following are the two available methods to authenticate a user, given a username and a password (registration required):

  • Using a temporary session key, which expires after a certain amount of time has passed with no performed API calls with that key.

  • Using a temporary session key, which expires after a certain amount of time has passed with no performed API calls with that key.

In both cases, the returned user_key, as well as the session key or the token, are required to be provided in the HTTP request headers in order to perform any API call after the login.

Authenticate using a session key

The login with session key API lets you authenticate by using your username and password, and returns a token to be used for authenticating the next API calls.

The following HTTP headers should be provided after the login:

user_key:{USER_KEY}

Session_key:{SESSION_KEY}

Where {USER_KEY} and {SESSION_KEY} are the values returned by the login API.

{USER_KEY} and {SESSION_KEY} placeholders can be found in all code examples. When actually running the example, the correct values must be used instead.
The returned session key expires when no API calls are performed for 5 minutes)

HTTP Method

GET

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/login?username={USERNAME}&password={PASSWORD}

Parameters

Parameter Type Description Required Default
username String Your account’s username Yes -
password String Your account’s password Yes -

Returns

Code Description
200 The user_key and the session_key
404 [Not found] Credentials are incorrect
400 Other errors, details are in the body
Copy code
# Session Key example

curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/login?username={username}&password={password}' -H 'Content-Type: application/json'  

# Access token example

curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/login?username={username}&password={password}' -H 'Content-Type: application/json'
On success, the above command returns the following response:
{USER_KEY};{SESSION_KEY}
Where {USER_KEY} is the user key and {SESSION_KEY} is the session key
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/login?username={username}&password={password}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("GET");

if (conn.getResponseCode() != 200) {
	throw new RuntimeException("Failed : HTTP error code : "
		+ conn.getResponseCode());
}
BufferedReader br =
	new BufferedReader(new InputStreamReader(conn.getInputStream()));

String response = "";
String output;
while ((output = br.readLine()) != null) {
	response += output;
}
String[] parts = response.split(";");
String user_key = parts[0];
String session_key = parts[1];
System.out.println("user_key: " + user_key);
System.out.println("Session_key: " + session_key);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
On success, the above command returns the following response:
{USER_KEY};{SESSION_KEY}
Where {USER_KEY} is the user key and {SESSION_KEY} is the session key
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/login?username={username}&password={password}');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

if ($info['http_code'] != 200) {
echo('Error!');
}
else {
$values = explode(";", $response);
echo('user_key: ' . $values[0]);
echo('Session_key: ' . $values[1]);
}
?>
On success, the above command returns the following response:
{USER_KEY};{SESSION_KEY}
Where {USER_KEY} is the user key and {SESSION_KEY} is the session key
Copy code
# pip install requests
import requests
import json

r = requests.get("https://app.gateway.smsend.it/API/v1.0/REST/login?username={username}&password={password}")

if r.status_code != 200:
print("An error occurred, return code is: " + str(r.status_code))
else:
response = r.text
user_key, session_key = response.split(';')
print("user_key: " + user_key)
print("Session_key: " + session_key)
On success, the above command returns the following response:
{USER_KEY};{SESSION_KEY}
Where {USER_KEY} is the user key and {SESSION_KEY} is the session key
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/login?username={username}&password={password}',
method: 'GET',
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
var arr = response.split(';');
console.log("user_key: " + arr[0]);
console.log("Session_key: " + arr[1]);
}
else {
console.log('An error occurred..');
}
}
});
On success, the above command returns the following response:
{USER_KEY};{SESSION_KEY}
Where {USER_KEY} is the user key and {SESSION_KEY} is the session key
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/login?username={username}&password={password}")

# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'


# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
user_key, session_key = response.split(';')
puts "user_key: " + user_key
puts "Session_key: " + session_key
else
puts "Error.."
end
On success, the above command returns the following response:
{USER_KEY};{SESSION_KEY}
Where {USER_KEY} is the user key and {SESSION_KEY} is the session key
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())
{
	String response = wb.DownloadString("https://app.gateway.smsend.it/API/v1.0/REST/login?username={username}&password={password}");
	String[] auth = response.Split(';');
	Console.WriteLine("user_key: " + auth[0]);
	Console.WriteLine("Session_key: " + auth[1]);
}

}
}
}
On success, the above command returns the following response:
{USER_KEY};{SESSION_KEY}
Where {USER_KEY} is the user key and {SESSION_KEY} is the session key
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/login?username={username}&password={password}";

my $req = HTTP::Request->new(GET => $server_endpoint);

$req->header('Content_type' => 'application/json');

my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
$response = $resp->decoded_content;
my ($user_key, $session_key) = $response =~ /(.*);(.*)/;
print "user_key: $user_key\n";
print "Session_key: $session_key\n";
}
On success, the above command returns the following response:
{USER_KEY};{SESSION_KEY}
Where {USER_KEY} is the user key and {SESSION_KEY} is the session key

Authenticate using a user token

The login with token API lets you authenticate by using your username and password, and returns a token to be used for authenticating the next API calls.

The following HTTP headers should be provided after the login:

user_key:{USER_KEY}

Access_token:{ACCESS_TOKEN}

Where {USER_KEY} and {ACCESS_TOKEN} are the values returned by the login API.

{USER_KEY} and {ACCESS_TOKEN} placeholders can be found in all code examples. When actually running the example, the correct values must be used instead.

HTTP Method

GET

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/token?username={USERNAME}&password={PASSWORD}

Parameters

Parameter Type Description Required Default
username String Your account’s username Yes -
password String Your account’s password Yes -

Returns

Code Description
200 The user_key and the access token
404 [Not found]Credentials are incorrect
400 Other errors, details are in the body
Copy code
# Session Key example

curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/login?username={username}&password={password}' -H 'Content-Type: application/json'  

# Access token example

curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/login?username={username}&password={password}' -H 'Content-Type: application/json'
On success, the above command returns the following response:
{USER_KEY};{ACCESS_TOKEN}
Where {USER_KEY} is the user key and {ACCESS_TOKEN} is the access token
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/token?username={username}&password={password}");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestMethod("GET");

if (conn.getResponseCode() != 200) {
	throw new RuntimeException("Failed : HTTP error code : "
							   + conn.getResponseCode());
}
BufferedReader br =
	new BufferedReader(new InputStreamReader(conn.getInputStream()));

String response = "";
String output;
while ((output = br.readLine()) != null) {
	response += output;
}
String[] parts = response.split(";");
String user_key = parts[0];
String access_token = parts[1];
System.out.println("user_key: " + user_key);
System.out.println("Access_token: " + access_token);
conn.disconnect();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
On success, the above command returns the following response:
{USER_KEY};{ACCESS_TOKEN}
Where {USER_KEY} is the user key and {ACCESS_TOKEN} is the access token
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/token?username={username}&password={password}');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

if ($info['http_code'] != 200) {
echo('Error!');
}
else {
$values = explode(";", $response);
echo('user_key: ' . $values[0]);
echo('Access_token: ' . $values[1]);
}
?>
On success, the above command returns the following response:
{USER_KEY};{ACCESS_TOKEN}
Where {USER_KEY} is the user key and {ACCESS_TOKEN} is the access token
Copy code
# pip install requests
import requests
import json

r = requests.get("https://app.gateway.smsend.it/API/v1.0/REST/token?username={username}&password={password}")

if r.status_code != 200:
print("An error occurred, return code is: " + str(r.status_code))
else:
response = r.text
user_key, access_token = response.split(';')
print("user_key: " + user_key)
print("Access_token: " + access_token)
On success, the above command returns the following response:
{USER_KEY};{ACCESS_TOKEN}
Where {USER_KEY} is the user key and {ACCESS_TOKEN} is the access token
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/token?username={username}&password={password}',
method: 'GET',
callback: function (error, responseMeta, response) {
if (!error && responseMeta.statusCode == 200) {
var arr = response.split(';');
console.log("user_key: " + arr[0]);
console.log("Access_token: " + arr[1]);
}
else {
console.log('An error occurred..');
}
}
});
On success, the above command returns the following response:
{USER_KEY};{ACCESS_TOKEN}
Where {USER_KEY} is the user key and {ACCESS_TOKEN} is the access token
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/token?username={username}&password={password}")

# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'

# Send the request
responseData = http.request(request)
if responseData.code == "200"
response = responseData.body
user_key, access_token = response.split(';')
puts "user_key: " + user_key
puts "Access_token: " + access_token
else
puts "Error.."
end
On success, the above command returns the following response:
{USER_KEY};{ACCESS_TOKEN}
Where {USER_KEY} is the user key and {ACCESS_TOKEN} is the access token
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())
{
	String response = wb.DownloadString("https://app.gateway.smsend.it/API/v1.0/REST/token?username={username}&password={password}");
	String[] auth = response.Split(';');
	Console.WriteLine("user_key: " + auth[0]);
	Console.WriteLine("Access_token: " + auth[1]);
}

}
}
}
On success, the above command returns the following response:
{USER_KEY};{ACCESS_TOKEN}
Where {USER_KEY} is the user key and {ACCESS_TOKEN} is the access token
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/token?username={username}&password={password}";

my $req = HTTP::Request->new(GET => $server_endpoint);

$req->header('Content_type' => 'application/json');

my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
$response = $resp->decoded_content;
my ($user_key, $access_token) = $response =~ /(.*);(.*)/;
print "user_key: $user_key\n";
print "Access_token: $access_token\n";
}
On success, the above command returns the following response:
{USER_KEY};{ACCESS_TOKEN}
Where {USER_KEY} is the user key and {ACCESS_TOKEN} is the access token