How to Query SMS Units Balance

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 query for SMS Units balance by making a HTTP GET request with the following:


Endpoint
https://service.textpie.co.ke/api/v1/customer/sms_unit
Code Examples
                                        
curl -X GET "https://service.textpie.co.ke/api/v1/customer/sms_unit" -H "accept: application/json" -H "X-API-KEY: {API_KEY}"
                                        
                                    
                                        
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
  .url("https://service.textpie.co.ke/api/v1/customer/sms_unit")
  .method("GET", body)
  .addHeader("accept", "application/json")
  .addHeader("X-API-KEY", "{API_KEY}")
  .build();
Response response = client.newCall(request).execute();
                                        
                                    
                                        
var http = require('follow-redirects').http;
var fs = require('fs');

var options = {
  'method': 'GET',
  'hostname': 'service.textpie.co.ke',
  'path': '/api/v1/customer/sms_unit',
  'headers': {
    'accept': 'application/json',
    'X-API-KEY': '{API_KEY}'
  },
  '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);
  });
});

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

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://service.textpie.co.ke/api/v1/customer/sms_unit',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'X-API-KEY: {API_KEY}'
  ),
));

$response = curl_exec($curl);

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

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

headers = {
  'accept': 'application/json',
  'X-API-KEY': '{API_KEY}'
}

response = requests.get(url, headers=headers)

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

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

# Set up the HTTP headers
headers = {
  'accept' => 'application/json',
  'X-API-KEY' => '{API_KEY}'
}

# Create the HTTP request
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)
headers.each { |key, value| request[key] = value }

# Make the request
response = http.request(request)

# Print the response body
puts response.body

                                        
                                    
Example of a Successful Response
                                
{
  "available_units": "integer"
}
                                
                            
Status codes
Code Description
200 SMS message(s) successfully queued
401 Authentication error
404 Account not found