How to Send Premium SMS

This action requires headers to be sent with your API Key. This can be retrieved from your account by accessing the api details section

You can send a single or multiple premium SMS(s) to one or many recipients by making a HTTP POST request with the following:


Endpoint
https://service.textpie.co.ke/api/v1/customer/premium/sms
Request Body
                                
{
    "api_username": "string",
    "message": "string",
    "short_code": "string"
}
                                
                            
Code Examples
                                        
curl --location 'https://service.textpie.co.ke/api/v1/customer/premium/sms' \
--header 'X-API-KEY: {API_KEY}' \
--header 'Content-Type: text/plain' \
--data '{
    "api_username": "{API_USENAME}",
    "short_code": "{SENDER_ID}",
    "message": "Hello Textpie!"
}'
                                        
                                    
                                        
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "{\"api_username\": \"{API_USERNAME}\",\"short_code\": \"{SENDER_ID}\",\"message\": \"Hello Textpie!\"}");
Request request = new Request.Builder()
  .url("https://service.textpie.co.ke/api/v1/customer/premium/sms")
  .method("POST", body)
  .addHeader("X-API-KEY", "{API_KEY}")
  .addHeader("Content-Type", "text/plain")
  .build();
Response response = client.newCall(request).execute();
                                        
                                    
                                        
var http = require('follow-redirects').http;
var fs = require('fs');

var options = {
  'method': 'POST',
  'hostname': 'service.textpie.co.ke',
  'path': '/api/v1/customer/premium/sms',
  'headers': {
    'X-API-KEY': '{API_KEY}',
    'Content-Type': 'text/plain'
  },
  'maxRedirects': 20
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function (chunk) {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });

  res.on("error", function (error) {
    console.error(error);
  });
});

var postData =  "{\"api_username\": \"{API_USERNAME}\",\"short_code\": \"{SENDER_ID}\",\"message\": \"Hello Textpie!\"}";

req.write(postData);

req.end();
                                        
                                    
                                        
<?php$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://service.textpie.co.ke/api/v1/customer/premium/sms',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "api_username": "{API_USERNAME}",
    "short_code": "{SENDER_ID}",
    "message": "Hello Textpie!"
 }',
  CURLOPT_HTTPHEADER => array(
    'X-API-KEY: {API_KEY}',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);
curl_close($curl);
echo $response;
                                        
                                    
                                        
import requests

url = "https://service.textpie.co.ke/api/v1/customer/premium/sms"

payload = {
    "api_username": "{API_USERNAME}",
    "short_code": "{SENDER_ID}",
    "message": "Hello Textpie!"
}
headers = {
  'X-API-KEY': '{API_KEY}',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, json=payload)

print(response.text)
                                        
                                    
                                        
require "uri"
require "json"
require "net/http"

url = URI("https://service.textpie.co.ke/api/v1/customer/premium/sms")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = "{API_KEY}"
request["Content-Type"] = "application/json"
request.body = {
  :api_username => "{API_USERNAME}"
  :short_code => "{SENDER_ID}",
  :message => "Hello Textpie!"
}.to_json

response = https.request(request)
puts response.read_body
                                        
                                    
Payload
Parameter Description Required
phone A single phone number (MSISDN) YES
api_username Account username. This can be retrieved from your account's API details menu YES
short_code Your premium shortcode YES
message The message to be sent YES
Example of a Successful Response
                                
{
    "id": "string",
    "api_username": "string",
    "request_id": "string",
    "message": "string",
    "short_code": "string",
    "status": "string",
    "is_last_message": false
}
                                
                            
Status codes
Code Description
201 SMS message(s) successfully queued
401 Authentication error
402 Insufficient units
403 Invalid sender id
404 Account not found