NAV

Message(Last Updated : 01/04/2017)

Send a message via supported communication channels, including mobile-text message (SMS/MMS), or email.

Methods

PUT /rest/v1/{user_name}/message
GET /rest/v1/{user_name}/message/{message_id}
GET /rest/v1/{user_name}/message/scheduled
DELETE /rest/v1/{user_name}/message/scheduled/{message_id}

PUT Message

To send a message, you will need to provide the ID of the subscription or distribution list(s) you wish to message.

Resource Information

Response Formats JSON
Allowed Methods PUT
URL http://api.trumpia.com/rest/v1/{user_name}/message
{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
description * Description of your message for your reference.
email See Email Object table below.
sms/mms Send an SMS or MMS by changing this parameter. See SMS or MMS Object table below.
org_name_id The organization name ID you wish to include in the mobile message. Only registered organization name IDs can be used. You can get the registered organization name IDs via GET Organization Name. The default organization name is used if this parameter is not specified.
recipients * See Recipients Object table below.
mail_merge Mail merge is the replacement value for null data if the content contains mail merge variables, such as first name and last name. See Mail Merge Object table below.
send_date Date format: YYYY-MM-DD hh:mm:ss (ex: 2009-04-22 14:10:32)
Value Description
YYYY four-digit year
MM two-digit month (01=January, etc.)
DD two-digit day of month (01 through 31)
hh two digit hours (00 through 23; am/pm NOT allowed)
mm two digit minutes (00 through 59)
ss two digit seconds (00 through 59)

> Email Object

* required parameters
Parameter Description
subject * Email subject.
body * Email content.

You can add first name, last name, and custom data fields as mail merge data. This will automatically populate a placeholder text in the message that will be replaced with data from the subscriber. Also, you can have up to ten mail merge data fields, and format them as specified below.
Data Input Value
First Name [$FirstName]
Last Name [$LastName]
Custom Data Field You can get this value via GET Custom Data Field. You can add value of "mail_merge_text". Ex) [$CustomData-HIGH_SCHOOL]
If you do not enter the mail merge data in the correct format, our system will process it as regular text. As a result, you may get a status code referencing unsupported characters due to '[', ']'.

When you use mail merge in your message, the system will calculate the character limit with the maximum length specified in each mail merge field. This is specified below.
Data Calculated Max Character Count
First Name 30 characters
Last Name 30 characters
Custom Data Field - Text Field You can get the maximum character count via the GET Custom Data Field function. The max length will be returned in the "max_length" parameter.
Custom Data Field - Radio Button The maximum character count will be decided by the longest value in the set. Ex) "values" : ["Giraffe", "Dog", "Cat"]. This means the character count is seven.
Custom Data Field - Drop Down List The maximum character count will be decided by the longest value in the set. Ex) "values" : ["Giraffe", "Dog", "Cat"]. This means the character count is seven.
Custom Data Field - Date & Time Date: 10 characters
Date & Time: 20 characters
Custom Data Field - Number You can get the maximum character count via the GET Custom Data Field function. The max length will be returned in the "max" parameter. The max value will be the digit count of the max value. Ex) "max" : 100. This means the character count is three.
Custom Data Field - Text Area You cannot use this custom data field in your message, as the maximum character count is too large (4,000).
reply_to Use a different reply to email address. The default email address will be used if parameter is null.
shareable The shareable parameter allows you to add a "Share on Social Sites" link in the footer of the email. By default, this will be set to true, which means this link will be added to the footer. Please note that this is a Boolean type.
forwardable The forwardable parameter allows you to add a "Forward Email" link in the footer of the email. By default, this will be set to true, which means this link will be added to the footer. Please note that this is a Boolean type.

> SMS Object

* required parameters
Parameter Description
message * SMS message. Supported Character Set.

Character limits vary per country. The maximum length for a message is 160 characters as default. For instance, SMS messages for Canadian accounts are limited to 140 characters. Although a 160 character message can be sent in full to US mobile numbers, Canadian mobile devices will only receive 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.

You can add first name, last name, and custom data fields as mail merge data. This will automatically populate a placeholder text in the message that will be replaced with data from the subscriber. Also, you can have up to ten mail merge data fields, and format them as specified below.
Data Input Value
First Name [$FirstName]
Last Name [$LastName]
Custom Data Field You can get this value via GET Custom Data Field. You can add value of "mail_merge_text". Ex) [$CustomData-HIGH_SCHOOL]
If you do not enter the mail merge data in the correct format, our system will process it as regular text. As a result, you may get a status code referencing unsupported characters due to '[', ']'.

When you use mail merge in your message, the system will calculate the character limit with the maximum length specified in each mail merge field. This is specified below.
Data Calculated Max Character Count
First Name 30 characters
Last Name 30 characters
Custom Data Field - Text Field You can get the maximum character count via the GET Custom Data Field function. The max length will be returned in the "max_length" parameter.
Custom Data Field - Radio Button The maximum character count will be decided by the longest value in the set. Ex) "values" : ["Giraffe", "Dog", "Cat"]. This means the character count is seven.
Custom Data Field - Drop Down List The maximum character count will be decided by the longest value in the set. Ex) "values" : ["Giraffe", "Dog", "Cat"]. This means the character count is seven.
Custom Data Field - Date & Time Date: 10 characters
Date & Time: 20 characters
Custom Data Field - Number You can get the maximum character count via the GET Custom Data Field function. The max length will be returned in the "max" parameter. The max value will be the digit count of the max value. Ex) "max" : 100. This means the character count is three.
Custom Data Field - Text Area You cannot use this custom data field in your message, as the maximum character count is too large (4,000).

> MMS Object

* required parameters
Parameter Description
subject MMS subject line; character limit is 50 bytes. Supported Character Set.
message * MMS message; character limit is 500 bytes. Supported Character Set.

You can add first name, last name, and custom data fields as mail merge data. This will automatically populate a placeholder text in the message that will be replaced with data from the subscriber. Also, you can have up to ten mail merge data fields, and format them as specified below. specified below.
Data Input Value
First Name [$FirstName]
Last Name [$LastName]
Custom Data Field You can get this value via GET Custom Data Field. You can add value of "mail_merge_text". Ex) [$CustomData-HIGH_SCHOOL]
If you do not enter the mail merge data in the correct format, our system will process it as regular text. As a result, you may get a status code referencing unsupported characters due to '[', ']'.

When you use mail merge in your message, the system will calculate the character limit with the maximum length specified in each mail merge field. This is specified below.
Data Calculated Max Character Count
First Name 30 characters
Last Name 30 characters
Custom Data Field - Text Field You can get the maximum character count via the GET Custom Data Field function. The max length will be returned in the "max_length" parameter.
Custom Data Field - Radio Button The maximum character count will be decided by the longest value in the set. Ex) "values" : ["Giraffe", "Dog", "Cat"]. This means the character count is seven.
Custom Data Field - Drop Down List The maximum character count will be decided by the longest value in the set. Ex) "values" : ["Giraffe", "Dog", "Cat"]. This means the character count is seven.
Custom Data Field - Date & Time Date: 10 characters
Date & Time: 20 characters
Custom Data Field - Number You can get the maximum character count via the GET Custom Data Field function. The max length will be returned in the "max" parameter. The max value will be the digit count of the max value. Ex) "max" : 100. This means the character count is three.
Custom Data Field - Text Area You cannot use this custom data field in your message, as the maximum character count is too large (4,000).
resource Resource URL required. 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.

> Recipients Object

* required parameters
Parameter Description
type * Send to one or more subscriptions or lists.

Example value: 'list' or 'subscription'
value * Subscription IDs or List IDs. You can enter up to 100 list IDs or 300 subscription IDs with an API call.

> Mail Merge Object

* required parameters
Parameter Description
first_name If you added first_name in the message content, you can set this as replacement text. When the subscriber's data is null, then this value will be used.
last_name If you added last_name in the message contents, you can set this as replacement text. When the subscriber's data is null, then this value will be used.

Code sample for PUT Message

"Request Example:
PUT http://api.trumpia.com/rest/v1/{user_name}/message"
{
 "description" : "This is a description",
 "email" :
 {
    "subject" : "Hello [$FirstName], REST API is here!",
    "body" : "Contact support for more info."
 },
 "sms" :
 {
    "message" : "Hello [$LastName], REST API is out now!"
 },
 "recipients" :
 {
    "type" : "list",
    "value" : "987987987980, 9879879879801"
 },
 "mail_merge" :
 {
    "first_name" : "Jason",
    "last_name" : "Doe"
 }
}

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


<?
    // PUT Message - Send a message.
    include "request_rest.php";

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

    $request_data = array(
        "description" => "This is a description",
        "email" => array(
            "subject" => "api.trumpia.com REST API",
            "body" => "We look forward to serving you."
        ),
        "sms" => array(
            "message" => "Hello api.trumpia.com API"
        ),
        "recipients" => array(
            "type" => "list",
            "value" => "987987987980"
        )
    );

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


<?
    // PUT Message - Send a message (with MMS).
    include "request_rest.php";

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

    $request_data = array(
        "description" => "This is a description",
        "email" => array(
            "subject" => "api.trumpia.com REST API",
            "body" => "We look forward to serving you."
        ),
        "mms" => array(
            "subject" => "api.trumpia.com REST API",
            "message" => "Hello api.trumpia.com API",
            "resource" => "http://api.trumpia.com/images/main_120424/logo_t2.png"
        ),
        "recipients" => array(
            "type" => "list",
            "value" => "987987987980"
        )
    );

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




// PUT Message - Send 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>Message Put SMS Sample Code</title>
<body>

<%
    String username = "username";

    JSONObject email = new JSONObject();
    email.put("subject", "api.trumpia.com REST API");
    email.put("body", "Hello. We look forward to serving you.");

    JSONObject im = new JSONObject();
    im.put("message", "Hello. This is IM Message.");

    JSONObject sms = new JSONObject();
    sms.put("message", "This is SMS Message.");

    JSONObject recipients = new JSONObject();
    recipients.put("type", "list");
    recipients.put("value", "987987987980");
    //recipients.put("type", "subscription");
    //recipients.put("value", "987987987980");

    JSONObject mailMerge = new JSONObject();
    mailMerge.put("first_name", "Subscriber's First Name");
    mailMerge.put("last_name", "Subscriber's Last Name");

    JSONObject messagePut = new JSONObject();
    messagePut.put("description", "This is description");
    messagePut.put("email", email);
    messagePut.put("im", im);
    messagePut.put("sms", sms);
    messagePut.put("recipients", recipients);
    messagePut.put("mail_merge", mailMerge);
    //messagePut.put("send_date", "2012-04-23 12:00:00");

    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/message";
    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(messagePut.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 Message - Send a message (with MMS).
<%@ 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>Message Put MMS Sample Code</title>
<body>

<%
    String username = "username";

    JSONObject email = new JSONObject();
    email.put("subject", "api.trumpia.com REST API");
    email.put("body", "Hello. We look forward to serving you.");

    JSONObject im = new JSONObject();
    im.put("message", "Hello. This is IM Message.");

    JSONObject mms = new JSONObject();
    mms.put("subject", "MMS SUBJECT");
    mms.put("message", "This is sms Message.");
    mms.put("resource", "http://api.trumpia.com/files.jpg");

    JSONObject recipients = new JSONObject();
    recipients.put("type", "list");
    recipients.put("value", "987987987980");
    //recipients.put("type", "subscription");
    //recipients.put("value", "987987987980");

    JSONObject mailMerge = new JSONObject();
    mailMerge.put("first_name", "Subscriber's First Name");
    mailMerge.put("last_name", "Subscriber's Last Name");

    JSONObject messagePut = new JSONObject();
    messagePut.put("description", "This is description");
    messagePut.put("email", email);
    messagePut.put("im", im);
    messagePut.put("mms", mms);
    messagePut.put("recipients", recipients);
    messagePut.put("mail_merge", mailMerge);
    //messagePut.put("send_date", "2012-04-23 12:00:00");

    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/message";
    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(messagePut.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 Message - Send 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 MessageInfo
    {
        public string description { get; set; }
        public JObject email { get; set; }
        public JObject sms { get; set; }
        public JObject recipients { get; set; }
    }
    class Result
    {
        public string request_id { get; set; }
    }
    class MessagePut
    {
        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 emailData = new JObject();
                emailData.Add("subject", "Hello REST API");
                emailData.Add("body", "We look forward to serving you.");

                JObject smsData = new JObject();
                smsData.Add("message", "Hello REST API");

                JObject recipientData = new JObject();
                recipientData.Add("type", "subscription");
                recipientData.Add("value", "987987987980");

                var info = new MessageInfo() { description = "This is a description", email = emailData, sms = smsData, recipients = recipientData };
                Uri postUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/message", username));
                var response = client.PutAsJsonAsync(postUrl, info).Result;
                if (response.IsSuccessStatusCode)
                {
                    var p = response.Content.ReadAsAsync<Result>().Result;
                    string json = JsonConvert.SerializeObject(p);
                    Console.WriteLine(json);
                }
            }
        }
    }
}

GET Message

Retrieve the statistics of a successfully processed message. This includes the total number of recipients, delivered messages, and failed messages. FYI, requested_data will be added for PUT Message item only. You cannot GET requested_data for created messages in the web service.

Resource Information

Response Formats JSON
Allowed Methods GET
URL http://api.trumpia.com/rest/v1/{user_name}/message/{message_id}
{user_name} Your account username (this can be found in the Account Settings page after logging in.)
{message_id} The details of this message_id that are retrieved.

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 Message

"Request Example (all subscriptions):
GET http://api.trumpia.com/rest/v1/{user_name}/message/{message_id}"

"Response Example: The following examples are for message blasts that include SMS. For blasts that include MMS, the only difference will be that the 'sms' parameter will be called 'mms'."
{
 "status" : "sent",
 "email" : {"total" : 5,"sent" : 2,"failed" : 3},
 "sms" : {"total" : 5,"sent" : 5,"failed" : 0},
 "im" : {"total" : 5,"sent" : 1,"failed" : 4},
 "coupon" :
 [
    {"coupon_code" : "9pao8e98l9s0","subscription" : "6666666"},
    {"coupon_code" : "ap9o8e9979sa","subscription" : "7777777"},
    {"coupon_code" : "a03ui49s83a8","subscription" : "8888888"},
    {"coupon_code" : "afn209z7va2f","subscription" : "9999999"},
    {"coupon_code" : "ginz921x3482","subscription" : "0000000"}
 ],
 "used_credit" :
 {
    "domestic" : 100,
    "international" : 20
 }
}


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

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/message";
    $message_id = "987987987987";
    $request_url =  $request_url . "/" . $message_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 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>Message Get Sample Code</title>
<body>

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

    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 MessageInfo
    {
        public string status { get; set; }
        public JObject email { get; set; }
        public JObject sms { get; set; }
    }
    class MessageDetailGet
    {
        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}/message/{1}", username, messageId));
                if (response.IsSuccessStatusCode)
                {
                    MessageInfo messageInfo = await response.Content.ReadAsAsync<MessageInfo>();
                    string json = JsonConvert.SerializeObject(messageInfo);
                    Console.WriteLine(json);
                }
            }
        }
    }
}

GET Message (Scheduled)

Retrieve all scheduled messages.

Resource Information

Response Formats JSON
Allowed Methods GET
URL http://api.trumpia.com/rest/v1/{user_name}/message/scheduled
{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

Query String

You can retrieve scheduled messages. You can get a partial set of messages using the offset and limit parameters.

* required parameters
Parameter Description
order The order is the chronological order in which messages are retrieved.
Value Description
scheduled_at Ascending order.
-scheduled_at Descending order.
Default: scheduled_at
offset This is the offset for the list. The value specified here will be the number of messages skipped in the retrieval. The entered value can only be a non-negative number. For example, if you enter 'offset=100’, only the 101st message and onwards will be retrieved.

Default: 0
limit The limit is the number of items in the response. The entered value can only be a numeric value between 1 and 1000. For example, if you enter 'offset=100&limit=200', then you will receive the 101st to 300th scheduled messages.

Default: 50

Code sample for GET Message (Scheduled)

"Request Example
GET http://api.trumpia.com/rest/v1/{user_name}/message/scheduled?offset=100&limit=2&order=scheduled"

"Response Example:"
{
  "total_count" : 12345,
  "messages" :
  [
    {
      "message_id":987987987980,
      "description" : "This is a description",
      "scheduled_at":"2016-07-20T12:34:56Z",
      "sms":4,
      "email":500
    },
    {
      "message_id":987987987981,
      "description" : "This is a description",
      "scheduled_at":"2016-07-15T12:34:56Z",
      "mms":4,
      "email":500
    }
  ]
}


<?
    // GET Message(Scheduled) - Lookup one or multiple scheduled messages.
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/message/scheduled?";
    $offset = "10";
    $limit = "30";
    $order = "scheduled_at";
    $request_url =  $request_url . "offset=" . $offset . "&limit=" . $limit . "&order=" . $order;

    $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 Message(Scheduled) - Lookup one or multiple scheduled messages.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ 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>GET Scheduled Messages Sample Code</title>
<body>

<%
    String username = "username";
    String offset = "10";
    String limit = "30";
    String order = "scheduled_at";
    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/message/scheduled?offset=" +offset+ "&limit=" +limit+ "&order=" + order;
    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(Scheduled) - Lookup one or multiple scheduled messages.
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 ScheduledMessageInfo
    {
        public String total_id_count { get; set; }
        public JArray message_id_list { get; set; }
    }

    class ScheduledMessageGet
    {
        static void Main(string[] args)
        {
            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 offset = "10";
                var limit = "30";
                var order = "scheduled_at";
                //GET
                HttpResponseMessage response = await client.GetAsync(string.Format("/rest/v1/{0}/message/scheduled?offset={1}&limit={2}&order={3}", username, offset, limit, order));
                if (response.IsSuccessStatusCode)
                {
                    ScheduledMessageInfo messageList = await response.Content.ReadAsAsync<ScheduledMessageInfo>();
                    string json = JsonConvert.SerializeObject(messageList);
                    Console.WriteLine(json);
                }
            }
        }
    }
}

DELETE Message

Cancel a scheduled messages.

Resource Information

Response Formats JSON
Allowed Methods DELETE
URL http://api.trumpia.com/rest/v1/{user_name}/message/{message_id}
{user_name} Your account username (this can be found in the Account Settings page after logging in.)
{message_id} The message_id of the message that will be cancelled.

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 DELETE Message.

"Request Example:
GET http://api.trumpia.com/rest/v1/{user_name}/message/scheduled/{message_id}"
{
   "request_id" : "T151111522645dsfwesedf",
   "message_id" : 987987987987,
   "status_code" : "MPCE4001"
}


<?
    // DELETE Message - Cancel a scheduled message.
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/message/scheduled";
    $message_id = "987987987980";
    $request_url =  $request_url . "/" . $message_id;

    $request_rest = new RestRequest();

    $request_rest->setRequestURL($request_url);
    $request_rest->setAPIKey("{api_key}");
    $request_rest->setMethod("DELETE");
    $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";
    }
?>


// DELETE Message - Cancel a scheduled message.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ 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>Scheduled Message Delete Sample Code</title>
<body>

<%
    String username = "username";
    String messageID = "987987987980";
    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/message/scheduled/" + messageID;
    URL url = new URL(urlStr);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("DELETE");
    conn.setDoOutput(true);
    conn.setAllowUserInteraction(false);
    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>


// DELETE Message - Cancel a scheduled message.
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 Result
    {
        public string request_id { get; set; }
        public string message_id { get; set; }
        public string status_code { get; set; }
    }
    class ScheduledMessageDelete
    {
        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";
                var messageID = "987987987980";
                //DELETE
                Uri deleteUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/message/scheduled/{1}", username, messageID));
                var response = client.DeleteAsync(deleteUrl).Result;
                if (response.IsSuccessStatusCode)
                {
                    var p = response.Content.ReadAsAsync<Result>().Result;
                    string json = JsonConvert.SerializeObject(p);
                    Console.WriteLine(json);
                }
            }
        }
    }
}