Sample code for 30+ languages & platforms
Visual Basic 6.0 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 Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim http As New ChilkatHttp
http.RequireSslCertVerify = 1
'  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 ChilkatHttpResponse
success = http.HttpNoBody("GET","https://platform.clickatell.com/v1/balance",resp)
If (resp.StatusCode = 0) Then
    Debug.Print "No HTTP response. Check the connection and retry the lookup."
    Exit Sub
End If

Dim reply As New ChilkatJsonObject
Dim parsed As Long
parsed = reply.Load(resp.BodyStr)
If ((success <> 1) Or ((resp.StatusCode <> 200))) Then
    Debug.Print "Clickatell returned HTTP " & resp.StatusCode
    If (parsed = 1) Then
        If (reply.HasMember("error.description") = 1) Then
            Debug.Print reply.StringOf("error.description")
        End If

    End If

    Exit Sub
End If

If (parsed <> 1) Then
    Debug.Print "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.Print "The balance response is missing the amount or currency."
    Exit Sub
End If

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