NAV

Direct Mobile Message(Last Updated : 02/04/2021)

Send a message via mobile message (SMS/LMS/MMS).

Methods

PUT /rest/v1/{user_name}/mobilemessage
GET /rest/v1/{user_name}/mobilemessage/{task_id}

PUT Direct Mobile Message

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


Most countries are supported for SMS, but only the US is supported for MMS/LMS. If you attempt to send MMS/LMS to other countries, you will receive an error message.

Resource Information

Response Formats JSON
Allowed Methods PUT
URL http://api.trumpia.com/rest/v1/{user_name}/mobilemessage
{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
country_code Country code of the mobile number. If left blank then it will be assumed to be a U.S. number. If the country_code value is 0, the mobile_number value will be used to infer the country code. Must contain only numeric characters.

Default value: 1
mobile_number * For U.S., the 10-digit number without the leading 0 or 1. For some international numbers, the leading 0 or 1 also must be omitted. No symbols or spaces.

Example value: 7774443210

If the country_code value is 0, the mobile_number value will be used to infer the country code. To ensure that the system accepts the mobile number you enter, the mobile number needs to be formatted in the E.164 standard. This means that a “+” needs to be in front of the full mobile number of the recipient. If the “+” is not listed before the number, the system will reject your request.

Example value: +17774443210
message * SMS/LMS/MMS message.
See Message Object table below. Either text or media is required.
sender Determine which number should be used to send the message. You can specify either your short or long code or a registered landline number.

Default value: The account's short or long code
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.

> Message Object

* required parameters
Parameter Description
text The text of the message you wish to send.

Supported Character Set

Character limits vary per country. The maximum length for a message in the US and Canada is 140 bytes.

Any message that contains more than the maximum number of characters allowed will be converted to a concatenated message. Concatenated messages are limited to 980 characters.

Also, please note that the mobile message header and footer are counted as part of the message and should be taken into consideration when composing a message.
media Resource URL required. The image size limit is 500 KB. Supported image file types include .JPG, .PNG, .GIF (non-animated), .BMP. Video size limit is 3 MB. Supported video file types include .AVI, .MP4, .WMV, and .MOV. Supported audio and video codecs
subject MMS subject line; character limit is 50 bytes. Supported Character Set

Code sample for PUT Direct Mobile Message

"Request Example (SMS case):

PUT http://api.trumpia.com/rest/v1/{user_name}/mobilemessage"

{
  "sender" : "76000",
  "country_code" : 1,
  "mobile_number" : "2003004000",
  "message" :
  {
    "text" : "Hello and thank you for submitting your information."
  },
  "org_name_id" : 12345
}

"Request Example (LMS case):

PUT http://api.trumpia.com/rest/v1/{user_name}/mobilemessage"

{
  "sender" : "76000",
  "country_code" : 1,
  "mobile_number" : "2003004000",
  "message" :
  {
    "text" : "Thank you for submitting your information. You will be receiving an email with instructions for your next steps. Please review the email and feel free to reach out to us if you have any questions."
  },
  "org_name_id" : 12345
}

"Request Example (MMS case):

PUT http://api.trumpia.com/rest/v1/{user_name}/mobilemessage"

{
  "sender" : "76000",
  "country_code" : 1,
  "mobile_number" : "2003004000",
  "message" :
  {
    "text" : "Hello and thank you for submitting your information.",
    "media" : "http://aaa.com/xxx.jpg" ,
    "subject" : "API!!!"
  },
  "org_name_id" : 12345
}



"Response Example:"

{
  "request_id" : "1234561234567asdf123",
  "task_id" : 987987987987,
  "status_code": "MPCE4001"
}


<?
//PUT Mobile Message - Send a SMS/MMS/LMS message
include "request_rest.php";

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

//SMS
$request_data = array(
    "mobile_number" => "2003004000",
    "message" => array(
                "text" => "The quick brown fox jumps over the lazy dog!"
        )
);

$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
    echo "response : " . $json_response_data;
} else {
    echo $response_status ." - connection failure";
}
?>







<?
//PUT Mobile Message - Send a SMS/MMS/LMS message
include "request_rest.php";

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

//MMS
$request_data = array(
    "mobile_number" => "2003004000",
    "message" => array(
                "text" => "The quick brown fox jumps over the lazy dog!",
                "media" => "http://{your-media}",
                "subject" => "Test message"
        )
);

$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
    echo "response : " . $json_response_data;
} else {
    echo $response_status ." - connection failure";
}
?>


// PUT Mobile Message
<%@ 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>MobileMessagePut Sample Code</title>
<body>

<%
    String username = "username";
    String mobileNumber = "2003004000";
    //SMS
    JSONObject message = new JSONObject();
    message.put("text", "The quick brown fox jumps over the lazy dog!");

    JSONObject mobileMessagePut = new JSONObject();
    mobileMessagePut.put("mobile_number", mobileNumber);
    mobileMessagePut.put("message", message);


    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/mobilemessage";
    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(mobileMessagePut.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 Mobile Message
<%@ 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>MobileMessagePut Sample Code</title>
<body>

<%
    String mobileNumber = "2003004000";
    //MMS
    JSONObject message = new JSONObject();
    message.put("text" : "The quick brown fox jumps over the lazy dog!");
    message.put("media" : "http://{your-media}");
    message.put("subject", "Test Message");

    JSONObject mobileMessagePut = new JSONObject();
    mobileMessagePut.put("mobile_number", mobileNumber);
    mobileMessagePut.put("message", message);


    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/mobilemessage";
    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(mobileMessagePut.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 MobileMessage - Send a SMS/MMS/LMS message
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
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
{
    //SMS
    class MobileMessageInfo
    {
        public string mobile_number { get; set; }
        public JObject message { get; set; }
    }
    class Result
    {
        public string request_id { get; set; }
        public long task_id { get; set; }
        public string status_code { get; set; }
    }
    class MobileMessagePut
    {
        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
                JObject messageObject = new JObject();
                messageObject.Add("text", "The quick brown fox jumps over the lazy dog!");

                var info = new MobileMessageInfo() { mobile_number = "2003004000", message = messageObject };
                Uri putUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/mobilemessage", username));
                var response = client.PutAsJsonAsync(putUrl, info).Result;
                if (response.IsSuccessStatusCode)
                {
                    var p = response.Content.ReadAsAsync<Result>().Result;
                    string json = JsonConvert.SerializeObject(p);
                    Console.WriteLine(json);
                }
            }
        }
    }
}







// PUT MobileMessage - Send a SMS/MMS/LMS message
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
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
{
    //MMS
    class MobileMessageInfo
    {
        public string mobile_number { get; set; }
        public JObject message { get; set; }
    }
    class Result
    {
        public string request_id { get; set; }
        public long task_id { get; set; }
        public string status_code { get; set; }
    }
    class MobileMessagePut
    {
        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
                JObject messageObject = new JObject();
                messageObject.Add("text", "The quick brown fox jumps over the lazy dog!");
                messageObject.Add("media", "http://{your-media}");
                messageObject.Add("subject", "Test Message");

                var info = new MobileMessageInfo() { mobile_number = "2003004000", message = messageObject };
                Uri putUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/mobilemessage", username));
                var response = client.PutAsJsonAsync(putUrl, info).Result;
                if (response.IsSuccessStatusCode)
                {
                    var p = response.Content.ReadAsAsync<Result>().Result;
                    string json = JsonConvert.SerializeObject(p);
                    Console.WriteLine(json);
                }
            }
        }
    }
}

GET Direct Mobile Message

Retrieve statistics of a successfully processed message.

Resource Information

Response Formats JSON
Allowed Methods GET
URL http://api.trumpia.com/rest/v1/{user_name}/mobilemessage/{task_id}
{user_name} Your account username (this can be found in the Account Settings page after logging in.)
{task_id} The task 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 Mobile Message

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

"Response Example (SMS Case):"
{
  "task_id": 987987987987,
  "used_credit":
  {
    "domestic": 1,
    "international": 0
  },
  "sms":
  {
    "total": 1,
    "failed": 0,
    "sent": 1
  },
  "status": "sent"
}


"Response Example (LMS/MMS Case):"
{
  "task_id": 987987987987,
  "used_credit":
  {
    "domestic": 3,
    "international": 0
  },
  "mms":
  {
    "total": 1,
    "failed": 0,
    "sent": 1
  },
  "status": "sent"
}


<?
    // GET Mobile Message - Retrieve the statistics of a message.
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/mobilemessage";
    $task_id = "987987987987";
    $request_url =  $request_url . "/" . $task_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 Mobile Message - Retrieve the statistics of a message.
<%@ 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>Mobile Message Get Sample Code</title>
<body>

<%
    String username = "username";
    String taskId = "987987987987";
    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/mobilemessage/" + taskId;

    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 Message - Retrieve the statistics of a message.
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
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 MobileMessageInfo
    {
        public string request_id { get; set; }
        public long task_id { get; set; }
        public string status_code { get; set; }
    }
    class  MobileMessageDetailGet
    {
        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 messageId = "987987987987";

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