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