CREDIT BALANCE


Introduction

This API endpoint allows users to retrieve their credit balance. The credit balance represents the remaining credits available for sending SMS messages.

Endpoint

This endpoint retrieves the credit balance for the authenticated user.

Method Endpoint
GET https://app.techspace.co.ke/api/v1/credit-balance

Request Headers

Header Description Value
api-key The API key provided to authenticate the user. szrgh88Z62Ne828RcXM1sCRbFEfm42St
client-id The client ID associated with the user's API key. F2ikqLLEA9EsmWyTzeEAsjln0avMxTix

Note: These are example values. Please obtain your actual API key and client ID from the portal. Visit the portal, go to Settings, then API Keys, and generate your keys.

Response

Success (200 OK)

Returns a JSON object containing the user's credit balance.

{
    "balance": 250 
}

Examples

PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://app.techspace.co.ke/api/v1/credit-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 => 'GET',
  CURLOPT_HTTPHEADER => array(
    'api-key: szrgh88Z62Ne828RcXM1sCRbFEfm42St',
    'client-id: F2ikqLLEA9EsmWyTzeEAsjln0avMxTix'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

?>

Node JS

var https = require('follow-redirects').https;
var fs = require('fs');

var options = {
  'method': 'GET',
  'hostname': 'app.techspace.co.ke',
  'path': '/api/v1/credit-balance',
  'headers': {
    'api-key': 'szrgh88Z62Ne828RcXM1sCRbFEfm42St',
    'client-id': 'F2ikqLLEA9EsmWyTzeEAsjln0avMxTix'
  },
  'maxRedirects': 20
};

var req = https.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();

Curl


curl --location 'https://app.techspace.co.ke/api/v1/credit-balance' \
--header 'api-key: szrgh88Z62Ne828RcXM1sCRbFEfm42St' \
--header 'client-id: F2ikqLLEA9EsmWyTzeEAsjln0avMxTix'

Javascript

var myHeaders = new Headers();
myHeaders.append("api-key", "szrgh88Z62Ne828RcXM1sCRbFEfm42St");
myHeaders.append("client-id", "F2ikqLLEA9EsmWyTzeEAsjln0avMxTix");

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("https://app.techspace.co.ke/api/v1/credit-balance", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Python

import http.client

conn = http.client.HTTPSConnection("app.techspace.co.ke")
payload = ''
headers = {
  'api-key': 'szrgh88Z62Ne828RcXM1sCRbFEfm42St',
  'client-id': 'F2ikqLLEA9EsmWyTzeEAsjln0avMxTix'
}
conn.request("GET", "/api/v1/credit-balance", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Go Native

package main

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

func main() {

  url := "https://app.techspace.co.ke/api/v1/credit-balance"
  method := "GET"

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

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("api-key", "szrgh88Z62Ne828RcXM1sCRbFEfm42St")
  req.Header.Add("client-id", "F2ikqLLEA9EsmWyTzeEAsjln0avMxTix")

  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))
}