Trumpia is a leading Messaging and Marketing company. Its a automated communications platform which provide complete texting solution. Using this you can send bulk messages to users with automated process.
Trumpia’s API provide features to integrate your system to his services. In this post we will explain you, how to getting start with it and add new subscriber in your Subscriber List via api.
To communicate with the Trumpia api, you need an API KEY. Get your api key through send a request to trumpia support. After accepting their policies and reviewing, your request will approve and issue a unique Api Key.
How to Add New Subscriber in Trumpia list via API:
You need to include “request_rest.php” file to execute the api calls. Here is the file code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
<?php class RestRequest { private $curl_handle; private $request_url; private $method; private $request_body; private $content_type; private $api_key; private $response_body; private $response_status; public function __construct() { $this->method = "GET"; $this->request_body = ""; $this->content_type = "application/json"; } public function setRequestURL($request_url) { $this->request_url = $request_url; } public function setAPIKey($api_key) { $this->api_key = $api_key; } public function setRequestBody($request_body) { $this->request_body = $request_body; } public function setContentType($content_type) { $this->content_type = $content_type; } public function setMethod($method) { $this->method = $method; } private function setCurlOption() { curl_setopt($this->curl_handle, CURLOPT_TIMEOUT, 10); curl_setopt($this->curl_handle, CURLOPT_URL, $this->request_url); curl_setopt($this->curl_handle, CURLOPT_HTTPHEADER, array("Content-Type: " . $this->content_type, "X-Apikey: " . $this->api_key)); curl_setopt($this->curl_handle, CURLOPT_RETURNTRANSFER, true); } private function invoke() { $this->response_body = curl_exec($this->curl_handle); $this->response_status = curl_getinfo($this->curl_handle, CURLINFO_HTTP_CODE); } public function execute() { $this->curl_handle = curl_init(); $this->setCurlOption(); switch (strtoupper($this->method)) { case "GET": $this->setGet(); break; case "POST": $this->setPost(); break; case "PUT": $this->setPut(); break; case "DELETE": $this->setDelete(); break; default: $this->setGet(); break; } $this->invoke(); curl_close($this->curl_handle); $result = array($this->response_status, $this->response_body); return $result; } private function setGet() { curl_setopt($this->curl_handle, CURLOPT_POST, false); } private function setPost() { curl_setopt($this->curl_handle, CURLOPT_POST, true); curl_setopt($this->curl_handle, CURLOPT_POSTFIELDS, $this->request_body); } private function setDelete() { curl_setopt($this->curl_handle, CURLOPT_CUSTOMREQUEST, "DELETE"); } private function setPut() { curl_setopt($this->curl_handle, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($this->curl_handle, CURLOPT_POSTFIELDS, $this->request_body); } } ?> |
After save this file, create “add_subscriber.php” file to add new subscriber in list. You have to place your Trumpia Api Key in this file.
You May Also Like:
How to Add New Product in Bigcommerce via API V2
How to Insert New Lead Data in Zoho CRM Through API
How to Get Opportunity Data from Salesforce Through API in PHP
How to Install Magento Security Patch via Putty
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?php //subscription PUT include "request_rest.php"; $request_url = "http://api.trumpia.com/rest/v1/{user_name}/subscription"; // use your username here $request_data = array( "list_name" => "list29", // your list name "subscriptions" => array( array( "mobile" => array("number"=>"2144448750", "country_code"=>"1"), "voice_device" => "mobile" ) ) ); $request_rest = new RestRequest(); $request_rest->setRequestURL($request_url); $request_rest->setAPIKey("c8bfc4***********6089521"); // Use you API KEY Here $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"; } ?> |
In this file use your created list name in request data with subscription parameters. Must change username in the request url with your own to process the api request. Using above code you can easily integrate trumpia api and add new subscriber in it. Thanks