NAV

Subscription(Last Updated : 10/29/2020)

Add subscriptions into distribution lists. Store name, mobile numbers, landline, email addresses, and custom data for each subscription.

Methods

PUT /rest/v1/{user_name}/subscription
GET /rest/v1/{user_name}/subscription
GET /rest/v1/{user_name}/subscription/{subscription_id}
GET /rest/v1/{user_name}/subscription/search
POST /rest/v1/{user_name}/subscription/{subscription_id}
DELETE /rest/v1/{user_name}/subscription/{subscription_id}

PUT Subscription

Create a subscription record for a subscriber. A unique mobile number, landline, or email address is required for a new subscription. This record is required for sending messages to the subscriber and for most API requests.

Resource Information

Response Formats JSON
Allowed Methods PUT
URL http://api.trumpia.com/rest/v1/{user_name}/subscription
{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
list_name * The name of your distribution list that has been previously created. This is the list to which the subscriber will be added.
subscriptions * Subscriptions information must be provided for at least one of the following keys. See Subscription Object table below.

> Subscription Object

* required parameters
Parameter Description
first_name First name of subscription.
last_name Last name of subscription.
voice_device If the subscription needs to be reached out via voice, voice_device has to be specified. If voice_device is not specified, a voice message cannot be sent to the subscription.

Note: Supported countries for voice are US, Canada, Guam and Puerto Rico.

The possible values for voice_device are 'Landline' and 'Mobile' . When you set the voice_device attribute, you must also register the respective landline or mobile information. For example, if you register the mobile number instead of landline and set voice_device to 'Landline', then the voice message cannot be sent.
email Email address of the subscription.
mobile See Mobile Object table below.
landline See Landline Object table below.
customdata Add custom data such as birthday, age, etc. This is created using PUT Custom Data Field. Existing customdata_ids can be found using GET Custom Data Field. See Custom Data Object table below.

>> Mobile Object

* required parameters
Parameter Description
number * Mobile phone number.
country_code Country code of the number.

Default value: 1

>> Landline Object

* required parameters
Parameter Description
number * Landline phone number.
country_code Country code of the number.

Default value: 1

>> Custom Data Object

* required parameters
Parameter Description
customdata_id * Custom data field ID.
value * Custom data value. There are basic, differing restrictions for each type of custom data field.
Field Type Description
Text Field This must contain only alphanumeric characters. You can get max_length via GET Custom Data Field.
Radio Button Enter a fixed value. You can get the fixed value via GET Custom Data Field.
Drop-down List Enter a fixed value. You can get the fixed value via GET Custom Data Field.
Date & Time Enter the value with this format:
  - Date only Case : YYYY-MM-DD
  - Date & Time Case : YYYY-MM-DD hh:mm:ss
Text Area This must contain only alphanumeric characters. Max_length is 4000 characters.
Number This must contain only numeric characters. You can get min and max value via GET Custom Data Field.

Code sample for PUT Subscription

"Request Example:
PUT http://api.trumpia.com/rest/v1/{user_name}/subscription"
{
  "list_name" : "listname0001,listname0002,listname0003",
  "subscriptions" :
  [
    {
      "first_name" : "Subscriber's First Name",
      "last_name" : "Subscriber's Last Name",
      "email" : "subscriber_email0001@api.trumpia.com",
      "mobile" :
      {
        "number" : "2003004000",
        "country_code" : "1"
      },
      "voice_device" : "mobile",
      "customdata" :
      [
        {
          "customdata_id" : 987987987987,
          "value" : "Apple"
        },
        {
          "customdata_id" : 987987987980,
          "value" : "2014-10-10 00:00:01"
        }
      ]
    },
    {
      "first_name" : "Subscriber's First Name02",
      "email" : "subscriber_email0002@api.trumpia.com",
      "landline" :
      {
        "number" : "3004005000",
        "country_code" : "1"
      },
      "voice_device" : "landline"
    }
  ]
}

"Example response:"
{
  "request_id" : "1234561234567asdf123"
}


<?
    // PUT Subscription - Create one or multiple subscriptions.
    include "request_rest.php";

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

    $request_data = array(
        "list_name" => "listname0001",
        "subscriptions" => array(
            array(
                "first_name" => "Subscriber's First Name",
                "last_name" => "Subscriber's Last Name",
                "email" => "subscriber_email0001@trumpia.com",
                "aim" => "aimname",
                "mobile" => array("number" => "2003004000", "country_code" => "1"),
                "landline" => array("number" => "3004005000", "country_code" => "1"),
                "voice_device" => "mobile",
                "customdata" => array(
                    array(
                        "customdata_id" => "987987987989",
                        "value" => "Customdata value",
                    )
                )
            ),
            array(
                "first_name" => "Subscriber's First Name02",
                "last_name" => "Subscriber's Last Name02",
                "email" => "subscriber_email0002@trumpia.com",
                "aim" => "aimname02",
                "mobile" => array("number"=>"2003004001", "country_code" => "1"),
                "landline" => array("number"=>"3004005001", "country_code" => "1"),
                "voice_device" => "landline"
            )
        )
    );

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


// PUT Subscription - Create one or multiple subscriptions.
<%@ 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>Subscription Put Sample Code</title>
<body>

<%
    String username = "username";
    JSONObject mobile = new JSONObject();
    mobile.put("number", "2003004000");
    mobile.put("country_code", "1");
    JSONObject landline = new JSONObject();
    landline.put("number", "3004005000");
    landline.put("country_code", "1");
    JSONObject customData = new JSONObject();
    customData.put("customdata_id", "987987987987");
    customData.put("value", "Customdata value");

    JSONArray customDataArray = new JSONArray();
    customDataArray.add(customData);

    JSONArray subscriptions = new JSONArray();
    JSONObject subscription = new JSONObject();
    subscription.put("first_name", "FirstName");
    subscription.put("last_name", "LastName");
    subscription.put("email", "test@email.com");
    subscription.put("aim", "aimname");
    subscription.put("mobile", mobile);
    subscription.put("landline", landline);
    subscription.put("voice_device", "mobile");
    subscription.put("customdata", customDataArray);
    subscriptions.add(subscription);

    JSONObject subscriptionPut = new JSONObject();
    subscriptionPut.put("list_name", "listname0001");
    subscriptionPut.put("subscriptions", subscriptions);

    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/subscription";
    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(subscriptionPut.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 Subscription - Create one or multiple subscriptions.
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 SubscriptionInfo
    {
        public string list_name { get; set; }
        public JArray subscriptions { get; set; }
    }
    class Result
    {
        public string request_id { get; set; }
    }
    class SubscriptionPut
    {
        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 subscription = new JObject();
                subscription.Add("first_name", "Subscriber's First Name");
                subscription.Add("last_name", "Subscriber's Last Name");
                subscription.Add("email", "subscriber_email0001@trumpia.com");
                subscription.Add("aim", "aimname");

                JObject mobile = new JObject();
                mobile.Add("number", "2003004000");
                mobile.Add("country_code", "1");
                subscription.Add("mobile", mobile);

                JObject landline = new JObject();
                landline.Add("number", "3004005000");
                landline.Add("country_code", "1");
                subscription.Add("landline", landline);

                JObject customData = new JObject();
                customData.Add("customdata_id", "987987987989");
                customData.Add("value", "Customdata value");
                JArray customDataArray = new JArray();
                customDataArray.Add(customData);
                subscription.Add("customdata", customDataArray);

                JArray array = new JArray();
                array.Add(subscription);

                var info = new SubscriptionInfo() { list_name = "listname0001", subscriptions = array };
                Uri postUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/subscription", 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 Subscription

Look up basic information, like list IDs and names, of existing distribution lists, or look up detailed information from a specific distribution list.

Resource Information

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

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 a full set or a subset of subscriptions. They will be in descending order by created date. You can also get a partial set of subscribers using the row_size and page parameters.

* required parameters
Parameter Description
row_size The number of subscription ID’s you want to retrieve. Entered value can only be a numeric value between 100 and 10000.

Default value: 100
page You can receive a partial set of subscriptions in descending order by created date.

Default value: 1

Code sample for GET Subscription

"Request Example: (with row_size and page)"
"GET http://api.trumpia.com/rest/v1/{user_name}/subscription?row_size=100&page=3"

"Response Example:"
{
  "subscription_id_list" :
  [
    "987987987980","987987987981","987987987982","987987987988","987987987989"
  ]
}

"Request Example: for a specific subscription"
"GET http://api.trumpia.com/rest/v1/{user_name}/subscription/{subscription_id}"

"Response Example:"
{
  "list_ids" :
  [
    "987987987980", "987987987981", "987987987982", "987987987983"
  ],
  "created_date" : "2012-02-27 18:05:33",
  "landline" :
  {
    "value" : "3004005000",
    "country_code" :1,
    "verified" : "true"
  },
  "email" :
  {
    "value" : "subscriber_email0001@api.trumpia.com",
    "verified" : "true"
  },
  "first_name" : "Subscriber's First Name",
  "customdata" :
  [
    {
      "customdata_id" : 987987987987,
      "name" : "favorite fruit",
      "value" : "Apple"
    },
    {
      "customdata_id" : 987987987980,
      "name" : "birthday",
      "value" : "2014-10-10 00:00:01"
    }
  ]
}


<?
    // GET Subscription - Retrieve all subscription.
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/subscription?";
    $page = 2;
    $row_size = 100;
    $request_url =  $request_url . "page=" . $page . "&row_size=" . $row_size;

    $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 Subscription - Retrieve a subscription by ID.
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/subscription";
    $subscription_id = "987987987980";
    $request_url =  $request_url . "/" . $subscription_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 Subscription - Retrieve all subscription.
<%@ 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>SubscriptionGetAll Sample Code</title>
<body>

<%
    String username = "username";
    int page = 2;
    int rowSize = 100;
    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/subscription?page=" + page + "&row_size=" + rowSize;
    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 Subscription - Retrieve a subscription by ID.
<%@ 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>Subscription Get By Id Sample Code</title>
<body>

<%
    String username = "username";
    String subscriptionID = "987987987980";
    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/subscription/" + subscriptionID;
    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 Subscription - Retrieve all subscription.
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 SubscriptionInfo
    {
        public JArray subscription_id_list { get; set; }
    }
    class SubscriptionGet
    {
        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 page = 2;
                                var rowSize = 100;

                //GET
                HttpResponseMessage response = await client.GetAsync(string.Format("/rest/v1/{0}/subscription?page={1}&row_size={2}", username, page, rowSize));
                if (response.IsSuccessStatusCode)
                {
                    SubscriptionInfo subscriptionList = await response.Content.ReadAsAsync<SubscriptionInfo>();
                    string json = JsonConvert.SerializeObject(subscriptionList);
                    Console.WriteLine(json);
                }
            }
        }
    }
}


// GET Subscription - Retrieve a subscription by ID.
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 SubscriptionInfo
    {
        public string first_name{ get; set; }
        public string last_name { get; set; }
        public string created_date { get; set; }
        public JObject mobile { get; set; }
        public JObject email { get; set; }

    }
    class SubscriptionDetailGet
    {
        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 subscriptionId = "987987987980";

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

GET Subscription (Search)

Search for subscription IDs by various data types, including first or last name, phone number, email address, date the account was created, and more.

Resource Information

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

* required parameters
Parameter Description
row_size The number of subscription ID’s you want to retrieve. Entered value can only be a numeric value between 100 and 10,000.

Default value: 10,000
page Your contact database will be split into “pages”, each containing the number of contacts entered in row_size. The page value will decide how many sets of (row_size) contacts to offset by for the returned values.

Default value: 1
search_type Search for the type of subscription data by setting the search_type (ie. phone number, email, first name, etc.). This will allow you to search for subscriptions that contain data for the specified type.
Value Description
1 Email
2 Mobile
3 Landline
102 Country Code
103 Created Date
104 First Name
105 Last Name
search_data Based on the search_type selected above, you must provide the appropriate data. For example, if you would like to search for a specific subscription ID by email, set search_type=1 and provide that contact's email address for search_data, such as search_data=johndoh@mail.com. If you would like to retrieve all the subscription IDs for which there are data for particular search types, for example all subscriptions with email addresses, set search_data=all. This feature only works for search types 1-4.

For searching by created date (i.e., search_type=103), the search_data must be in the format: YYYY-MM-DD hh:mm:ss~YYYY-MM-DD hh:mm:ss (ex: 2013-03-01 13:00:00~2013-04-01 13:00:00). To search over a date range, use the character "~" between the two dates.
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)
list_id You may limit the search to a specific distribution list.

Code sample for GET Subscription (search)

"The following example includes the parameters and values necessary to search for
the subscription with the email address johndoh@mail.com from the distribution list 12345.

Request Example: (search for one subscription ID by email address):"
"GET http://api.trumpia.com//rest/v1/{user_name}/subscription/search?search_type=1&search_data=johndoh@mail.com&list_id=12345"

"Response Example:"
{
  "subscription_id_list" :
  [
    "987987987980"
  ]
}

"Request Example (search for all subscription ID’s by phone number):

To search your entire database for all the subscriptions that have a landline phone number saved,
 you would submit the following call:"

"GET http://api.trumpia.com//rest/v1/{user_name}/subscription/search?search_type=3&search_data=all"

"Response Example: The subscription ID’s for all the relevant subscriptions will be returned:"
{
  "subscription_id_list" :
  [
    "987987987980","987987987981","987987987982","987987987983","987987987984","987987987985","987987987986","987987987987"
  ]
}


<?
    // GET Search Subscription - Lookup one or multiple subscriptions.
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/subscription/search?";
    $search_type = "1";
    $search_data = "subscriber_email0001@trumpia.com";
    $list_id = "987987987980";
    $request_url =  $request_url . "search_type=" . $search_type . "&search_data=" . $subscription_id . "&list_id=" . $list_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 Search Subscription - Lookup one or multiple subscriptions.
<%@ 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>SubscriptionSearchGet Sample Code</title>
<body>

<%
    String username = "username";
    String searchType = "1";
    String searchData = "subscriber_email0001@trumpia.com";
    String listID = "987987987980";
    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/subscription/search?search_type=" +searchType+ "&search_data=" +searchData+ "&list_id=" + listID;
    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 Search Subscription - Lookup one or multiple subscriptions.
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 SubscriptionInfo
    {
        public JArray subscription_id_list { get; set; }
    }

    class SubscriptionSearchGet
    {
        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 searchType = 1;
                var searchData = "subscriber_email0001@trumpia.com";
                var listId = "16654";
                //GET
                HttpResponseMessage response = await client.GetAsync(string.Format("/rest/v1/{0}/subscription/search?search_type={1}&search_data={2}&list_id={3}", username, searchType, searchData, listId));
                if (response.IsSuccessStatusCode)
                {
                    SubscriptionInfo subscriptionList = await response.Content.ReadAsAsync<SubscriptionInfo>();
                    string json = JsonConvert.SerializeObject(subscriptionList);
                    Console.WriteLine(json);
                }
            }
        }
    }
}

POST Subscription

Update the contact information, such as name, phone number, email address, and distribution list, for an existing subscription.

Resource Information

Response Formats JSON
Allowed Methods POST
URL http://api.trumpia.com/rest/v1/{user_name}/subscription/{subscription_id}
{user_name} Your account username (this can be found in the Account Settings page after logging in.)
{subscription_id} Subscription_id that is being edited.

Example value: 987987987980

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
list_name The name of your distribution list that has been previously created. This is the list to which the subscriber will be added.
subscriptions See Subscription Object table below.

Note: In case you are deleting specific data from a subscription, put "delete" as the value to the desired parameter.

> Subscription Object

* required parameters
Parameter Description
first_name First name of subscription.
last_name Last name of subscription.
email Email address of the subscription.
mobile See Mobile Object table below.
landline See Landline Object table below.
customdata Add custom data such as birthday, age, etc. This is created using PUT Custom Data Field. Existing customdata_ids can be found using GET Custom Data Field. See Custom Data Object table below.

>> Mobile Object

* required parameters
Parameter Description
number Mobile phone number.
country_code Country code of the number.

Default value: 1

>> Landline Object

* required parameters
Parameter Description
number Landline phone number.
country_code Country code of the number.

Default value: 1

>> Custom Data Object

* required parameters
Parameter Description
customdata_id * Custom data field ID.
value * Custom data value. There are basic, differing restrictions for each type of custom data field.
Field Type Description
Text Field This must contain only alphanumeric characters. You can get max_length via GET Custom Data Field.
Radio Button Enter a fixed value. You can get the fixed value via GET Custom Data Field.
Drop-down List Enter a fixed value. You can get the fixed value via GET Custom Data Field.
Date & Time Enter the value with this format:
  - Date only Case : YYYY-MM-DD
  - Date & Time Case : YYYY-MM-DD hh:mm:ss
Text Area This must contain only alphanumeric characters. Max_length is 4000 characters.
Number This must contain only numeric characters. You can get min and max value via GET Custom Data Field.

Code sample for POST Subscription

"Request Example:
POST http://api.trumpia.com/rest/v1/{user_name}/subscription/{subscription_id}"
{
  "list_name" : "listname0001,listname0002,listname0003",
  "subscriptions" :
  [
    {
      "first_name" : "Subscriber's First Name",
      "last_name" : "Subscriber's Last Name",
      "email" : "subscriber_email0001@api.trumpia.com",
      "aim" : "aimname",
      "mobile" :
      {
        "number" : "2003004000",
        "country_code" : "1"
      },
      "customdata" :
      [
        {
          "customdata_id" : 987987987987,
          "value" : "Apple"
        },
        {
          "customdata_id" : 987987987980,
          "value" : "2014-10-10 00:00:01"
        }
      ]
    }
  ]
}

"Response Example:"
{
  "request_id" : "1234561234567asdf123"
}


<?
    // POST Subscription - Update a subscription.
    include "request_rest.php";

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

    $request_data = array(
        "list_name" => "listname0001",
        "subscriptions" => array(
            array(
                "first_name" => "Subscriber's First Name",
                "last_name" => "Subscriber's Last Name",
                "email" => "subscriber_email0001@trumpia.com",
                "aim" => "aimname",
                "mobile" => array("number"=>"2003004000", "country_code" => "1"),
                "landline" => array("number"=>"3004005000", "country_code" => "1"),
                "voice_device" => "mobile",
                "customdata" => array(
                    array(
                        "customdata_id" => "987987987989",
                        "value" => "Customdata value",
                    )
                )
            )
        )
    );

    $request_rest = new RestRequest();

    $request_rest->setRequestURL($request_url);
    $request_rest->setAPIKey("{api_key}");
    $request_rest->setRequestBody(json_encode($request_data));
    $request_rest->setMethod("POST");
    $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;
    } else {
        echo $response_status ." - connection failure";
    }
?>


// POST Subscription - Update a subscription.
<%@ 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>Subscription Post Sample Code</title>
<body>

<%
    String username = "username";
    JSONObject mobile = new JSONObject();
    mobile.put("number", "2003004000");
    mobile.put("country_code", "1");
    JSONObject landline = new JSONObject();
    landline.put("number", "3004005000");
    landline.put("country_code", "1");
    JSONObject customData = new JSONObject();
    customData.put("customdata_id", "987987987987");
    customData.put("value", "Customdata value");

    JSONArray customDataArray = new JSONArray();
    customDataArray.add(customData);

    JSONArray subscriptions = new JSONArray();
    JSONObject subscription = new JSONObject();
    subscription.put("first_name", "FirstName");
    subscription.put("last_name", "LastName");
    subscription.put("email", "test@email.com");
    subscription.put("aim", "aimname");
    subscription.put("mobile", mobile);
    subscription.put("landline", landline);
    subscription.put("voice_device", "mobile");
    subscription.put("customdata", customDataArray);
    subscriptions.add(subscription);

    JSONObject subscriptionPut = new JSONObject();
    subscriptionPut.put("list_name", "listname0001");
    subscriptionPut.put("subscriptions", subscriptions);

    String subscriptionID = "987987987980";
    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/subscription/" + subscriptionID;
    URL url = new URL(urlStr);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    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(subscriptionPut.toJSONString());
    writer.close();
    outPutStream.close();

    if (conn.getResponseCode() != 200) {
%>
    URL : <%=urlStr%>
    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>


// POST Subscription - Update a subscription.
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace samplecode
{
    class SubscriptionInfo
    {
        public string list_name { get; set; }
        public JArray subscriptions { get; set; }
    }
    class Result
    {
        public string request_id { get; set; }
    }
    class SubscriptionPost
    {
        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 subscriptionId = "987987987980";
                //POST
                JObject subscription = new JObject();
                subscription.Add("first_name", "Subscriber's First Name");
                subscription.Add("last_name", "Subscriber's Last Name");
                subscription.Add("email", "subscriber_email0001@trumpia.com");
                subscription.Add("aim", "aimname");

                JObject mobile = new JObject();
                mobile.Add("number", "2003004000");
                mobile.Add("country_code", "1");
                subscription.Add("mobile", mobile);

                JObject landline = new JObject();
                landline.Add("number", "2003005000");
                landline.Add("country_code", "1");
                subscription.Add("landline", landline);

                JObject customData = new JObject();
                customData.Add("customdata_id", "987987987989");
                customData.Add("value", "Customdata value");
                JArray customDataArray = new JArray();
                customDataArray.Add(customData);
                subscription.Add("customdata", customDataArray);

                JArray array = new JArray();
                array.Add(subscription);

                var list = new SubscriptionInfo() { list_name = "listname0001", subscriptions = array };
                Uri postUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/subscription/{1}", username, subscriptionId));
                var response = client.PostAsJsonAsync(postUrl, list).Result;
                if (response.IsSuccessStatusCode)
                {
                    var p = response.Content.ReadAsAsync<Result>().Result;
                    string json = JsonConvert.SerializeObject(p);
                    Console.WriteLine(json);
                }
            }
        }
    }
}

DELETE Subscription

Permanently remove a subscription.

Resource Information

Response Formats JSON
Allowed Methods DELETE
URL http://api.trumpia.com/rest/v1/{user_name}/subscription/{subscription_id}
{user_name} Your account username (this can be found in the Account Settings page after logging in.)
{subscription_id} Subscription_id that is being deleted.

Example value: 987987987980

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 Subscription

"Request Example:
DELETE http://api.trumpia.com/rest/v1/{user_name}/subscription/{subscription_id}"

"Response Example:"
{
  "subscription_id" : 987987987980
}


<?
    // DELETE Subscription - Delete a subscription.
    include "request_rest.php";

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/subscription";
    $subscription_id = "987987987980";
    $request_url =  $request_url . "/" . $subscription_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 Subscription - Delete a subscription.
<%@ 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>Subscription Delete Sample Code</title>
<body>

<%
    String username = "username";
    String subscriptionID = "987987987980";
    String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/subscription/" + subscriptionID;
    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 Subscription - Delete a subscription.
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; }
    }
    class SubscriptionDelete
    {
        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 subscriptionId = "987987987980";
                //DELETE
                Uri deleteUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/subscription/{1}", username, subscriptionId));
                var response = client.DeleteAsync(deleteUrl).Result;
                if (response.IsSuccessStatusCode)
                {
                    var p = response.Content.ReadAsAsync<Result>().Result;
                    string json = JsonConvert.SerializeObject(p);
                    Console.WriteLine(json);
                }
            }
        }
    }
}