Returns the current balance for the specified channel in your account.

Endpoint


POST https://app.topups.co.ke/api/get_balance LIVE

Request


Parameter Example
Headers
Accept application/json
String | Optional
The format of the response body. Options are:
  • application/json
  • text/xml
Defaults to application/json if not specified.
Authorization Bearer a12f4f9a99be83f1e631e379834864e7
String | Required
The API token used for authorizing the API call as Bearer token.
Content-Type application/json
String | Optional
The format of the request body. Options are:
  • application/json
  • text/xml
Defaults to application/json if not specified.
Body
channel_type Airtime
String | Required
Type of Topups channel. Options are:
  • Airtime
  • Agent Float
  • SMS

Code Scripts


POST /api/get_balance HTTP/1.1
Host: app.topups.co.ke
Accept: application/json
Authorization: Bearer a12f4f9a99be83f1e631e379834864e7
Content-Type: application/json
Content-Length: 35

{
    "channel_type": "Airtime"
}
curl --request POST 'https://app.topups.co.ke/api/send_airtime' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer a12f4f9a99be83f1e631e379834864e7' \
--header 'Content-Type: application/json' \
--data-raw '{
    "channel_type": "Airtime"
}'
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://app.topups.co.ke/api/get_balance',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS =>'{
        "channel_type": "Airtime"
    }',
    CURLOPT_HTTPHEADER => array(
        'Accept: application/json',
        'Authorization: Bearer a12f4f9a99be83f1e631e379834864e7',
        'Content-Type: application/json'
    ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
#!/usr/bin/python
import http.client
import json

conn = http.client.HTTPSConnection("app.topups.co.ke")
payload = json.dumps({
    "channel_type": "Airtime"
})
headers = {
    'Accept': 'application/json',
    'Authorization': 'Bearer a12f4f9a99be83f1e631e379834864e7',
    'Content-Type': 'application/json'
}
conn.request("POST", "/api/get_balance", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
require "uri"
require "json"
require "net/http"

url = URI("https://app.topups.co.ke/api/get_balance")

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

request = Net::HTTP::Post.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Bearer a12f4f9a99be83f1e631e379834864e7"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
    "channel_type": "Airtime"
})

response = https.request(request)
puts response.read_body
OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n    \"channel_type\": \"Airtime\"\r\n}");
Request request = new Request.Builder()
    .url("https://app.topups.co.ke/api/get_balance")
    .method("POST", body)
    .addHeader("Accept", "application/json")
    .addHeader("Authorization", "Bearer a12f4f9a99be83f1e631e379834864e7")
    .addHeader("Content-Type", "application/json")
    .build();
Response response = client.newCall(request).execute();
var client = new RestClient("https://app.topups.co.ke/api/get_balance");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Accept", "application/json");
request.AddHeader("Authorization", "Bearer a12f4f9a99be83f1e631e379834864e7");
request.AddHeader("Content-Type", "application/json");
var body = @"{
" + "\n" +
@"    ""channel_type"": ""Airtime""
" + "\n" +
@"}";
request.AddParameter("application/json", body,  ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
var request = require('request');
var options = {
    'method': 'POST',
    'url': 'https://app.topups.co.ke/api/get_balance',
    'headers': {
        'Accept': 'application/json',
        'Authorization': 'Bearer a12f4f9a99be83f1e631e379834864e7',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        "channel_type": "Airtime"
    })
};
request(options, function (error, response) {
if (error) throw new Error(error);
    console.log(response.body);
});
package main

import (
    "fmt"
    "strings"
    "net/http"
    "io/ioutil"
)

func main() {

url := "https://app.topups.co.ke/api/get_balance"
method := "POST"

payload := strings.NewReader(`{`+"
"+`
    "channel_type": "Airtime"`+"
"+`
}`)

client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)

if err != nil {
    fmt.Println(err)
    return
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Authorization", "Bearer a12f4f9a99be83f1e631e379834864e7")
req.Header.Add("Content-Type", "application/json")

res, err := client.Do(req)
if err != nil {
    fmt.Println(err)
    return
}
defer res.Body.Close()

body, err := ioutil.ReadAll(res.Body)
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(string(body))
}

Response


Parameter Example
status
type SUCCESS
String
Indication of whether the API call executed successfully or failed. Options are:
  • SUCCESS
  • FAIL
code 0000
Numeric
Identifier of the API call result status
message Balance Found
String
Description of the API call result status
data
error []
Array of Strings
A list of errors found when the API call fails. Returns empty if none are found.
channel
type Airtime
String
Type of product channel. Options are:
  • Airtime
  • Agent Float
  • SMS
currency KES
String
Currency of your balance
balance 41126.00
Numeric
Balance of the specified channel

Success Example


{
    "status": {
        "type": "SUCCESS",
        "code": "0000",
        "message": "Balance Found"
    },
    "data": {
        "errors": [],
        "channel": {
            "type": "Airtime",
            "currency": "KES",
            "balance": "41226.00"
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<xml>
    <status>
        <type>SUCCESS</type>
        <code>0000</code>
        <message>Balance Found</message>
    </status>
    <data>
        <errors/>
        <channel>
            <type>Airtime</type>
            <currency>KES</currency>
            <balance>41226.00</balance>
        </channel>
    </data>
</xml>

Status


Code
0000 SUCCESS
Balance Found
1000 FAIL
Invalid API Request
2000 FAIL
Invalid Request Method
3000 FAIL
Missing or Invalid Parameters
4000 FAIL
Invalid API Token
5000 FAIL
Request Not Allowed
6000 FAIL
Invalid Account

Fail Example


{
    "status": {
        "type": "FAIL",
        "code": "3000",
        "message": "Missing or Invalid Parameters"
    },
    "data": {
        "errors": [
            "'channel_type is required.'"
        ]
    }
}
<?xml version="1.0" encoding="utf-8"?>
<xml>
    <status>
        <type>FAIL</type>
        <code>3000</code>
        <message>Missing or Invalid Parameters</message>
    </status>
    <data>
        <errors>
            <error>'channel_type is required.'</error>
        </errors>
    </data>
</xml>