NAV

Keyword(Last Updated : 01/04/2017)

A mobile keyword enables API users to collect new subscriptions automatically through any SMS-enabled mobile phone. An auto-response message can also be set up that is sent to new subscribers after texting in the keyword. Parameter values can be set so that you can receive an inbound PUSH Notification by email or SMS whenever the keyword is texted in.

Methods

PUT /rest/v1/{user_name}/keyword
GET /rest/v1/{user_name}/keyword
GET /rest/v1/{user_name}/keyword/{keyword_id}
POST /rest/v1/{user_name}/keyword/{keyword_id}
DELETE /rest/v1/{user_name}/keyword/{keyword_id}

PUT Keyword

Create a mobile keyword that can collect phone numbers, user information, and automatically send a response message.

Resource Information

Response Formats JSON
Allowed Methods PUT
URL http://api.trumpia.com/rest/v1/{user_name}/keyword
{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
keyword * The keyword that users will text. The keyword must be one word with no spaces. It is case-insensitive. There is a 4- to 50-character limit.
lists * The list_name to which the keyword is attached. Contacts will be automatically added to the list.
allow_message * This enables users to add their own message or response after the keyword. This message will be sent to your Inbox.
auto_response * Configure the settings of your auto-response message. See Auto Response 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.
notify Configure to be notified of any messages from your users. Either email or mobile must be set. See Notify Object table below.
optin_type The opt-in types for keyword sign-up. You can change the default value at Sign In > Account > General Default Setting. The default opt-in type is used if this parameter is not specified.
Value Description
1 Single Opt-In: The subscriber only needs to text in a keyword to complete their sign-up.
2 Double Opt-In: After a subscriber texts in a keyword, they will be asked to reply yes or no to verify their sign-up. If they reply yes, their sign-up is complete.

> Auto Response Object

* required parameters
Parameter Description
message * The content of your auto-response 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.
frequency The number of times an auto-response message will be delivered when a user texts in the keyword.
Value Description
1 everytime
2 only once per mobile number
3 only once every day
Default value: 1
alternative_message The content of an alternative auto-response message. This message will be sent if a user texts in the keyword more than once. 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.
alternative_coupon This alternate message will be sent to your user in case you have run out of coupon codes. To set up a coupon code to be inserted into the message of your auto-response or alternative_message, you must login to your account dashboard.

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.

> Notify Object

* required parameters
Parameter Description
email Email address where a notification will be sent when a person signs up via this keyword.

Example value: testemail@testdomain.com
mobile Mobile phone numbers where a notification will be sent when a person signs up via this keyword.

Example value: 2003004000
subscription * Valid value is all or new.
Value Description
all Notify for all subscriptions.
new Notify only when the subscriber's mobile number is new to your subscription database.

Code sample for PUT Keyword

"Request Example:
PUT http://api.trumpia.com/rest/v1/{user_name}/keyword"
{
  "keyword" : "testKeyword",
  "lists" : "987987987980,987987987981",
  "allow_message" : "true",
  "auto_response" :
  {
    "frequency" : "2",
    "message" : "hi this is auto response message",
    "alternative_message" : "welcome back :)"
  },
  "notify" :
  {
    "email" : "subscriber_email0001@api.trumpia.com",
    "mobile" : "2003004000",
    "subscription" : "new"
  }
}

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


<?
    // PUT Keyword - Create a keyword.
    include "request_rest.php";

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

    $request_data = array(
        "keyword" => "testKeyword",
        "lists" => "987987987980,987987987981",
        "allow_message" => "TRUE",
        "auto_response" => array("message"=>"auto response message.  coupon code : [$CouponCode-coupon]", "frequency"=>"2", "alternative_message"=>"alternative message", "alternative_coupon"=>"alternative coupon message"),
        "notify" => array("email"=>"subscriber_email0001@trumpia.com", "mobile"=>"2003004000", "subscription"=>"NEW")
    );

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


// PUT Keyword - Create a keyword.
<%@ 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>Keyword Put Sample Code</title>
<body>

<%
	String keyword = "testKeyword";
	String username = "username";
	String keywordId = "12345";
	String lists = "987987987980,987987987981";
	String allowMessage = "TRUE";
	JSONObject autoResponse = new JSONObject();
	autoResponse.put("message", "auto response message. coupon code : [$CouponCode-coupon]");
	autoResponse.put("frequency", "2");
	autoResponse.put("alternative_message", "alternative message");
	autoResponse.put("alternative_coupon", "alternative coupon message");
	JSONObject notify = new JSONObject();
	notify.put("email", "subscriber_email0001@trumpia.com");
	notify.put("mobile", "2003004000");
	notify.put("subscription", "NEW");

	JSONObject listPost = new JSONObject();
	listPost.put("keyword", keyword);
	listPost.put("lists", lists);
	listPost.put("allow_message", allowMessage);
	listPost.put("auto_response", autoResponse);
	listPost.put("notify", notify);

	String urlStr = "api.trumpia.com/rest/v1/" + username + "/keyword";
	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(listPut.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 Keyword - Create a keyword.
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 KeywordInfo
    {
        public string keyword { get; set; }
        public string lists { get; set; }
        public string allow_message { get; set; }
        public JObject auto_response { get; set; }
        public JObject notify { get; set; }
    }

    class Result
    {
        public string request_id { get; set; }
    }
    class KeywordPut
    {
        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 autoResponseData = new JObject();
                autoResponseData.Add("message", "hi this is auto response message");
                autoResponseData.Add("frequency", "2");
                autoResponseData.Add("alternative_message", "welcome back :)");

                JObject notifyData = new JObject();
                notifyData.Add("subscription", "new");
                notifyData.Add("email", "subscriber_email0001@trumpia.com");

                var info = new KeywordInfo() { keyword = "testKeyword", lists = "987987987980,987987987981", allow_message = "TRUE", auto_response = autoResponseData, notify = notifyData };
                Uri postUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/keyword", 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 Keyword

Lookup general information about your mobile keywords, including ID, name, and short code, or more detailed information, like auto-response message, for an individual keyword.

Resource Information

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

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 Keyword

"Request Example (to retrieve general information for all your keywords):
GET http://api.trumpia.com/rest/v1/{user_name}/keyword"

"Response Example:"
{
  "keyword" :
  [
    {"keyword_id" : "987987987980","keyword" : "testKeyword","shortcode" : "95577"},
    {"keyword_id" : "987987987981","keyword" : "testKeyword","shortcode" : "95577"},
    {"keyword_id" : "987987987982","keyword" : "testKeyword","shortcode" : "95577"}
  ]
}

"Request Example (to retrieve complete information for a specific keyword):
GET http://api.trumpia.com/rest/v1/{user_name}/keyword/{keyword_id}"

"Response Example:"
{
  "keyword" : "testKeyword",
  "auto_response_message" : "This is the keyword message.",
  "shortcode" : "95577",
  "alternative_message" : "Hi there!",
  "alternative_coupon" : "This is the alternative coupon message."
}


<?
    //GET Keyword - Retrieve all keywords.
    include "request_rest.php";

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

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

    $request_url = "http://api.trumpia.com/rest/v1/{user_name}/keyword";
    $keyword_id = "987987987980";
    $request_url =	$request_url . "/" . $keyword_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 Keyword - Retrieve all keywords.
<%@ 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>Keyword Get All Sample Code</title>

<body>

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

	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 Keyword - Retrieve a keyword 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>Keyword Get By Id Sample Code</title>
<body>

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

	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 Keyword - Retrieve all keywords.
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 KeywordInfo
    {
        public JArray keyword { get; set;}
    }
    class KeywordGet
    {
        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";

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


// GET Keyword - Retrieve a keyword by ID.
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 KeywordInfo
    {
        public string keyword { get; set; }
        public string shortcode { get; set; }
        public string auto_response_message { get; set; }
        public string alternative_message { get; set; }
    }
    class KeywordDetailGet
    {
        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 keywordId = "987987987980";

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

POST Keyword

Update your mobile keyword and auto-response message. All values can be changed except for the name of your keyword (i.e., "keyword" parameter).

Resource Information

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

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
lists The list_name to which the keyword is attached. Contacts will be automatically added to the list.
allow_message This enables users to add their own message or response after the keyword. This message will be sent to your Inbox.
auto_response Configure the settings of your auto-response message. See Auto Response 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.
notify Configure to be notified of any messages from your users. Either email or mobile must be set.
- After successful update, subscription must exist if notify exists on the keyword.
- After successful update, either email or mobile must exist if notify exists on the keyword.
See Notify Object table below.
optin_type The opt-in types for keyword sign-up.
Value Description
1 Single Opt-In: The subscriber only needs to text in a keyword to complete their sign-up.
2 Double Opt-In: After a subscriber texts in a keyword, they will be asked to reply yes or no to verify their sign-up. If they reply yes, their sign-up is complete.

> Auto Response Object

* required parameters
Parameter Description
message The content of your auto-response 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.
frequency The number of times an auto-response message will be delivered when a user texts in the keyword. 
Value Description
1 everytime
2 only once per mobile number
3 only once every day
Default value: 1
alternative_message The content of an alternative auto-response message. This message will be sent if a user texts in the keyword more than once. 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.
alternative_coupon This alternate message will be sent to your user in case you have run out of coupon codes. To set up a coupon code to be inserted into the message of your auto-response or alternative_message, you must login to your account dashboard.

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.

> Notify Object

* required parameters
Parameter Description
email Email address where a notification will be sent when a person signs up via this keyword.

Example value: testemail@testdomain.com
mobile Mobile phone numbers where a notification will be sent when a person signs up via this keyword.

Example value: 2003004000
subscription Valid value is all or new.
Value Description
all Notify for all subscriptions.
new Notify only when the subscriber's mobile number is new to your subscription database.

Code samples for POST Keyword

"Request Example:
POST http://api.trumpia.com/rest/v1/{user_name}/keyword/{keyword_id}"
{
  "notify" :
  {
    "email" : "subscriber_email0001@api.trumpia.com",
    "mobile" : "2003004000"
  }
}

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


<?
    // POST Keyword - Update a keyword.
    include "request_rest.php";

    $request_url = "api.trumpia.com/rest/v1/{user_name}/keyword";
    $keyword_id = "987987987980";
    $request_url =	$request_url . "/" . $keyword_id;

    $request_data = array(
        "lists" => "987987987980,987987987981,987987987982",
        "allow_message" => "TRUE",
        "auto_response" => array("message"=>"auto response message edit", "frequency"=>"2", "alternative_message"=>"alternative message edit"),
        "notify" => array("email"=>"subscriber_email0001@trumpia.com", "mobile"=>"2003004000", "subscription"=>"NEW")
    );

    $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 Keyword - Update a keyword.
<%@ 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>Keyword Post Sample Code</title>
<body>

<%
	String username = "username";
	String keywordId = "987987987980";
	String lists = "987987987980,987987987981,987987987982";
	String allowMessage = "TRUE";
	JSONObject autoResponse = new JSONObject();
	autoResponse.put("message", "auto response message edit");
	autoResponse.put("frequency", "2");
	autoResponse.put("alternative_message", "alternative message edit");
	JSONObject notify = new JSONObject();
	notify.put("email", "subscriber_email0001@trumpia.com");
	notify.put("mobile", "2003004000");
	notify.put("subscription", "NEW");

	JSONObject keywordPost = new JSONObject();
	keywordPost.put("lists", lists);
	keywordPost.put("allow_message", allowMessage);
	keywordPost.put("auto_response", autoResponse);
	keywordPost.put("notify", notify);

	String urlStr = "http://api.trumpia.com/rest/v1/" + username + "/keyword/" + keywordId;
	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(listPost.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>


// POST Keyword - Update a keyword.
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 KeywordInfo
    {
        public string lists { get; set; }
        public string allow_message { get; set; }
        public JObject auto_response { get; set; }
        public JObject notify { get; set; }
    }
    class Result
    {
        public string request_id { get; set; }
    }
    class KeywordPost
    {
        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 keywordId = "987987987980";
                //POST
                JObject autoResponseData = new JObject();
                autoResponseData.Add("message", "hi this is auto response message");
                autoResponseData.Add("frequency", "2");
                autoResponseData.Add("alternative_message", "welcome back :)");

                JObject notifyData = new JObject();
                notifyData.Add("subscription", "new");
                notifyData.Add("email", "subscriber_email0001@trumpia.com");

                var list = new KeywordInfo() { lists = "987987987980,987987987981", allow_message = "TRUE", auto_response = autoResponseData, notify = notifyData };
                Uri postUrl = new Uri(string.Format("http://api.trumpia.com/rest/v1/{0}/keyword/{1}", username, keywordId));
                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 Keyword

Permanently delete a mobile keyword.

Resource Information

Response Formats JSON
Allowed Methods DELETE
URL http://api.trumpia.com/rest/v1/{user_name}/keyword/{keyword_id}
{user_name} Your account username (this can be found in the Account Settings page after logging in.)
{keyword_id} The keyword_id that will be deleted. Keyword_ids can be found using GET Keyword.

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 Keyword

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

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


<?
    // DELETE Keyword - Delete a keyword.
    include "request_rest.php";

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

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