Subaccount API

If enabled as a superaccount or reseller, the user can create subaccounts that can be assigned to third-parties.

Superaccounts may or may not share credits with their subaccounts.

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.

Get the list of subaccounts

Returns the list of subaccounts of the authenticated user.

HTTP Headers

user_key / Session_key

HTTP Method

GET

HTTP Request

https://app.gateway.smsend.it/subaccounts?pageNumber={page}&pageSize={size}

Parameters

Parameter Type Description Required Default
pageNumber Int Return the given results page No 1
pageSize Int The number of results in a page No 10

Returns

Code Description
200 The paginated list of subaccounts of the authenticated user
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found

The “credits” and “credits-sum” fields will be populated only in the case in which the subaccount has “credit-eat-mode” = 2

Copy code
s
# Session Key example
curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/subaccounts' -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/subaccounts' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}'
On success, the above command returns the following response:
{
  "result": "OK",
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2,
  "subaccount": [
    {
      "activation-time": "20160823",
      "active": true,
      "address": "via viotta",
      "allowtpoavalidation": true,
      "cell": "+393385958233",
      "city": "Città",
      "fiscal-code": "PRRFCC92L09L488E",
      "pa-code": null,
      "company": false,
      "company-name": null,
      "create-time": "20160823",
      "credit-eat-mode": 2,
      "credits-sum": "€ 0,000",
      "default-message-type": \"L\",
      "default-nation": "ita",
      "dfeu": true,
      "email": "prova@prova.pr",
      "fax": "0461757575",
      "foreign": false,
      "id-user": 5,
      "invoicing-email": null,
      "language": "ita",
      "legal-agreement-time": "20160823",
      "legalAgreementVersion": 0,
      "login": "logon",
      "max-subaccounts": -1,
      "name": "nome",
      "num-cell-for-test-sms": "+393385958233",
      "partner": false,
      "partner-code": null,
      "phone": "0461757575",
      "piva": null,
      "preferred-tpoa": "+393385958233",
      "private": true,
      "province": "Trento",
      "referral": false,
      "shop_cart_check": true,
      "split-payment": false,
      "subaccount": true,
      "subaccount-types": 0,
      "super-account-name": "",
      "superaccount": false,
      "surname": "asdasd",
      "use24": true,
      "user-nation": "ita",
      "zip-code": "38010",
      "credits": [
        {
          "id": "N",
          "qty": 10
        },
        {
          "id": "L",
          "qty": 10
        },
        {
          "id": "LL",
          "qty": 10
        },
        {
          "id": "EE",
          "qty": 10
        }
      ]
    }
  ]
}
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/subaccounts");
            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 EEON 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:
{
  "result": "OK",
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2,
  "subaccount": [
    {
      "activation-time": "20160823",
      "active": true,
      "address": "via viotta",
      "allowtpoavalidation": true,
      "cell": "+393385958233",
      "city": "Città",
      "fiscal-code": "PRRFCC92L09L488E",
      "pa-code": null,
      "company": false,
      "company-name": null,
      "create-time": "20160823",
      "credit-eat-mode": 2,
      "credits-sum": "€ 0,000",
      "default-message-type": \"L\",
      "default-nation": "ita",
      "dfeu": true,
      "email": "prova@prova.pr",
      "fax": "0461757575",
      "foreign": false,
      "id-user": 5,
      "invoicing-email": null,
      "language": "ita",
      "legal-agreement-time": "20160823",
      "legalAgreementVersion": 0,
      "login": "logon",
      "max-subaccounts": -1,
      "name": "nome",
      "num-cell-for-test-sms": "+393385958233",
      "partner": false,
      "partner-code": null,
      "phone": "0461757575",
      "piva": null,
      "preferred-tpoa": "+393385958233",
      "private": true,
      "province": "Trento",
      "referral": false,
      "shop_cart_check": true,
      "split-payment": false,
      "subaccount": true,
      "subaccount-types": 0,
      "super-account-name": "",
      "superaccount": false,
      "surname": "asdasd",
      "use24": true,
      "user-nation": "ita",
      "zip-code": "38010",
      "credits": [
        {
          "id": "N",
          "qty": 10
        },
        {
          "id": "L",
          "qty": 10
        },
        {
          "id": "LL",
          "qty": 10
        },
        {
          "id": "EE",
          "qty": 10
        }
      ]
    }
  ]
}
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccounts');
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:
{
  "result": "OK",
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2,
  "subaccount": [
    {
      "activation-time": "20160823",
      "active": true,
      "address": "via viotta",
      "allowtpoavalidation": true,
      "cell": "+393385958233",
      "city": "Città",
      "fiscal-code": "PRRFCC92L09L488E",
      "pa-code": null,
      "company": false,
      "company-name": null,
      "create-time": "20160823",
      "credit-eat-mode": 2,
      "credits-sum": "€ 0,000",
      "default-message-type": \"L\",
      "default-nation": "ita",
      "dfeu": true,
      "email": "prova@prova.pr",
      "fax": "0461757575",
      "foreign": false,
      "id-user": 5,
      "invoicing-email": null,
      "language": "ita",
      "legal-agreement-time": "20160823",
      "legalAgreementVersion": 0,
      "login": "logon",
      "max-subaccounts": -1,
      "name": "nome",
      "num-cell-for-test-sms": "+393385958233",
      "partner": false,
      "partner-code": null,
      "phone": "0461757575",
      "piva": null,
      "preferred-tpoa": "+393385958233",
      "private": true,
      "province": "Trento",
      "referral": false,
      "shop_cart_check": true,
      "split-payment": false,
      "subaccount": true,
      "subaccount-types": 0,
      "super-account-name": "",
      "superaccount": false,
      "surname": "asdasd",
      "use24": true,
      "user-nation": "ita",
      "zip-code": "38010",
      "credits": [
        {
          "id": "N",
          "qty": 10
        },
        {
          "id": "L",
          "qty": 10
        },
        {
          "id": "LL",
          "qty": 10
        },
        {
          "id": "EE",
          "qty": 10
        }
      ]
    }
  ]
}
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/subaccounts", 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:
{
  "result": "OK",
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2,
  "subaccount": [
    {
      "activation-time": "20160823",
      "active": true,
      "address": "via viotta",
      "allowtpoavalidation": true,
      "cell": "+393385958233",
      "city": "Città",
      "fiscal-code": "PRRFCC92L09L488E",
      "pa-code": null,
      "company": false,
      "company-name": null,
      "create-time": "20160823",
      "credit-eat-mode": 2,
      "credits-sum": "€ 0,000",
      "default-message-type": \"L\",
      "default-nation": "ita",
      "dfeu": true,
      "email": "prova@prova.pr",
      "fax": "0461757575",
      "foreign": false,
      "id-user": 5,
      "invoicing-email": null,
      "language": "ita",
      "legal-agreement-time": "20160823",
      "legalAgreementVersion": 0,
      "login": "logon",
      "max-subaccounts": -1,
      "name": "nome",
      "num-cell-for-test-sms": "+393385958233",
      "partner": false,
      "partner-code": null,
      "phone": "0461757575",
      "piva": null,
      "preferred-tpoa": "+393385958233",
      "private": true,
      "province": "Trento",
      "referral": false,
      "shop_cart_check": true,
      "split-payment": false,
      "subaccount": true,
      "subaccount-types": 0,
      "super-account-name": "",
      "superaccount": false,
      "surname": "asdasd",
      "use24": true,
      "user-nation": "ita",
      "zip-code": "38010",
      "credits": [
        {
          "id": "N",
          "qty": 10
        },
        {
          "id": "L",
          "qty": 10
        },
        {
          "id": "LL",
          "qty": 10
        },
        {
          "id": "EE",
          "qty": 10
        }
      ]
    }
  ]
}
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/subaccounts',
    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:
{
  "result": "OK",
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2,
  "subaccount": [
    {
      "activation-time": "20160823",
      "active": true,
      "address": "via viotta",
      "allowtpoavalidation": true,
      "cell": "+393385958233",
      "city": "Città",
      "fiscal-code": "PRRFCC92L09L488E",
      "pa-code": null,
      "company": false,
      "company-name": null,
      "create-time": "20160823",
      "credit-eat-mode": 2,
      "credits-sum": "€ 0,000",
      "default-message-type": \"L\",
      "default-nation": "ita",
      "dfeu": true,
      "email": "prova@prova.pr",
      "fax": "0461757575",
      "foreign": false,
      "id-user": 5,
      "invoicing-email": null,
      "language": "ita",
      "legal-agreement-time": "20160823",
      "legalAgreementVersion": 0,
      "login": "logon",
      "max-subaccounts": -1,
      "name": "nome",
      "num-cell-for-test-sms": "+393385958233",
      "partner": false,
      "partner-code": null,
      "phone": "0461757575",
      "piva": null,
      "preferred-tpoa": "+393385958233",
      "private": true,
      "province": "Trento",
      "referral": false,
      "shop_cart_check": true,
      "split-payment": false,
      "subaccount": true,
      "subaccount-types": 0,
      "super-account-name": "",
      "superaccount": false,
      "surname": "asdasd",
      "use24": true,
      "user-nation": "ita",
      "zip-code": "38010",
      "credits": [
        {
          "id": "N",
          "qty": 10
        },
        {
          "id": "L",
          "qty": 10
        },
        {
          "id": "LL",
          "qty": 10
        },
        {
          "id": "EE",
          "qty": 10
        }
      ]
    }
  ]
}
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/subaccounts")

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

request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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:
{
  "result": "OK",
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2,
  "subaccount": [
    {
      "activation-time": "20160823",
      "active": true,
      "address": "via viotta",
      "allowtpoavalidation": true,
      "cell": "+393385958233",
      "city": "Città",
      "fiscal-code": "PRRFCC92L09L488E",
      "pa-code": null,
      "company": false,
      "company-name": null,
      "create-time": "20160823",
      "credit-eat-mode": 2,
      "credits-sum": "€ 0,000",
      "default-message-type": \"L\",
      "default-nation": "ita",
      "dfeu": true,
      "email": "prova@prova.pr",
      "fax": "0461757575",
      "foreign": false,
      "id-user": 5,
      "invoicing-email": null,
      "language": "ita",
      "legal-agreement-time": "20160823",
      "legalAgreementVersion": 0,
      "login": "logon",
      "max-subaccounts": -1,
      "name": "nome",
      "num-cell-for-test-sms": "+393385958233",
      "partner": false,
      "partner-code": null,
      "phone": "0461757575",
      "piva": null,
      "preferred-tpoa": "+393385958233",
      "private": true,
      "province": "Trento",
      "referral": false,
      "shop_cart_check": true,
      "split-payment": false,
      "subaccount": true,
      "subaccount-types": 0,
      "super-account-name": "",
      "superaccount": false,
      "surname": "asdasd",
      "use24": true,
      "user-nation": "ita",
      "zip-code": "38010",
      "credits": [
        {
          "id": "N",
          "qty": 10
        },
        {
          "id": "L",
          "qty": 10
        },
        {
          "id": "LL",
          "qty": 10
        },
        {
          "id": "EE",
          "qty": 10
        }
      ]
    }
  ]
}
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/subaccounts");

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

        }
    }
}
						    
On success, the above command returns the following response:
{
  "result": "OK",
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2,
  "subaccount": [
    {
      "activation-time": "20160823",
      "active": true,
      "address": "via viotta",
      "allowtpoavalidation": true,
      "cell": "+393385958233",
      "city": "Città",
      "fiscal-code": "PRRFCC92L09L488E",
      "pa-code": null,
      "company": false,
      "company-name": null,
      "create-time": "20160823",
      "credit-eat-mode": 2,
      "credits-sum": "€ 0,000",
      "default-message-type": \"L\",
      "default-nation": "ita",
      "dfeu": true,
      "email": "prova@prova.pr",
      "fax": "0461757575",
      "foreign": false,
      "id-user": 5,
      "invoicing-email": null,
      "language": "ita",
      "legal-agreement-time": "20160823",
      "legalAgreementVersion": 0,
      "login": "logon",
      "max-subaccounts": -1,
      "name": "nome",
      "num-cell-for-test-sms": "+393385958233",
      "partner": false,
      "partner-code": null,
      "phone": "0461757575",
      "piva": null,
      "preferred-tpoa": "+393385958233",
      "private": true,
      "province": "Trento",
      "referral": false,
      "shop_cart_check": true,
      "split-payment": false,
      "subaccount": true,
      "subaccount-types": 0,
      "super-account-name": "",
      "superaccount": false,
      "surname": "asdasd",
      "use24": true,
      "user-nation": "ita",
      "zip-code": "38010",
      "credits": [
        {
          "id": "N",
          "qty": 10
        },
        {
          "id": "L",
          "qty": 10
        },
        {
          "id": "LL",
          "qty": 10
        },
        {
          "id": "EE",
          "qty": 10
        }
      ]
    }
  ]
}
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/subaccounts";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
  $response = $resp->decoded_content;
  my $obj = from_json($response);

}
						    
On success, the above command returns the following response:
{
  "result": "OK",
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2,
  "subaccount": [
    {
      "activation-time": "20160823",
      "active": true,
      "address": "via viotta",
      "allowtpoavalidation": true,
      "cell": "+393385958233",
      "city": "Città",
      "fiscal-code": "PRRFCC92L09L488E",
      "pa-code": null,
      "company": false,
      "company-name": null,
      "create-time": "20160823",
      "credit-eat-mode": 2,
      "credits-sum": "€ 0,000",
      "default-message-type": \"L\",
      "default-nation": "ita",
      "dfeu": true,
      "email": "prova@prova.pr",
      "fax": "0461757575",
      "foreign": false,
      "id-user": 5,
      "invoicing-email": null,
      "language": "ita",
      "legal-agreement-time": "20160823",
      "legalAgreementVersion": 0,
      "login": "logon",
      "max-subaccounts": -1,
      "name": "nome",
      "num-cell-for-test-sms": "+393385958233",
      "partner": false,
      "partner-code": null,
      "phone": "0461757575",
      "piva": null,
      "preferred-tpoa": "+393385958233",
      "private": true,
      "province": "Trento",
      "referral": false,
      "shop_cart_check": true,
      "split-payment": false,
      "subaccount": true,
      "subaccount-types": 0,
      "super-account-name": "",
      "superaccount": false,
      "surname": "asdasd",
      "use24": true,
      "user-nation": "ita",
      "zip-code": "38010",
      "credits": [
        {
          "id": "N",
          "qty": 10
        },
        {
          "id": "L",
          "qty": 10
        },
        {
          "id": "LL",
          "qty": 10
        },
        {
          "id": "EE",
          "qty": 10
        }
      ]
    }
  ]
}

Create a subaccount

Creates a new subaccount for the authenticated user, which has to be a superaccount.

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

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

Body Fields

Parameter Type Description Required Default
address String The subaccount address Yes -
cell String The subaccount mobile phone number Yes -
city String The subaccount city Yes -
company Bool Is the subaccount a company? No true
company-name String The company name Yes (if company=true) -
credit-eat-mode Int (0, 1, 2) Tells from who credits are scaled. 0 = own credits, 1 = superaccount credits, 2 = own credits and superaccount ones Yes -
dfeu Bool Use the Date Format in EUropean format No true
email String (a valid Email) The subaccount email Yes -
fax String The subaccount FAX number No “”
invoicing-email String (a valid Email) If provided, invoices will be sent here instead of the default email No “”
language String The subaccount language. If none, defaults to the one of the superaccount No to the one of the superaccount
login String The subaccount login username (must not contain any spaces) Yes -
name String The subaccount owner first name Yes -
num-cell-for-test-sms String (Phone number) A phone number where test SMS messages will be sent No “”
password String The subaccount password (min 8 chars, max 16 chars) No If null, will be autogenerated
phone String (PhoneNumber) The subaccount phone number No “”
piva String The subaccount VAT number (P.Iva in Italy) Yes (if company=true)
province String The subaccount province Yes -
superaccount Bool The subaccount is a superaccount itself (i.e. it can create his own subaccounts) No false
surname String The subaccount last name Yes -
use24 Bool Use the 24 hour format for time No true
zip-code String The subaccount ZIP Code Yes -
id-subaccount-profile Int Specifying a custom subaccount profile allows a superaccount to narrow down the subaccount enabled features (e.g. Only send SMS messages, or even further, only send a specific type of SMS message) No The default profile

Returns

Code Description
200 Success, returns an empty response with the HTTP Location header pointing to the created subaccount
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found
Copy code
# Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount' -H 'Content-Type: application/json' \
-H 'user_key: {USER_KEY}' -H 'Session_key: {SESSION_KEY}' -d'
{
    "address": "via xxx", 
    "cell": "+393393939393", 
    "city": "myCity", 
    "fiscal-code": "BRGRJM87J89JH907E", 
    "company": true, 
    "company-name": "myCompany", 
    "credit-eat-mode": 1, 
    "dfeu": true, 
    "email": "em@a.il", 
    "fax": "0461686868", 
    "invoicing-email": "em@a.il", 
    "language": "ita", 
    "login": "myLogin", 
    "name": "myNome", 
    "num-cell-for-test-sms": "+393393939393", 
    "password": "myPassword", 
    "phone": "0461656565", 
    "piva": "104456015145", 
    "province": "TN", 
    "superaccount": false, 
    "surname": "mySurname", 
    "use24": true, 
    "zip-code": "38010", 
    "id-subaccount-profile": 1
}
'

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}' -d'
{
    "address": "via xxx", 
    "cell": "+393393939393", 
    "city": "myCity", 
    "fiscal-code": "BRGRJM87J89JH907E", 
    "company": true, 
    "company-name": "myCompany", 
    "credit-eat-mode": 1, 
    "dfeu": true, 
    "email": "em@a.il", 
    "fax": "0461686868", 
    "invoicing-email": "em@a.il", 
    "language": "ita", 
    "login": "myLogin", 
    "name": "myNome", 
    "num-cell-for-test-sms": "+393393939393", 
    "password": "myPassword", 
    "phone": "0461656565", 
    "piva": "104456015145", 
    "province": "TN", 
    "superaccount": false, 
    "surname": "mySurname", 
    "use24": true, 
    "zip-code": "38010", 
    "id-subaccount-profile": 1
}
'
On success, the above command returns the following response:
# The HTTP location header that points to the created subaccount:
'Location': '/subaccount/18107'
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/subaccount");
            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 = "{" + 
              "    \"address\": \"via xxx\", " + 
              "    \"cell\": \"+393393939393\", " + 
              "    \"city\": \"myCity\", " + 
              "    \"fiscal-code\": \"BRGRJM87J89JH907E\", " + 
              "    \"company\": true, " + 
              "    \"company-name\": \"myCompany\", " + 
              "    \"credit-eat-mode\": 1, " + 
              "    \"dfeu\": true, " + 
              "    \"email\": \"em@a.il\", " + 
              "    \"fax\": \"0461686868\", " + 
              "    \"invoicing-email\": \"em@a.il\", " + 
              "    \"language\": \"ita\", " + 
              "    \"login\": \"myLogin\", " + 
              "    \"name\": \"myNome\", " + 
              "    \"num-cell-for-test-sms\": \"+393393939393\", " + 
              "    \"password\": \"myPassword\", " + 
              "    \"phone\": \"0461656565\", " + 
              "    \"piva\": \"104456015145\", " + 
              "    \"province\": \"TN\", " + 
              "    \"superaccount\": false, " + 
              "    \"surname\": \"mySurname\", " + 
              "    \"use24\": true, " + 
              "    \"zip-code\": \"38010\", " + 
              "    \"id-subaccount-profile\": 1" + 
              "}";

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

            if (conn.getResponseCode() != 200) {
                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 subaccount:
'Location': '/subaccount/18107'
Copy code
<?php

$payload = '{' . 
  '    "address": "via xxx", ' . 
  '    "cell": "+393393939393", ' . 
  '    "city": "myCity", ' . 
  '    "fiscal-code": "BRGRJM87J89JH907E", ' . 
  '    "company": true, ' . 
  '    "company-name": "myCompany", ' . 
  '    "credit-eat-mode": 1, ' . 
  '    "dfeu": true, ' . 
  '    "email": "em@a.il", ' . 
  '    "fax": "0461686868", ' . 
  '    "invoicing-email": "em@a.il", ' . 
  '    "language": "ita", ' . 
  '    "login": "myLogin", ' . 
  '    "name": "myNome", ' . 
  '    "num-cell-for-test-sms": "+393393939393", ' . 
  '    "password": "myPassword", ' . 
  '    "phone": "0461656565", ' . 
  '    "piva": "104456015145", ' . 
  '    "province": "TN", ' . 
  '    "superaccount": false, ' . 
  '    "surname": "mySurname", ' . 
  '    "use24": true, ' . 
  '    "zip-code": "38010", ' . 
  '    "id-subaccount-profile": 1' . 
  '}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount');
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'] != 200) {
    echo('Error!');
}
else {
    echo('Success!');
}?>
On success, the above command returns the following response:
# The HTTP location header that points to the created subaccount:
'Location': '/subaccount/18107'
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 = """{
    "address": "via xxx", 
    "cell": "+393393939393", 
    "city": "myCity", 
    "fiscal-code": "BRGRJM87J89JH907E", 
    "company": true, 
    "company-name": "myCompany", 
    "credit-eat-mode": 1, 
    "dfeu": true, 
    "email": "em@a.il", 
    "fax": "0461686868", 
    "invoicing-email": "em@a.il", 
    "language": "ita", 
    "login": "myLogin", 
    "name": "myNome", 
    "num-cell-for-test-sms": "+393393939393", 
    "password": "myPassword", 
    "phone": "0461656565", 
    "piva": "104456015145", 
    "province": "TN", 
    "superaccount": false, 
    "surname": "mySurname", 
    "use24": true, 
    "zip-code": "38010", 
    "id-subaccount-profile": 1
}"""

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

if r.status_code != 200:
    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 subaccount:
'Location': '/subaccount/18107'
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/subaccount',
    method: 'POST',
    headers: { 'user_key' : '{USER_KEY}', 'Session_key' : '{SESSION_KEY}' },

    json: true,
    body:     {
        "address": "via xxx", 
        "cell": "+393393939393", 
        "city": "myCity", 
        "fiscal-code": "BRGRJM87J89JH907E", 
        "company": true, 
        "company-name": "myCompany", 
        "credit-eat-mode": 1, 
        "dfeu": true, 
        "email": "em@a.il", 
        "fax": "0461686868", 
        "invoicing-email": "em@a.il", 
        "language": "ita", 
        "login": "myLogin", 
        "name": "myNome", 
        "num-cell-for-test-sms": "+393393939393", 
        "password": "myPassword", 
        "phone": "0461656565", 
        "piva": "104456015145", 
        "province": "TN", 
        "superaccount": false, 
        "surname": "mySurname", 
        "use24": true, 
        "zip-code": "38010", 
        "id-subaccount-profile": 1
    },

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

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/subaccount")
payload =     {
        "address": "via xxx", 
        "cell": "+393393939393", 
        "city": "myCity", 
        "fiscal-code": "BRGRJM87J89JH907E", 
        "company": true, 
        "company-name": "myCompany", 
        "credit-eat-mode": 1, 
        "dfeu": true, 
        "email": "em@a.il", 
        "fax": "0461686868", 
        "invoicing-email": "em@a.il", 
        "language": "ita", 
        "login": "myLogin", 
        "name": "myNome", 
        "num-cell-for-test-sms": "+393393939393", 
        "password": "myPassword", 
        "phone": "0461656565", 
        "piva": "104456015145", 
        "province": "TN", 
        "superaccount": false, 
        "surname": "mySurname", 
        "use24": true, 
        "zip-code": "38010", 
        "id-subaccount-profile": 1
    }

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

request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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.."
end
On success, the above command returns the following response:
# The HTTP location header that points to the created subaccount:
'Location': '/subaccount/18107'
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 = "{" + 
                  "    \"address\": \"via xxx\", " + 
                  "    \"cell\": \"+393393939393\", " + 
                  "    \"city\": \"myCity\", " + 
                  "    \"fiscal-code\": \"BRGRJM87J89JH907E\", " + 
                  "    \"company\": true, " + 
                  "    \"company-name\": \"myCompany\", " + 
                  "    \"credit-eat-mode\": 1, " + 
                  "    \"dfeu\": true, " + 
                  "    \"email\": \"em@a.il\", " + 
                  "    \"fax\": \"0461686868\", " + 
                  "    \"invoicing-email\": \"em@a.il\", " + 
                  "    \"language\": \"ita\", " + 
                  "    \"login\": \"myLogin\", " + 
                  "    \"name\": \"myNome\", " + 
                  "    \"num-cell-for-test-sms\": \"+393393939393\", " + 
                  "    \"password\": \"myPassword\", " + 
                  "    \"phone\": \"0461656565\", " + 
                  "    \"piva\": \"104456015145\", " + 
                  "    \"province\": \"TN\", " + 
                  "    \"superaccount\": false, " + 
                  "    \"surname\": \"mySurname\", " + 
                  "    \"use24\": true, " + 
                  "    \"zip-code\": \"38010\", " + 
                  "    \"id-subaccount-profile\": 1" + 
                  "}";

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

        }
    }
}
On success, the above command returns the following response:
# The HTTP location header that points to the created subaccount:
'Location': '/subaccount/18107'
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/subaccount";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $payload = {
    "address" => "via xxx", 
    "cell" => "+393393939393", 
    "city" => "myCity", 
    "fiscal-code" => "BRGRJM87J89JH907E", 
    "company" => true, 
    "company-name" => "myCompany", 
    "credit-eat-mode" => 1, 
    "dfeu" => true, 
    "email" => "em@a.il", 
    "fax" => "0461686868", 
    "invoicing-email" => "em@a.il", 
    "language" => "ita", 
    "login" => "myLogin", 
    "name" => "myNome", 
    "num-cell-for-test-sms" => "+393393939393", 
    "password" => "myPassword", 
    "phone" => "0461656565", 
    "piva" => "104456015145", 
    "province" => "TN", 
    "superaccount" => false, 
    "surname" => "mySurname", 
    "use24" => true, 
    "zip-code" => "38010", 
    "id-subaccount-profile" => 1
};

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

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

Edit subaccount

Edits the subaccount identified by the given subaccount_id. Calling user must be a superaccount.

HTTP Headers

user_key / Session_key

HTTP Method

PUT

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}?lock-subaccount={value}

Parameters

Parameter Type Description Required Default
subaccount_id Int The subaccount ID Yes -
lock-subaccount Bool Activate or deactivate the subaccount No false

Body Fields

Parameter Type Description Required Default
address String The subaccount address Yes -
cell String The subaccount mobile phone number Yes -
city String The subaccount city Yes -
company Bool Is the subaccount a company? No true
company-name String The company name Yes (if company=true) -
credit-eat-mode Int (0, 1, 2) Tells from who credits are scaled. 0 = own credits, 1 = superaccount credits, 2 = own credits and superaccount ones Yes -
dfeu Bool Use the Date Format in EUropean format No true
email String (a valid Email) The subaccount email Yes -
fax String The subaccount FAX number No “”
invoicing-email String (a valid Email) If provided, invoices will be sent here instead of the default email No “”
language String The subaccount language. If none, defaults to the one of the superaccount No to the one of the superaccount
login String The subaccount login username (Must not contain any spaces) Yes -
name String The subaccount owner first name Yes -
num-cell-for-test-sms String (Phone number) A phone number where test SMS messages will be sent No “”
password String The subaccount password (min 8 chars, max 16 chars) No If null, will be autogenerated
phone String (PhoneNumber) The subaccount phone number No “”
piva String The subaccount VAT number (P.Iva in Italy) Yes (if company=true)
province String The subaccount province Yes -
superaccount Bool The subaccount is a superaccount itself (i.e. it can create his own subaccounts) No false
surname String The subaccount last name Yes -
use24 Bool Use the 24 hour format for time No true
zip-code String The subaccount ZIP Code Yes -
id-subaccount-profile Int Specifying a custom subaccount profile allows a superaccount to narrow down the subaccount enabled features (e.g. Only send SMS messages, or even further, only send a specific type of SMS message) No The default profile

Returns

Code Description
200 Success, returns an empty response with the HTTP Location header pointing to the created subaccount
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found
Copy code
# Session Key example
curl -XPUT 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}' -H 'Content-Type: application/json' \
-H 'user_key: {USER_KEY}' -H 'Session_key: {SESSION_KEY}' -d'
{
    "address": "via xxx", 
    "cell": "+393393939393", 
    "city": "myCity", 
    "fiscal-code": "BRGRJM87J89JH907E", 
    "company": true, 
    "company-name": "myCompany", 
    "credit-eat-mode": 1, 
    "dfeu": true, 
    "email": "em@a.il", 
    "fax": "0461686868", 
    "invoicing-email": "em@a.il", 
    "language": "ita", 
    "login": "myLogin", 
    "name": "myNome", 
    "num-cell-for-test-sms": "+393393939393", 
    "password": "myPassword", 
    "phone": "0461656565", 
    "piva": "104456015145", 
    "province": "TN", 
    "superaccount": false, 
    "surname": "mySurname", 
    "use24": true, 
    "zip-code": "38010", 
    "id-subaccount-profile": 1
}
'

# Access token example
curl -XPUT 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}' -d'
{
    "address": "via xxx", 
    "cell": "+393393939393", 
    "city": "myCity", 
    "fiscal-code": "BRGRJM87J89JH907E", 
    "company": true, 
    "company-name": "myCompany", 
    "credit-eat-mode": 1, 
    "dfeu": true, 
    "email": "em@a.il", 
    "fax": "0461686868", 
    "invoicing-email": "em@a.il", 
    "language": "ita", 
    "login": "myLogin", 
    "name": "myNome", 
    "num-cell-for-test-sms": "+393393939393", 
    "password": "myPassword", 
    "phone": "0461656565", 
    "piva": "104456015145", 
    "province": "TN", 
    "superaccount": false, 
    "surname": "mySurname", 
    "use24": true, 
    "zip-code": "38010", 
    "id-subaccount-profile": 1
}
'
On success, the above command returns the following response:
# The HTTP location header that points to the edited subaccount:
'Location': '/subaccount/18107'
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/subaccount/{subaccount_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", "{ACCESS_TOKEN}");

            conn.setRequestMethod("PUT");

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

            String payload = "{" + 
              "    \"address\": \"via xxx\", " + 
              "    \"cell\": \"+393393939393\", " + 
              "    \"city\": \"myCity\", " + 
              "    \"fiscal-code\": \"BRGRJM87J89JH907E\", " + 
              "    \"company\": true, " + 
              "    \"company-name\": \"myCompany\", " + 
              "    \"credit-eat-mode\": 1, " + 
              "    \"dfeu\": true, " + 
              "    \"email\": \"em@a.il\", " + 
              "    \"fax\": \"0461686868\", " + 
              "    \"invoicing-email\": \"em@a.il\", " + 
              "    \"language\": \"ita\", " + 
              "    \"login\": \"myLogin\", " + 
              "    \"name\": \"myNome\", " + 
              "    \"num-cell-for-test-sms\": \"+393393939393\", " + 
              "    \"password\": \"myPassword\", " + 
              "    \"phone\": \"0461656565\", " + 
              "    \"piva\": \"104456015145\", " + 
              "    \"province\": \"TN\", " + 
              "    \"superaccount\": false, " + 
              "    \"surname\": \"mySurname\", " + 
              "    \"use24\": true, " + 
              "    \"zip-code\": \"38010\", " + 
              "    \"id-subaccount-profile\": 1" + 
              "}";

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

            if (conn.getResponseCode() != 200) {
                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 edited subaccount:
'Location': '/subaccount/18107'
Copy code
<?php

$payload = '{' . 
  '    "address": "via xxx", ' . 
  '    "cell": "+393393939393", ' . 
  '    "city": "myCity", ' . 
  '    "fiscal-code": "BRGRJM87J89JH907E", ' . 
  '    "company": true, ' . 
  '    "company-name": "myCompany", ' . 
  '    "credit-eat-mode": 1, ' . 
  '    "dfeu": true, ' . 
  '    "email": "em@a.il", ' . 
  '    "fax": "0461686868", ' . 
  '    "invoicing-email": "em@a.il", ' . 
  '    "language": "ita", ' . 
  '    "login": "myLogin", ' . 
  '    "name": "myNome", ' . 
  '    "num-cell-for-test-sms": "+393393939393", ' . 
  '    "password": "myPassword", ' . 
  '    "phone": "0461656565", ' . 
  '    "piva": "104456015145", ' . 
  '    "province": "TN", ' . 
  '    "superaccount": false, ' . 
  '    "surname": "mySurname", ' . 
  '    "use24": true, ' . 
  '    "zip-code": "38010", ' . 
  '    "id-subaccount-profile": 1' . 
  '}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_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: {ACCESS_TOKEN}'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_PUT, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

if ($info['http_code'] != 200) {
    echo('Error!');
}
else {
    echo('Success!');
}
?>
On success, the above command returns the following response:
# The HTTP location header that points to the edited subaccount:
'Location': '/subaccount/18107'
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 = """{
    "address": "via xxx", 
    "cell": "+393393939393", 
    "city": "myCity", 
    "fiscal-code": "BRGRJM87J89JH907E", 
    "company": true, 
    "company-name": "myCompany", 
    "credit-eat-mode": 1, 
    "dfeu": true, 
    "email": "em@a.il", 
    "fax": "0461686868", 
    "invoicing-email": "em@a.il", 
    "language": "ita", 
    "login": "myLogin", 
    "name": "myNome", 
    "num-cell-for-test-sms": "+393393939393", 
    "password": "myPassword", 
    "phone": "0461656565", 
    "piva": "104456015145", 
    "province": "TN", 
    "superaccount": false, 
    "surname": "mySurname", 
    "use24": true, 
    "zip-code": "38010", 
    "id-subaccount-profile": 1
}"""

r = requests.put("https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}", headers=headers, data=payload)

if r.status_code != 200:
    print("An error occurred, return code is: " + str(r.status_code))
else:
    print('Success!')
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/subaccount/{subaccount_id}',
    method: 'PUT',
    headers: { 'user_key' : '{USER_KEY}', 'Session_key' : '{SESSION_KEY}' },

    json: true,
    body:     {
        "address": "via xxx", 
        "cell": "+393393939393", 
        "city": "myCity", 
        "fiscal-code": "BRGRJM87J89JH907E", 
        "company": true, 
        "company-name": "myCompany", 
        "credit-eat-mode": 1, 
        "dfeu": true, 
        "email": "em@a.il", 
        "fax": "0461686868", 
        "invoicing-email": "em@a.il", 
        "language": "ita", 
        "login": "myLogin", 
        "name": "myNome", 
        "num-cell-for-test-sms": "+393393939393", 
        "password": "myPassword", 
        "phone": "0461656565", 
        "piva": "104456015145", 
        "province": "TN", 
        "superaccount": false, 
        "surname": "mySurname", 
        "use24": true, 
        "zip-code": "38010", 
        "id-subaccount-profile": 1
    },

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

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}")
payload =     {
        "address": "via xxx", 
        "cell": "+393393939393", 
        "city": "myCity", 
        "fiscal-code": "BRGRJM87J89JH907E", 
        "company": true, 
        "company-name": "myCompany", 
        "credit-eat-mode": 1, 
        "dfeu": true, 
        "email": "em@a.il", 
        "fax": "0461686868", 
        "invoicing-email": "em@a.il", 
        "language": "ita", 
        "login": "myLogin", 
        "name": "myNome", 
        "num-cell-for-test-sms": "+393393939393", 
        "password": "myPassword", 
        "phone": "0461656565", 
        "piva": "104456015145", 
        "province": "TN", 
        "superaccount": false, 
        "surname": "mySurname", 
        "use24": true, 
        "zip-code": "38010", 
        "id-subaccount-profile": 1
    }

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

request = Net::HTTP::Put.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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.."
end
On success, the above command returns the following response:
# The HTTP location header that points to the edited subaccount:
'Location': '/subaccount/18107'
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 = "{" + 
                  "    \"address\": \"via xxx\", " + 
                  "    \"cell\": \"+393393939393\", " + 
                  "    \"city\": \"myCity\", " + 
                  "    \"fiscal-code\": \"BRGRJM87J89JH907E\", " + 
                  "    \"company\": true, " + 
                  "    \"company-name\": \"myCompany\", " + 
                  "    \"credit-eat-mode\": 1, " + 
                  "    \"dfeu\": true, " + 
                  "    \"email\": \"em@a.il\", " + 
                  "    \"fax\": \"0461686868\", " + 
                  "    \"invoicing-email\": \"em@a.il\", " + 
                  "    \"language\": \"ita\", " + 
                  "    \"login\": \"myLogin\", " + 
                  "    \"name\": \"myNome\", " + 
                  "    \"num-cell-for-test-sms\": \"+393393939393\", " + 
                  "    \"password\": \"myPassword\", " + 
                  "    \"phone\": \"0461656565\", " + 
                  "    \"piva\": \"104456015145\", " + 
                  "    \"province\": \"TN\", " + 
                  "    \"superaccount\": false, " + 
                  "    \"surname\": \"mySurname\", " + 
                  "    \"use24\": true, " + 
                  "    \"zip-code\": \"38010\", " + 
                  "    \"id-subaccount-profile\": 1" + 
                  "}";

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

        }
    }
}
On success, the above command returns the following response:
# The HTTP location header that points to the edited subaccount:
'Location': '/subaccount/18107'
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/subaccount/{subaccount_id}";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $payload = {
    "address" => "via xxx", 
    "cell" => "+393393939393", 
    "city" => "myCity", 
    "fiscal-code" => "BRGRJM87J89JH907E", 
    "company" => true, 
    "company-name" => "myCompany", 
    "credit-eat-mode" => 1, 
    "dfeu" => true, 
    "email" => "em@a.il", 
    "fax" => "0461686868", 
    "invoicing-email" => "em@a.il", 
    "language" => "ita", 
    "login" => "myLogin", 
    "name" => "myNome", 
    "num-cell-for-test-sms" => "+393393939393", 
    "password" => "myPassword", 
    "phone" => "0461656565", 
    "piva" => "104456015145", 
    "province" => "TN", 
    "superaccount" => false, 
    "surname" => "mySurname", 
    "use24" => true, 
    "zip-code" => "38010", 
    "id-subaccount-profile" => 1
};

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

}
On success, the above command returns the following response:
# The HTTP location header that points to the edited subaccount:
'Location': '/subaccount/18107'

Change subaccount password

Change a subaccount’s password

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/changepwd

Parameters

Parameter Type Description Required Default
subaccount_id Int The subaccount ID Yes -

Body Fields

Parameter Type Description Required Default
passwd String The subaccount password (min 8 chars, max 16 chars) Yes -

Returns

Code Description
201 Password correctly changed. HTTP Location header pointing to the change password URL.
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found
Copy code
# Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/changepwd' -H 'Content-Type: application/json' \
-H 'user_key: {USER_KEY}' -H 'Session_key: {SESSION_KEY}' -d'
{
    "passwd": "password"
}
'

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/changepwd' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}' -d'
{
    "passwd": "password"
}
'
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'change password' URL:
'Location': '/subaccount/{subaccount_id}/changepwd'
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/subaccount/{subaccount_id}/changepwd");
            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 = "{" + 
              "    \"passwd\": \"password\"" + 
              "}";

            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 subaccount 'change password' URL:
'Location': '/subaccount/{subaccount_id}/changepwd'
Copy code
<?php

$payload = '{' . 
  '    "passwd": "password"' . 
  '}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/changepwd');
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 subaccount 'change password' URL:
'Location': '/subaccount/{subaccount_id}/changepwd'
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 = """{
    "passwd": "password"
}"""

r = requests.post("https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/changepwd", 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 subaccount 'change password' URL:
'Location': '/subaccount/{subaccount_id}/changepwd'
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/subaccount/{subaccount_id}/changepwd',
    method: 'POST',
    headers: { 'user_key' : '{USER_KEY}', 'Session_key' : '{SESSION_KEY}' },

    json: true,
    body:     {
        "passwd": "password"
    },

    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 subaccount 'change password' URL:
'Location': '/subaccount/{subaccount_id}/changepwd'
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/changepwd")
payload =     {
        "passwd": "password"
    }

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

request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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 subaccount 'change password' URL:
'Location': '/subaccount/{subaccount_id}/changepwd'
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 = "{" + 
                  "    \"passwd\": \"password\"" + 
                  "}";

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

        }
    }
}
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'change password' URL:
'Location': '/subaccount/{subaccount_id}/changepwd'
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/subaccount/{subaccount_id}/changepwd";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $payload = {
    "passwd" => "password"
};

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

}
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'change password' URL:
'Location': '/subaccount/{subaccount_id}/changepwd'

Get subaccount

Get a subaccount’s details

HTTP Headers

user_key / Session_key

HTTP Method

GET

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}

Parameters

Parameter Type Description Required Default
subaccount_id Int The subaccount ID Yes -

Returns

Code Description
200 Successful request
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found

The “credits” and “credits-sum” fields will be populated only in the case in which the subaccount has “credit-eat-mode” = 2. Move credit

Copy code
# Session Key example
curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}' -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/subaccount/{subaccount_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:
{
  "activation-time": "20160823",
  "active": true,
  "address": "via",
  "allowtpoavalidation": true,
  "cell": "+393385958233",
  "city": "Città",
  "fiscal-code": "FDFWEE92L45L458E",
  "pa-code": null,
  "company": false,
  "company-name": null,
  "create-time": "20160823",
  "credit-eat-mode": 2,
  "credits-sum": "€ 0,000",
  "default-message-type": \"L\",
  "default-nation": "ita",
  "dfeu": true,
  "email": "prova@prova.pr",
  "fax": "0461657575",
  "foreign": false,
  "id-user": 5,
  "invoicing-email": null,
  "language": "ita",
  "legal-agreement-time": "20160823",
  "legalAgreementVersion": 0,
  "login": "logon",
  "max-subaccounts": -1,
  "name": "nome",
  "num-cell-for-test-sms": "+393385958233",
  "partner": false,
  "partner-code": null,
  "phone": "0461657575",
  "piva": null,
  "preferred-tpoa": "+393385958233",
  "private": true,
  "province": "Trento",
  "referral": false,
  "shop_cart_check": true,
  "split-payment": false,
  "subaccount": true,
  "subaccount-types": 0,
  "super-account-name": "",
  "superaccount": false,
  "surname": "asdasd",
  "use24": true,
  "user-nation": "ita",
  "zip-code": "38010",
  "credits": [
    {
      "id": "N",
      "qty": 0
    },
    {
      "id": "L",
      "qty": 0
    },
    {
      "id": "LL",
      "qty": 0
    },
    {
      "id": "EE",
      "qty": 0
    }
  ]
}
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/subaccount/{subaccount_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", "{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 EEON 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:
{
  "activation-time": "20160823",
  "active": true,
  "address": "via",
  "allowtpoavalidation": true,
  "cell": "+393385958233",
  "city": "Città",
  "fiscal-code": "FDFWEE92L45L458E",
  "pa-code": null,
  "company": false,
  "company-name": null,
  "create-time": "20160823",
  "credit-eat-mode": 2,
  "credits-sum": "€ 0,000",
  "default-message-type": \"L\",
  "default-nation": "ita",
  "dfeu": true,
  "email": "prova@prova.pr",
  "fax": "0461657575",
  "foreign": false,
  "id-user": 5,
  "invoicing-email": null,
  "language": "ita",
  "legal-agreement-time": "20160823",
  "legalAgreementVersion": 0,
  "login": "logon",
  "max-subaccounts": -1,
  "name": "nome",
  "num-cell-for-test-sms": "+393385958233",
  "partner": false,
  "partner-code": null,
  "phone": "0461657575",
  "piva": null,
  "preferred-tpoa": "+393385958233",
  "private": true,
  "province": "Trento",
  "referral": false,
  "shop_cart_check": true,
  "split-payment": false,
  "subaccount": true,
  "subaccount-types": 0,
  "super-account-name": "",
  "superaccount": false,
  "surname": "asdasd",
  "use24": true,
  "user-nation": "ita",
  "zip-code": "38010",
  "credits": [
    {
      "id": "N",
      "qty": 0
    },
    {
      "id": "L",
      "qty": 0
    },
    {
      "id": "LL",
      "qty": 0
    },
    {
      "id": "EE",
      "qty": 0
    }
  ]
}
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_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: {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:
{
  "activation-time": "20160823",
  "active": true,
  "address": "via",
  "allowtpoavalidation": true,
  "cell": "+393385958233",
  "city": "Città",
  "fiscal-code": "FDFWEE92L45L458E",
  "pa-code": null,
  "company": false,
  "company-name": null,
  "create-time": "20160823",
  "credit-eat-mode": 2,
  "credits-sum": "€ 0,000",
  "default-message-type": \"L\",
  "default-nation": "ita",
  "dfeu": true,
  "email": "prova@prova.pr",
  "fax": "0461657575",
  "foreign": false,
  "id-user": 5,
  "invoicing-email": null,
  "language": "ita",
  "legal-agreement-time": "20160823",
  "legalAgreementVersion": 0,
  "login": "logon",
  "max-subaccounts": -1,
  "name": "nome",
  "num-cell-for-test-sms": "+393385958233",
  "partner": false,
  "partner-code": null,
  "phone": "0461657575",
  "piva": null,
  "preferred-tpoa": "+393385958233",
  "private": true,
  "province": "Trento",
  "referral": false,
  "shop_cart_check": true,
  "split-payment": false,
  "subaccount": true,
  "subaccount-types": 0,
  "super-account-name": "",
  "superaccount": false,
  "surname": "asdasd",
  "use24": true,
  "user-nation": "ita",
  "zip-code": "38010",
  "credits": [
    {
      "id": "N",
      "qty": 0
    },
    {
      "id": "L",
      "qty": 0
    },
    {
      "id": "LL",
      "qty": 0
    },
    {
      "id": "EE",
      "qty": 0
    }
  ]
}
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/subaccount/{subaccount_id}", 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:
{
  "activation-time": "20160823",
  "active": true,
  "address": "via",
  "allowtpoavalidation": true,
  "cell": "+393385958233",
  "city": "Città",
  "fiscal-code": "FDFWEE92L45L458E",
  "pa-code": null,
  "company": false,
  "company-name": null,
  "create-time": "20160823",
  "credit-eat-mode": 2,
  "credits-sum": "€ 0,000",
  "default-message-type": \"L\",
  "default-nation": "ita",
  "dfeu": true,
  "email": "prova@prova.pr",
  "fax": "0461657575",
  "foreign": false,
  "id-user": 5,
  "invoicing-email": null,
  "language": "ita",
  "legal-agreement-time": "20160823",
  "legalAgreementVersion": 0,
  "login": "logon",
  "max-subaccounts": -1,
  "name": "nome",
  "num-cell-for-test-sms": "+393385958233",
  "partner": false,
  "partner-code": null,
  "phone": "0461657575",
  "piva": null,
  "preferred-tpoa": "+393385958233",
  "private": true,
  "province": "Trento",
  "referral": false,
  "shop_cart_check": true,
  "split-payment": false,
  "subaccount": true,
  "subaccount-types": 0,
  "super-account-name": "",
  "superaccount": false,
  "surname": "asdasd",
  "use24": true,
  "user-nation": "ita",
  "zip-code": "38010",
  "credits": [
    {
      "id": "N",
      "qty": 0
    },
    {
      "id": "L",
      "qty": 0
    },
    {
      "id": "LL",
      "qty": 0
    },
    {
      "id": "EE",
      "qty": 0
    }
  ]
}
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/subaccount/{subaccount_id}',
    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:
{
  "activation-time": "20160823",
  "active": true,
  "address": "via",
  "allowtpoavalidation": true,
  "cell": "+393385958233",
  "city": "Città",
  "fiscal-code": "FDFWEE92L45L458E",
  "pa-code": null,
  "company": false,
  "company-name": null,
  "create-time": "20160823",
  "credit-eat-mode": 2,
  "credits-sum": "€ 0,000",
  "default-message-type": \"L\",
  "default-nation": "ita",
  "dfeu": true,
  "email": "prova@prova.pr",
  "fax": "0461657575",
  "foreign": false,
  "id-user": 5,
  "invoicing-email": null,
  "language": "ita",
  "legal-agreement-time": "20160823",
  "legalAgreementVersion": 0,
  "login": "logon",
  "max-subaccounts": -1,
  "name": "nome",
  "num-cell-for-test-sms": "+393385958233",
  "partner": false,
  "partner-code": null,
  "phone": "0461657575",
  "piva": null,
  "preferred-tpoa": "+393385958233",
  "private": true,
  "province": "Trento",
  "referral": false,
  "shop_cart_check": true,
  "split-payment": false,
  "subaccount": true,
  "subaccount-types": 0,
  "super-account-name": "",
  "superaccount": false,
  "surname": "asdasd",
  "use24": true,
  "user-nation": "ita",
  "zip-code": "38010",
  "credits": [
    {
      "id": "N",
      "qty": 0
    },
    {
      "id": "L",
      "qty": 0
    },
    {
      "id": "LL",
      "qty": 0
    },
    {
      "id": "EE",
      "qty": 0
    }
  ]
}
Copy code
require 'net/http'
require 'uri'
require 'json'

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

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

request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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:
{
  "activation-time": "20160823",
  "active": true,
  "address": "via",
  "allowtpoavalidation": true,
  "cell": "+393385958233",
  "city": "Città",
  "fiscal-code": "FDFWEE92L45L458E",
  "pa-code": null,
  "company": false,
  "company-name": null,
  "create-time": "20160823",
  "credit-eat-mode": 2,
  "credits-sum": "€ 0,000",
  "default-message-type": \"L\",
  "default-nation": "ita",
  "dfeu": true,
  "email": "prova@prova.pr",
  "fax": "0461657575",
  "foreign": false,
  "id-user": 5,
  "invoicing-email": null,
  "language": "ita",
  "legal-agreement-time": "20160823",
  "legalAgreementVersion": 0,
  "login": "logon",
  "max-subaccounts": -1,
  "name": "nome",
  "num-cell-for-test-sms": "+393385958233",
  "partner": false,
  "partner-code": null,
  "phone": "0461657575",
  "piva": null,
  "preferred-tpoa": "+393385958233",
  "private": true,
  "province": "Trento",
  "referral": false,
  "shop_cart_check": true,
  "split-payment": false,
  "subaccount": true,
  "subaccount-types": 0,
  "super-account-name": "",
  "superaccount": false,
  "surname": "asdasd",
  "use24": true,
  "user-nation": "ita",
  "zip-code": "38010",
  "credits": [
    {
      "id": "N",
      "qty": 0
    },
    {
      "id": "L",
      "qty": 0
    },
    {
      "id": "LL",
      "qty": 0
    },
    {
      "id": "EE",
      "qty": 0
    }
  ]
}
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/subaccount/{subaccount_id}");

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

        }
    }
}
On success, the above command returns the following response:
{
  "activation-time": "20160823",
  "active": true,
  "address": "via",
  "allowtpoavalidation": true,
  "cell": "+393385958233",
  "city": "Città",
  "fiscal-code": "FDFWEE92L45L458E",
  "pa-code": null,
  "company": false,
  "company-name": null,
  "create-time": "20160823",
  "credit-eat-mode": 2,
  "credits-sum": "€ 0,000",
  "default-message-type": \"L\",
  "default-nation": "ita",
  "dfeu": true,
  "email": "prova@prova.pr",
  "fax": "0461657575",
  "foreign": false,
  "id-user": 5,
  "invoicing-email": null,
  "language": "ita",
  "legal-agreement-time": "20160823",
  "legalAgreementVersion": 0,
  "login": "logon",
  "max-subaccounts": -1,
  "name": "nome",
  "num-cell-for-test-sms": "+393385958233",
  "partner": false,
  "partner-code": null,
  "phone": "0461657575",
  "piva": null,
  "preferred-tpoa": "+393385958233",
  "private": true,
  "province": "Trento",
  "referral": false,
  "shop_cart_check": true,
  "split-payment": false,
  "subaccount": true,
  "subaccount-types": 0,
  "super-account-name": "",
  "superaccount": false,
  "surname": "asdasd",
  "use24": true,
  "user-nation": "ita",
  "zip-code": "38010",
  "credits": [
    {
      "id": "N",
      "qty": 0
    },
    {
      "id": "L",
      "qty": 0
    },
    {
      "id": "LL",
      "qty": 0
    },
    {
      "id": "EE",
      "qty": 0
    }
  ]
}
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/subaccount/{subaccount_id}";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
  $response = $resp->decoded_content;
  my $obj = from_json($response);

}
On success, the above command returns the following response:
{
  "activation-time": "20160823",
  "active": true,
  "address": "via",
  "allowtpoavalidation": true,
  "cell": "+393385958233",
  "city": "Città",
  "fiscal-code": "FDFWEE92L45L458E",
  "pa-code": null,
  "company": false,
  "company-name": null,
  "create-time": "20160823",
  "credit-eat-mode": 2,
  "credits-sum": "€ 0,000",
  "default-message-type": \"L\",
  "default-nation": "ita",
  "dfeu": true,
  "email": "prova@prova.pr",
  "fax": "0461657575",
  "foreign": false,
  "id-user": 5,
  "invoicing-email": null,
  "language": "ita",
  "legal-agreement-time": "20160823",
  "legalAgreementVersion": 0,
  "login": "logon",
  "max-subaccounts": -1,
  "name": "nome",
  "num-cell-for-test-sms": "+393385958233",
  "partner": false,
  "partner-code": null,
  "phone": "0461657575",
  "piva": null,
  "preferred-tpoa": "+393385958233",
  "private": true,
  "province": "Trento",
  "referral": false,
  "shop_cart_check": true,
  "split-payment": false,
  "subaccount": true,
  "subaccount-types": 0,
  "super-account-name": "",
  "superaccount": false,
  "surname": "asdasd",
  "use24": true,
  "user-nation": "ita",
  "zip-code": "38010",
  "credits": [
    {
      "id": "N",
      "qty": 0
    },
    {
      "id": "L",
      "qty": 0
    },
    {
      "id": "LL",
      "qty": 0
    },
    {
      "id": "EE",
      "qty": 0
    }
  ]
}

Move credits from/to subaccount

Transfers credits between a superaccount and a subaccount.

The subaccount must be enabled to have its own credits (i.e. subaccount credit-eat-mode is 0 or 2)

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/credit

Parameters

Parameter Type Description Required Default
subaccount_id Int The subaccount ID Yes -

Body Fields

Parameter Type Description Required Default
credits List(Credit) The list of credits to move Yes -
Credit.message-type String The message type (“N” for High quality with reception notification, “L” for Medium Quality, “LL” For Low Cost) Yes -
Credit.amount Int The number of credits to transfer
Credit.super-to-sub Bool The transfer direction. true for superaccount to subaccount, false for subaccount to superaccount Yes -

Returns

Code Description
201 Credits were successfully moved. The HTTP Location header points to the API to recover credits
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found
Copy code
# Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/credit' -H 'Content-Type: application/json' \
-H 'user_key: {USER_KEY}' -H 'Session_key: {SESSION_KEY}' -d'
{
    "credits": [
        {
            "message-type": "N", 
            "amount": 5, 
            "super-to-sub": true
        }, 
        {
            "message-type": \"L\", 
            "amount": 50, 
            "super-to-sub": true
        }
    ]
}
'

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/credit' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}' -d'
{
    "credits": [
        {
            "message-type": "N", 
            "amount": 5, 
            "super-to-sub": true
        }, 
        {
            "message-type": \"L\", 
            "amount": 50, 
            "super-to-sub": true
        }
    ]
}
'
On success, the above command returns the following response:
# The HTTP Location header points to the API to recover credits:
'Location': '/subaccount/{subaccount_id}/credit'
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/subaccount/{subaccount_id}/credit");
            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 = "{" + 
              "    \"credits\": [" + 
              "        {" + 
              "            \"message-type\": \"N\", " + 
              "            \"amount\": 5, " + 
              "            \"super-to-sub\": true" + 
              "        }, " + 
              "        {" + 
              "            \"message-type\": \"SI\", " + 
              "            \"amount\": 50, " + 
              "            \"super-to-sub\": true" + 
              "        }" + 
              "    ]" + 
              "}";

            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 points to the API to recover credits:
'Location': '/subaccount/{subaccount_id}/credit'
Copy code
<?php

$payload = '{' . 
  '    "credits": [' . 
  '        {' . 
  '            "message-type": "N", ' . 
  '            "amount": 5, ' . 
  '            "super-to-sub": true' . 
  '        }, ' . 
  '        {' . 
  '            "message-type": \"L\", ' . 
  '            "amount": 50, ' . 
  '            "super-to-sub": true' . 
  '        }' . 
  '    ]' . 
  '}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/credit');
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!');
}
?>
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 = """{
    "credits": [
        {
            "message-type": "N", 
            "amount": 5, 
            "super-to-sub": true
        }, 
        {
            "message-type": \"L\", 
            "amount": 50, 
            "super-to-sub": true
        }
    ]
}"""

r = requests.post("https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/credit", 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 points to the API to recover credits:
'Location': '/subaccount/{subaccount_id}/credit'
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/subaccount/{subaccount_id}/credit',
    method: 'POST',
    headers: { 'user_key' : '{USER_KEY}', 'Session_key' : '{SESSION_KEY}' },

    json: true,
    body:     {
        "credits": [
            {
                "message-type": "N", 
                "amount": 5, 
                "super-to-sub": true
            }, 
            {
                "message-type": \"L\", 
                "amount": 50, 
                "super-to-sub": true
            }
        ]
    },

    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 points to the API to recover credits:
'Location': '/subaccount/{subaccount_id}/credit'
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/credit")
payload =     {
        "credits": [
            {
                "message-type": "N", 
                "amount": 5, 
                "super-to-sub": true
            }, 
            {
                "message-type": \"L\", 
                "amount": 50, 
                "super-to-sub": true
            }
        ]
    }

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

request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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 points to the API to recover credits:
'Location': '/subaccount/{subaccount_id}/credit'
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 = "{" + 
                  "    \"credits\": [" + 
                  "        {" + 
                  "            \"message-type\": \"N\", " + 
                  "            \"amount\": 5, " + 
                  "            \"super-to-sub\": true" + 
                  "        }, " + 
                  "        {" + 
                  "            \"message-type\": \"SI\", " + 
                  "            \"amount\": 50, " + 
                  "            \"super-to-sub\": true" + 
                  "        }" + 
                  "    ]" + 
                  "}";

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

        }
    }
}
On success, the above command returns the following response:
# The HTTP Location header points to the API to recover credits:
'Location': '/subaccount/{subaccount_id}/credit'
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/subaccount/{subaccount_id}/credit";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $payload = {
    "credits" => [
        {
            "message-type" => "N", 
            "amount" => 5, 
            "super-to-sub" => true
        }, 
        {
            "message-type" => \"L\", 
            "amount" => 50, 
            "super-to-sub" => true
        }
    ]
};

$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 points to the API to recover credits:
'Location': '/subaccount/{subaccount_id}/credit'

Get subaccount available credits

Returns the available credits of the given subaccount

HTTP Headers

user_key / Session_key

HTTP Method

GET

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/credit

Parameters

Parameter Type Description Required Default
subaccount_id Int or String The subaccount ID or Login Yes -

Returns

Code Description
200 Successful request, returns a JSON object with the available credits details
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found
Copy code
# Session Key example
curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/credit' -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/subaccount/{subaccount_id}/credit' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}'
On success, the above command returns the following response:
{
  "result": "OK",
  "credits": [
    {
      "message-type": "N",
      "amount": 20
    },
    {
      "message-type": \"L\",
      "amount": 150
    }
  ]
}
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/subaccount/{subaccount_id}/credit");
            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 EEON 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:
{
  "result": "OK",
  "credits": [
    {
      "message-type": "N",
      "amount": 20
    },
    {
      "message-type": \"L\",
      "amount": 150
    }
  ]
}
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/credit');
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:
{
  "result": "OK",
  "credits": [
    {
      "message-type": "N",
      "amount": 20
    },
    {
      "message-type": \"L\",
      "amount": 150
    }
  ]
}
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/subaccount/{subaccount_id}/credit", 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:
{
  "result": "OK",
  "credits": [
    {
      "message-type": "N",
      "amount": 20
    },
    {
      "message-type": \"L\",
      "amount": 150
    }
  ]
}
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/subaccount/{subaccount_id}/credit',
    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:
{
  "result": "OK",
  "credits": [
    {
      "message-type": "N",
      "amount": 20
    },
    {
      "message-type": \"L\",
      "amount": 150
    }
  ]
}
Copy code
require 'net/http'
require 'uri'
require 'json'

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

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

request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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:
{
  "result": "OK",
  "credits": [
    {
      "message-type": "N",
      "amount": 20
    },
    {
      "message-type": \"L\",
      "amount": 150
    }
  ]
}
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/subaccount/{subaccount_id}/credit");

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

        }
    }
}
On success, the above command returns the following response:
{
  "result": "OK",
  "credits": [
    {
      "message-type": "N",
      "amount": 20
    },
    {
      "message-type": \"L\",
      "amount": 150
    }
  ]
}
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/subaccount/{subaccount_id}/credit";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
  $response = $resp->decoded_content;
  my $obj = from_json($response);

}
On success, the above command returns the following response:
{
  "result": "OK",
  "credits": [
    {
      "message-type": "N",
      "amount": 20
    },
    {
      "message-type": \"L\",
      "amount": 150
    }
  ]
}

Get a subaccount’s purchases

Returns the paginated list of purchases made by a subaccount. Caller must be a superaccount.

HTTP Headers

user_key / Session_key

HTTP Method

GET

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase?pageNumber={page}&pageSize={size}

Parameters

subaccount_id Int or String The subaccount ID or Login Yes -
pageNumber Int Return the given results page No 1
pageSize Int The number of results in a page No 10

Returns

Code Description
200 The paginated list of the subaccount’s purchases
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found
Copy code
# Session Key example
curl -XGET 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase' -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/subaccount/{subaccount_id}/purchase' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}' 
							
On success, the above command returns the following response:
{
  "result": "OK",
  "purchases": [
    {
      "super-to-sub": false,
      "amount": 37,
      "create-time": "20160826104539",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    },
    {
      "super-to-sub": true,
      "amount": 37,
      "create-time": "20160826103027",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    }
  ],
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2
}
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/subaccount/{subaccount_id}/purchase");
            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 EEON 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:
{
  "result": "OK",
  "purchases": [
    {
      "super-to-sub": false,
      "amount": 37,
      "create-time": "20160826104539",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    },
    {
      "super-to-sub": true,
      "amount": 37,
      "create-time": "20160826103027",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    }
  ],
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2
}
Copy code
<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase');
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:
{
  "result": "OK",
  "purchases": [
    {
      "super-to-sub": false,
      "amount": 37,
      "create-time": "20160826104539",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    },
    {
      "super-to-sub": true,
      "amount": 37,
      "create-time": "20160826103027",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    }
  ],
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2
}
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/subaccount/{subaccount_id}/purchase", 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:
{
  "result": "OK",
  "purchases": [
    {
      "super-to-sub": false,
      "amount": 37,
      "create-time": "20160826104539",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    },
    {
      "super-to-sub": true,
      "amount": 37,
      "create-time": "20160826103027",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    }
  ],
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2
}
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/subaccount/{subaccount_id}/purchase',
    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:
{
  "result": "OK",
  "purchases": [
    {
      "super-to-sub": false,
      "amount": 37,
      "create-time": "20160826104539",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    },
    {
      "super-to-sub": true,
      "amount": 37,
      "create-time": "20160826103027",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    }
  ],
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2
}
Copy code
require 'net/http'
require 'uri'
require 'json'

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

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

request = Net::HTTP::Get.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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:
{
  "result": "OK",
  "purchases": [
    {
      "super-to-sub": false,
      "amount": 37,
      "create-time": "20160826104539",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    },
    {
      "super-to-sub": true,
      "amount": 37,
      "create-time": "20160826103027",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    }
  ],
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2
}
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/subaccount/{subaccount_id}/purchase");

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

        }
    }
}
On success, the above command returns the following response:
{
  "result": "OK",
  "purchases": [
    {
      "super-to-sub": false,
      "amount": 37,
      "create-time": "20160826104539",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    },
    {
      "super-to-sub": true,
      "amount": 37,
      "create-time": "20160826103027",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    }
  ],
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2
}
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/subaccount/{subaccount_id}/purchase";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $resp = $ua->request($req);
if ($resp->is_success && $resp->code == 200) {
  $response = $resp->decoded_content;
  my $obj = from_json($response);

}
On success, the above command returns the following response:
{
  "result": "OK",
  "purchases": [
    {
      "super-to-sub": false,
      "amount": 37,
      "create-time": "20160826104539",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    },
    {
      "super-to-sub": true,
      "amount": 37,
      "create-time": "20160826103027",
      "id_purchase": 20,
      "price": 37,
      "available": 0,
      "message-types": [
        {
          "message-type": "N",
          "unit-price": 1.2
        },
        {
          "message-type": "LL",
          "unit-price": 0.8
        }
      ]
    }
  ],
  "pageNumber": 1,
  "pageSize": 10,
  "total": 2
}

Create a subaccount purchase

Creates one or more purchases for the given subaccount.

Subaccount credit-eat-mode must be 2. Caller must be a superaccount.

HTTP Headers

user_key / Session_key

HTTP Method

POST

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount}/purchase

Parameters

Parameter Type Description Required Default
subaccount_id Int or String The subaccount ID or Login Yes -

Body Fields

Parameter Type Description Required Default
purchases List(Purchase) The list of purchases to be created Yes -
Purchase.message-types List(MessageType) The purchase’s message types Yes -
Purchase.price Float The quantity of purchased credits Yes -
MessageType.message-type String The message type (“N” for High quality with reception notification, “L” for Medium Quality, “LL” For Low Cost) Yes -
MessageType.unit-price Float The cost for the subaccount of a unit of the respective message-type Yes -

Returns

Code Description
200 Successful request. The HTTP location header that points to the subaccount ‘create purchase’ URL
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found
Copy code
 Session Key example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase' -H 'Content-Type: application/json' \
-H 'user_key: {USER_KEY}' -H 'Session_key: {SESSION_KEY}' -d'
{
    "purchases": [
        {
            "super-to-sub": true, 
            "price": 25.0, 
            "message-types": [
                {
                    "message-type": "N", 
                    "unit-price": 1.1
                }, 
                {
                    "message-type": \"L\", 
                    "unit-price": 0.7
                }
            ]
        }, 
        {
            "super-to-sub": true, 
            "price": 37.0, 
            "message-types": [
                {
                    "message-type": "N", 
                    "unit-price": 1.2
                }, 
                {
                    "message-type": \"L\", 
                    "unit-price": 0.8
                }
            ]
        }
    ]
}
'

# Access token example
curl -XPOST 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase' -H 'Content-Type: application/json' \
 -H 'user_key: {USER_KEY}' -H 'Access_token: {ACCESS_TOKEN}' -d'
{
    "purchases": [
        {
            "super-to-sub": true, 
            "price": 25.0, 
            "message-types": [
                {
                    "message-type": "N", 
                    "unit-price": 1.1
                }, 
                {
                    "message-type": \"L\", 
                    "unit-price": 0.7
                }
            ]
        }, 
        {
            "super-to-sub": true, 
            "price": 37.0, 
            "message-types": [
                {
                    "message-type": "N", 
                    "unit-price": 1.2
                }, 
                {
                    "message-type": \"L\", 
                    "unit-price": 0.8
                }
            ]
        }
    ]
}
'
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'create purchase' URL:
'Location': '/subaccount/{subaccount_id}/purchase'
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/subaccount/{subaccount_id}/purchase");
            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 = "{" + 
              "    \"purchases\": [" + 
              "        {" + 
              "            \"super-to-sub\": true, " + 
              "            \"price\": 25.0, " + 
              "            \"message-types\": [" + 
              "                {" + 
              "                    \"message-type\": \"N\", " + 
              "                    \"unit-price\": 1.1" + 
              "                }, " + 
              "                {" + 
              "                    \"message-type\": \"SI\", " + 
              "                    \"unit-price\": 0.7" + 
              "                }" + 
              "            ]" + 
              "        }, " + 
              "        {" + 
              "            \"super-to-sub\": true, " + 
              "            \"price\": 37.0, " + 
              "            \"message-types\": [" + 
              "                {" + 
              "                    \"message-type\": \"N\", " + 
              "                    \"unit-price\": 1.2" + 
              "                }, " + 
              "                {" + 
              "                    \"message-type\": \"SI\", " + 
              "                    \"unit-price\": 0.8" + 
              "                }" + 
              "            ]" + 
              "        }" + 
              "    ]" + 
              "}";

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

            if (conn.getResponseCode() != 200) {
                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 subaccount 'create purchase' URL:
'Location': '/subaccount/{subaccount_id}/purchase'
Copy code
<?php

$payload = '{' . 
  '    "purchases": [' . 
  '        {' . 
  '            "super-to-sub": true, ' . 
  '            "price": 25.0, ' . 
  '            "message-types": [' . 
  '                {' . 
  '                    "message-type": "N", ' . 
  '                    "unit-price": 1.1' . 
  '                }, ' . 
  '                {' . 
  '                    "message-type": \"L\", ' . 
  '                    "unit-price": 0.7' . 
  '                }' . 
  '            ]' . 
  '        }, ' . 
  '        {' . 
  '            "super-to-sub": true, ' . 
  '            "price": 37.0, ' . 
  '            "message-types": [' . 
  '                {' . 
  '                    "message-type": "N", ' . 
  '                    "unit-price": 1.2' . 
  '                }, ' . 
  '                {' . 
  '                    "message-type": \"L\", ' . 
  '                    "unit-price": 0.8' . 
  '                }' . 
  '            ]' . 
  '        }' . 
  '    ]' . 
  '}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase');
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'] != 200) {
    echo('Error!');
}
else {
    echo('Success!');
}
?>
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'create purchase' URL:
'Location': '/subaccount/{subaccount_id}/purchase'
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 = """{
    "purchases": [
        {
            "super-to-sub": true, 
            "price": 25.0, 
            "message-types": [
                {
                    "message-type": "N", 
                    "unit-price": 1.1
                }, 
                {
                    "message-type": \"L\", 
                    "unit-price": 0.7
                }
            ]
        }, 
        {
            "super-to-sub": true, 
            "price": 37.0, 
            "message-types": [
                {
                    "message-type": "N", 
                    "unit-price": 1.2
                }, 
                {
                    "message-type": \"L\", 
                    "unit-price": 0.8
                }
            ]
        }
    ]
}"""

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

if r.status_code != 200:
    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 subaccount 'create purchase' URL:
'Location': '/subaccount/{subaccount_id}/purchase'
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/subaccount/{subaccount_id}/purchase',
    method: 'POST',
    headers: { 'user_key' : '{USER_KEY}', 'Session_key' : '{SESSION_KEY}' },

    json: true,
    body:     {
        "purchases": [
            {
                "super-to-sub": true, 
                "price": 25.0, 
                "message-types": [
                    {
                        "message-type": "N", 
                        "unit-price": 1.1
                    }, 
                    {
                        "message-type": \"L\", 
                        "unit-price": 0.7
                    }
                ]
            }, 
            {
                "super-to-sub": true, 
                "price": 37.0, 
                "message-types": [
                    {
                        "message-type": "N", 
                        "unit-price": 1.2
                    }, 
                    {
                        "message-type": \"L\", 
                        "unit-price": 0.8
                    }
                ]
            }
        ]
    },

    callback: function (error, responseMeta, response) {
        if (!error && responseMeta.statusCode == 200) {
            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 subaccount 'create purchase' URL:
'Location': '/subaccount/{subaccount_id}/purchase'
Copy code
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase")
payload =     {
        "purchases": [
            {
                "super-to-sub": true, 
                "price": 25.0, 
                "message-types": [
                    {
                        "message-type": "N", 
                        "unit-price": 1.1
                    }, 
                    {
                        "message-type": \"L\", 
                        "unit-price": 0.7
                    }
                ]
            }, 
            {
                "super-to-sub": true, 
                "price": 37.0, 
                "message-types": [
                    {
                        "message-type": "N", 
                        "unit-price": 1.2
                    }, 
                    {
                        "message-type": \"L\", 
                        "unit-price": 0.8
                    }
                ]
            }
        ]
    }

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

request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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.."
end
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'create purchase' URL:
'Location': '/subaccount/{subaccount_id}/purchase'
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 = "{" + 
                  "    \"purchases\": [" + 
                  "        {" + 
                  "            \"super-to-sub\": true, " + 
                  "            \"price\": 25.0, " + 
                  "            \"message-types\": [" + 
                  "                {" + 
                  "                    \"message-type\": \"N\", " + 
                  "                    \"unit-price\": 1.1" + 
                  "                }, " + 
                  "                {" + 
                  "                    \"message-type\": \"SI\", " + 
                  "                    \"unit-price\": 0.7" + 
                  "                }" + 
                  "            ]" + 
                  "        }, " + 
                  "        {" + 
                  "            \"super-to-sub\": true, " + 
                  "            \"price\": 37.0, " + 
                  "            \"message-types\": [" + 
                  "                {" + 
                  "                    \"message-type\": \"N\", " + 
                  "                    \"unit-price\": 1.2" + 
                  "                }, " + 
                  "                {" + 
                  "                    \"message-type\": \"SI\", " + 
                  "                    \"unit-price\": 0.8" + 
                  "                }" + 
                  "            ]" + 
                  "        }" + 
                  "    ]" + 
                  "}";

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

        }
    }
}
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'create purchase' URL:
'Location': '/subaccount/{subaccount_id}/purchase'
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/subaccount/{subaccount_id}/purchase";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $payload = {
    "purchases" => [
        {
            "super-to-sub" => true, 
            "price" => 25.0, 
            "message-types" => [
                {
                    "message-type" => "N", 
                    "unit-price" => 1.1
                }, 
                {
                    "message-type" => \"L\", 
                    "unit-price" => 0.7
                }
            ]
        }, 
        {
            "super-to-sub" => true, 
            "price" => 37.0, 
            "message-types" => [
                {
                    "message-type" => "N", 
                    "unit-price" => 1.2
                }, 
                {
                    "message-type" => \"L\", 
                    "unit-price" => 0.8
                }
            ]
        }
    ]
};

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

}
						    
On success, the above command returns the following response:
# The HTTP location header that points to the subaccount 'create purchase' URL:
'Location': '/subaccount/{subaccount_id}/purchase'

Delete a subaccount’s purchase

Deletes a purchase of the given subaccount.

Caller must be a superaccount, and the Subaccount’s credit-eat-mode should be 2.

HTTP Headers

user_key / Session_key

HTTP Method

DELETE

HTTP Request

https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase/{purchase_id}

Parameters

Parameter Type Description Required Default
subaccount_id Int or String The subaccount ID or Login Yes -
purchase_id Int The purchase ID Yes -

Returns

Code Description
200 Successful request, purchase successfully deleted
400 Other errors, details are in the body
401 [Unauthorized] User_key, Token or Session_key are invalid or not provided
404 [Not found] The User_key was not found
Copy code
# Session Key example
curl -XDELETE 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase/{purchase_id}' -H 'Content-Type: application/json' \
-H 'user_key: {USER_KEY}' -H 'Session_key: {SESSION_KEY}' 

# Access token example
curl -XDELETE 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase/{purchase_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:
{"result":"OK"}
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/subaccount/{subaccount_id}/purchase");
            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 = "{" + 
              "    \"purchases\": [" + 
              "        {" + 
              "            \"super-to-sub\": true, " + 
              "            \"price\": 25.0, " + 
              "            \"message-types\": [" + 
              "                {" + 
              "                    \"message-type\": \"N\", " + 
              "                    \"unit-price\": 1.1" + 
              "                }, " + 
              "                {" + 
              "                    \"message-type\": \"SI\", " + 
              "                    \"unit-price\": 0.7" + 
              "                }" + 
              "            ]" + 
              "        }, " + 
              "        {" + 
              "            \"super-to-sub\": true, " + 
              "            \"price\": 37.0, " + 
              "            \"message-types\": [" + 
              "                {" + 
              "                    \"message-type\": \"N\", " + 
              "                    \"unit-price\": 1.2" + 
              "                }, " + 
              "                {" + 
              "                    \"message-type\": \"SI\", " + 
              "                    \"unit-price\": 0.8" + 
              "                }" + 
              "            ]" + 
              "        }" + 
              "    ]" + 
              "}";

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

            if (conn.getResponseCode() != 200) {
                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:
{"result":"OK"}
Copy code
<?php

$payload = '{' . 
  '    "purchases": [' . 
  '        {' . 
  '            "super-to-sub": true, ' . 
  '            "price": 25.0, ' . 
  '            "message-types": [' . 
  '                {' . 
  '                    "message-type": "N", ' . 
  '                    "unit-price": 1.1' . 
  '                }, ' . 
  '                {' . 
  '                    "message-type": \"L\", ' . 
  '                    "unit-price": 0.7' . 
  '                }' . 
  '            ]' . 
  '        }, ' . 
  '        {' . 
  '            "super-to-sub": true, ' . 
  '            "price": 37.0, ' . 
  '            "message-types": [' . 
  '                {' . 
  '                    "message-type": "N", ' . 
  '                    "unit-price": 1.2' . 
  '                }, ' . 
  '                {' . 
  '                    "message-type": \"L\", ' . 
  '                    "unit-price": 0.8' . 
  '                }' . 
  '            ]' . 
  '        }' . 
  '    ]' . 
  '}';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase');
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'] != 200) {
    echo('Error!');
}
else {
    echo('Success!');
}
?>
On success, the above command returns the following response:
{"result":"OK"}
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 = """{
    "purchases": [
        {
            "super-to-sub": true, 
            "price": 25.0, 
            "message-types": [
                {
                    "message-type": "N", 
                    "unit-price": 1.1
                }, 
                {
                    "message-type": \"L\", 
                    "unit-price": 0.7
                }
            ]
        }, 
        {
            "super-to-sub": true, 
            "price": 37.0, 
            "message-types": [
                {
                    "message-type": "N", 
                    "unit-price": 1.2
                }, 
                {
                    "message-type": \"L\", 
                    "unit-price": 0.8
                }
            ]
        }
    ]
}"""

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

if r.status_code != 200:
    print("An error occurred, return code is: " + str(r.status_code))
else:
    print('Success!')
On success, the above command returns the following response:
{"result":"OK"}
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/subaccount/{subaccount_id}/purchase',
    method: 'POST',
    headers: { 'user_key' : '{USER_KEY}', 'Session_key' : '{SESSION_KEY}' },

    json: true,
    body:     {
        "purchases": [
            {
                "super-to-sub": true, 
                "price": 25.0, 
                "message-types": [
                    {
                        "message-type": "N", 
                        "unit-price": 1.1
                    }, 
                    {
                        "message-type": \"L\", 
                        "unit-price": 0.7
                    }
                ]
            }, 
            {
                "super-to-sub": true, 
                "price": 37.0, 
                "message-types": [
                    {
                        "message-type": "N", 
                        "unit-price": 1.2
                    }, 
                    {
                        "message-type": \"L\", 
                        "unit-price": 0.8
                    }
                ]
            }
        ]
    },

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

uri = URI.parse("https://app.gateway.smsend.it/API/v1.0/REST/subaccount/{subaccount_id}/purchase")
payload =     {
        "purchases": [
            {
                "super-to-sub": true, 
                "price": 25.0, 
                "message-types": [
                    {
                        "message-type": "N", 
                        "unit-price": 1.1
                    }, 
                    {
                        "message-type": \"L\", 
                        "unit-price": 0.7
                    }
                ]
            }, 
            {
                "super-to-sub": true, 
                "price": 37.0, 
                "message-types": [
                    {
                        "message-type": "N", 
                        "unit-price": 1.2
                    }, 
                    {
                        "message-type": \"L\", 
                        "unit-price": 0.8
                    }
                ]
            }
        ]
    }

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

request = Net::HTTP::Post.new(uri.request_uri)
request['Content-type'] = 'application/json'
request['user_key'] = '{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.."
end
On success, the above command returns the following response:
{"result":"OK"}
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 = "{" + 
                  "    \"purchases\": [" + 
                  "        {" + 
                  "            \"super-to-sub\": true, " + 
                  "            \"price\": 25.0, " + 
                  "            \"message-types\": [" + 
                  "                {" + 
                  "                    \"message-type\": \"N\", " + 
                  "                    \"unit-price\": 1.1" + 
                  "                }, " + 
                  "                {" + 
                  "                    \"message-type\": \"SI\", " + 
                  "                    \"unit-price\": 0.7" + 
                  "                }" + 
                  "            ]" + 
                  "        }, " + 
                  "        {" + 
                  "            \"super-to-sub\": true, " + 
                  "            \"price\": 37.0, " + 
                  "            \"message-types\": [" + 
                  "                {" + 
                  "                    \"message-type\": \"N\", " + 
                  "                    \"unit-price\": 1.2" + 
                  "                }, " + 
                  "                {" + 
                  "                    \"message-type\": \"SI\", " + 
                  "                    \"unit-price\": 0.8" + 
                  "                }" + 
                  "            ]" + 
                  "        }" + 
                  "    ]" + 
                  "}";

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

        }
    }
}
On success, the above command returns the following response:
{"result":"OK"}
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/subaccount/{subaccount_id}/purchase";

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

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

# IMPORTANT: Not adding the ':' before 'user_key' and
# 'Session_key' will result in perl to automatically rewrite the
# headers as 'User-Key' and 'Session-Key', which is not supported
# by our API.
$req->header(':user_key' => $auth->[0],
             ':Session_key' => $auth->[1]);
my $payload = {
    "purchases" => [
        {
            "super-to-sub" => true, 
            "price" => 25.0, 
            "message-types" => [
                {
                    "message-type" => "N", 
                    "unit-price" => 1.1
                }, 
                {
                    "message-type" => \"L\", 
                    "unit-price" => 0.7
                }
            ]
        }, 
        {
            "super-to-sub" => true, 
            "price" => 37.0, 
            "message-types" => [
                {
                    "message-type" => "N", 
                    "unit-price" => 1.2
                }, 
                {
                    "message-type" => \"L\", 
                    "unit-price" => 0.8
                }
            ]
        }
    ]
};

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

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