Sample code for 30+ languages & platforms
Classic ASP 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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
set http = Server.CreateObject("Chilkat.Http")
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"

set resp = Server.CreateObject("Chilkat.HttpResponse")
success = http.HttpNoBody("GET","https://platform.clickatell.com/v1/balance",resp)
If (resp.StatusCode = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Check the connection and retry the lookup.") & "</pre>"
    Response.End
End If

set reply = Server.CreateObject("Chilkat.JsonObject")
parsed = reply.Load(resp.BodyStr)
If ((success <> 1) Or ((resp.StatusCode <> 200))) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Clickatell returned HTTP " & resp.StatusCode) & "</pre>"
    If (parsed = 1) Then
        If (reply.HasMember("error.description") = 1) Then
            Response.Write "<pre>" & Server.HTMLEncode( reply.StringOf("error.description")) & "</pre>"
        End If

    End If

    Response.End
End If

If (parsed <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON response.") & "</pre>"
    Response.End
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
    Response.Write "<pre>" & Server.HTMLEncode( "The balance response is missing the amount or currency.") & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Account balance: " & reply.StringOf("balance") & " " & reply.StringOf("currency")) & "</pre>"

%>
</body>
</html>