Sample code for 30+ languages & platforms
PowerShell Requires Chilkat v11.0.0+

Clickatell One API: Read the account balance and currency

See more Clickatell Examples

Request the messaging balance associated with a One API integration key. The response supplies both the decimal amount and its currency. Read the amount as text for display to preserve its precision. A zero balance is a valid result. For example, a billing dashboard can display 1267.92865 ZAR.

Clickatell API reference

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

#  Assumes Chilkat is unlocked. See Global Unlock Sample.
$http = New-Object Chilkat.Http
$http.RequireSslCertVerify = $true
#  Supply the key for this One API integration from application configuration.
$http.SetRequestHeader("Authorization","ONE_API_KEY")
$http.SetRequestHeader("Accept","application/json")

$resp = New-Object Chilkat.HttpResponse
$success = $http.HttpNoBody("GET","https://platform.clickatell.com/v1/balance",$resp)
if ($resp.StatusCode -eq 0) {
    $("No HTTP response. Check the connection and retry the lookup.")
    exit
}

$reply = New-Object Chilkat.JsonObject
$parsed = $reply.Load($resp.BodyStr)
if (($success -ne $true) -or (($resp.StatusCode -ne 200))) {
    $("Clickatell returned HTTP " + $resp.StatusCode)
    if ($parsed -eq $true) {
        if ($reply.HasMember("error.description") -eq $true) {
            $($reply.StringOf("error.description"))
        }

    }

    exit
}

if ($parsed -ne $true) {
    $("Expected a JSON response.")
    exit
}

#  JsonTypeOf returns 2 for a number and 1 for a string. Zero is a valid amount.
if (($reply.JsonTypeOf("balance") -ne 2) -or ($reply.JsonTypeOf("currency") -ne 1)) {
    $("The balance response is missing the amount or currency.")
    exit
}

$("Account balance: " + $reply.StringOf("balance") + " " + $reply.StringOf("currency"))