NAV

Direct SMS(Last Updated : 01/04/2017)

Send a message via mobile text message (SMS).

Methods

PUT /rest/v1/{user_name}/sms
GET /rest/v1/{user_name}/sms/{sms_id}

PUT Direct SMS

Send a message to a user by providing only the mobile number and message. Compared to PUT Message, REST SMS does not require the subscription to be added into the database. This function is great for one-off messages and notifications.

Resource Information

Response Formats JSON
Allowed Methods PUT
URL http://api.trumpia.com/rest/v1/{user_name}/sms
{user_name} Your account username (this can be found in the Account Settings page after logging in.)

Header Parameters

* required parameters
Parameter Description
Content-Type * application/json
X-Apikey * Your API key (This can be found in the API Settings page after logging in.)

Example value: 123456789abc1011

Body Parameters

* required parameters
Parameter Description
mobile_number * Mobile number of the recipient. Must contain only numeric characters and no country code.
country_code Country code of the mobile number. Must contain only numeric characters.

Default value: 1
message * The message you wish to send.

Supported Character Set

Character limits vary per country. The maximum length for a message is 160 characters by default. For instance, SMS messages for Canadian accounts are limited to 140 characters. Although a 160-character message can be sent in full to U.S. mobile numbers, Canadian mobile devices will receive only the first 140 characters.

Also, please note that the SMS header and footer are counted as part of the message and should be taken into consideration when composing a message.
sender The sender's short code or registered landline number. You can register a landline number via the webpage. Must contain only numeric characters.

Default sender value is assigned to your account. Locate this code by going to Account Settings.
org_name_id The ID of the organization name you wish to include in the message. Only registered organization names can be used. You can get the IDs of registered organization names via GET Organization Name. If this parameter is not specified, the default organization name will be used.

The organization name will be added automatically if you use a short code as the sender. But if you use a registered landline as the sender, the organization name will be not added. In this case, any org_name_id submitted in the request will be ignored.

Code sample for PUT Direct SMS

"Request Example:(via account’s short code case):
PUT http://api.trumpia.com/rest/v1/{user_name}/sms"
{
 "mobile_number" : "2003004000",
 "message" : "Hello, REST API is here!",
 "org_name_id" : "987987987980"
}

"Request Example (via registered landline case)
PUT http://api.trumpia.com/rest/v1/{user_name}/sms"
{
 "mobile_number" : "2003004000",
 "message" : "Hello, REST API is here!",
 "sender" : "7778889999"
}

"Response Example:"
{
 "request_id" : "1234561234567asdf123",
 "sms_id" : 987987987987
}


<?
    //PUT Direct SMS
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/sms";

    $request_data = array(
                                "mobile_number" => "2003004000",
                                "message" => "Hello, REST API is here!",
                                "country_code" => 1,
                                "sender" => "7778889999"
                            );

        $request_rest = new RestRequest();

        $request_rest->setRequestURL($request_url);
        $request_rest->setAPIKey("{api_key}");
        $request_rest->setRequestBody(json_encode($request_data));
        $request_rest->setMethod("PUT");
        $result = $request_rest->execute();

        $response_status = $result[0];
        $json_response_data = $result[1];

        if ($response_status == "200") {    //success
            $response_data = json_decode($json_response_data);
            echo "request_id : " . $response_data->request_id . "<br>";
            echo "sms_id : " . $response_data->sms_id;
        } else {
            echo $response_status ." - connection failure";
        }
?>


// PUT Direct SMS
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.json.simple.JSONArray" %>
<%@ page import="org.json.simple.JSONObject" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="java.io.OutputStreamWriter" %>
<%@ page import="java.io.Writer" %>
<%@ page import="java.net.HttpURLConnection" %>
<%@ page import="java.net.URL" %>
<html>
<title>SmsPut Sample Code</title>
<body>

<%
    String mobileNumber = "2003004000";
    String message = "Hello, REST API is here!";
    int countryCode = 1;
    String sender = "7778889999";

    JSONObject smsPut = new JSONObject();
    smsPut.put("mobile_number", mobileNumber);
    smsPut.put("message", message);
    smsPut.put("countryCode", countryCode);
    smsPut.put("sender", sender);

    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/sms";
    URL url = new URL(urlStr);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("PUT");
    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.setUseCaches(false);
    conn.setAllowUserInteraction(false);
    conn.setRequestProperty("Content-type", "application/json");
    conn.setRequestProperty("X-Apikey", "12345aaaaa67890aaaaa");
    OutputStream outPutStream = conn.getOutputStream();
    Writer writer = new OutputStreamWriter(outPutStream, "UTF-8");
    writer.write(smsPut.toJSONString());
    writer.close();
    outPutStream.close();

    if (conn.getResponseCode() != 200) {
%>
    Error : <%=conn.getResponseMessage()%>
<%
    }else{
    // Buffer the result into a string
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = rd.readLine()) != null) {
        sb.append(line);
    }
    rd.close();
    conn.disconnect();
%>
    Response : <%=sb.toString()%>
<%
    }
%>
</body>
</html>


// PUT Direct SMS
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace samplecode
{
    class SmsInfo
    {
        public string mobile_number { get; set; }
        public string message { get; set; }
        public int country_code { get; set; }
        public string sender { get; set; }
    }
    class Result
    {
        public string request_id { get; set; }
        public string sms_id { get; set; }
    }
    class SmsPut
    {
        static void Main()
        {
          RunAsync().Wait();
        }

        static async Task RunAsync()
        {
            using (var client = new HttpClient())
            {
                var apikey = "12345aaaaa67890aaaaa";

                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("X-Apikey", string.Format("{0}", apikey));

                                var username = "username";
                //PUT
                var sms = new SmsInfo() { mobile_number = "2003004000", message = "Hello, REST API is here!", country_code = 1, sender = "7778889999" };
                Uri putUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/sms",username));
                var response = client.PutAsJsonAsync(putUrl, sms).Result;
                if(response.IsSuccessStatusCode) {
                    var p = response.Content.ReadAsAsync<Result>().Result;
                    string json = JsonConvert.SerializeObject(p);
                    Console.WriteLine(json);
                }
            }
        }
    }
}

GET Direct SMS

Retrieve the statistics of a successfully processed message. This includes the amount of total, sent, and failed messages.

Resource Information

Response Formats JSON
Allowed Methods GET
URL http://api.trumpia.com/rest/v1/{user_name}/sms/{sms_id}
{user_name} Your account username (this can be found in the Account Settings page after logging in.)
{sms_id} The SMS ID you wish to get information for.

Header Parameters

* required parameters
Parameter Description
Content-Type * application/json
X-Apikey * Your API key (This can be found in the API Settings page after logging in.)

Example value: 123456789abc1011

Code sample for GET Direct SMS

"Request Example
GET http://api.trumpia.com/rest/v1/{user_name}/sms/{sms_id}"

"Response Example:"
{
 "sms_id" : 987987987987,
 "status" : "sent",
 "sms":
 {
   "total" : 1,
   "sent" : 1,
   "failed" : 0
 }
}


<?
    //GET Direct SMS
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/sms";
    $sms_id = "987987987980";
    $request_url =  $request_url . "/" . $sms_id;

    $request_rest = new RestRequest();

    $request_rest->setRequestURL($request_url);
    $request_rest->setAPIKey("{api_key}");
    $request_rest->setMethod("GET");
    $result = $request_rest->execute();

    $response_status = $result[0];
    $json_response_data = $result[1];

    if ($response_status == "200") {    //success
        echo $json_response_data;
    } else {
        echo $response_status ." - connection failure";
    }
?>


// GET Direct SMS
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.json.simple.JSONArray" %>
<%@ page import="org.json.simple.JSONObject" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="java.io.OutputStreamWriter" %>
<%@ page import="java.io.Writer" %>
<%@ page import="java.net.HttpURLConnection" %>
<%@ page import="java.net.URL" %>
<html>
<title>SmsGetById Sample Code</title>
<body>

<%
    String username = "username";
    String smsId = "987987987980";
    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/sms/" + smsId;

    URL url = new URL(urlStr);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestProperty("Content-type", "application/json");
    conn.setRequestProperty("X-Apikey", "12345aaaaa67890aaaaa");

    if (conn.getResponseCode() != 200) {
%>
    Error : <%=conn.getResponseMessage()%>
<%
    }else{
    // Buffer the result into a string
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = rd.readLine()) != null) {
        sb.append(line);
    }
    rd.close();
    conn.disconnect();
%>
    Response : <%=sb.toString()%>
<%
    }
%>
</body>
</html>


// GET Direct SMS
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace samplecode
{
    class SmsInfo
    {
        public JObject result { get; set; }
    }
    class SmsDetailGet
    {
        static void Main()
        {
           RunAsync().Wait();
        }

        static async Task RunAsync()
        {
            using (var client = new HttpClient())
            {
                var apikey = "12345aaaaa67890aaaaa";

                client.BaseAddress = new Uri("http://api.trumpia.com");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("X-Apikey", string.Format("{0}", apikey));

                                var username = "username";
                var smsId = "987987987980";

                //GET
                HttpResponseMessage response = await client.GetAsync(string.Format("/rest/v1/{0}/sms/{1}", username, smsId));
                if (response.IsSuccessStatusCode)
                {
                    SmsInfo smsInfo = await response.Content.ReadAsAsync<SmsInfo>();
                    string json = JsonConvert.SerializeObject(smsInfo);
                    Console.WriteLine(json);
                }
            }
        }
    }
}