Sample code for 30+ languages & platforms
VB.NET 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 VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New 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")

Dim resp As New Chilkat.HttpResponse
success = http.HttpNoBody("GET","https://platform.clickatell.com/v1/balance",resp)
If (resp.StatusCode = 0) Then
    Debug.WriteLine("No HTTP response. Check the connection and retry the lookup.")
    Exit Sub
End If

Dim reply As New Chilkat.JsonObject
Dim parsed As Boolean = reply.Load(resp.BodyStr)
If ((success <> True) Or ((resp.StatusCode <> 200))) Then
    Debug.WriteLine("Clickatell returned HTTP " & resp.StatusCode)
    If (parsed = True) Then
        If (reply.HasMember("error.description") = True) Then
            Debug.WriteLine(reply.StringOf("error.description"))
        End If

    End If

    Exit Sub
End If

If (parsed <> True) Then
    Debug.WriteLine("Expected a JSON response.")
    Exit Sub
End If


'  JsonTypeOf returns 2 for a number and 1 for a string. Zero is a valid amount.
If ((reply.JsonTypeOf("balance") <> 2) Or (reply.JsonTypeOf("currency") <> 1)) Then
    Debug.WriteLine("The balance response is missing the amount or currency.")
    Exit Sub
End If

Debug.WriteLine("Account balance: " & reply.StringOf("balance") & " " & reply.StringOf("currency"))