PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
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.
Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Resp
oleobject loo_Reply
long li_Parsed
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.RequireSslCertVerify = 1
// Supply the key for this One API integration from application configuration.
loo_Http.SetRequestHeader("Authorization","ONE_API_KEY")
loo_Http.SetRequestHeader("Accept","application/json")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
li_Success = loo_Http.HttpNoBody("GET","https://platform.clickatell.com/v1/balance",loo_Resp)
if loo_Resp.StatusCode = 0 then
Write-Debug "No HTTP response. Check the connection and retry the lookup."
destroy loo_Http
destroy loo_Resp
return
end if
loo_Reply = create oleobject
li_rc = loo_Reply.ConnectToNewObject("Chilkat.JsonObject")
li_Parsed = loo_Reply.Load(loo_Resp.BodyStr)
if (li_Success <> 1) OR ((loo_Resp.StatusCode <> 200)) then
Write-Debug "Clickatell returned HTTP " + string(loo_Resp.StatusCode)
if li_Parsed = 1 then
if loo_Reply.HasMember("error.description") = 1 then
Write-Debug loo_Reply.StringOf("error.description")
end if
end if
destroy loo_Http
destroy loo_Resp
destroy loo_Reply
return
end if
if li_Parsed <> 1 then
Write-Debug "Expected a JSON response."
destroy loo_Http
destroy loo_Resp
destroy loo_Reply
return
end if
// JsonTypeOf returns 2 for a number and 1 for a string. Zero is a valid amount.
if (loo_Reply.JsonTypeOf("balance") <> 2) OR (loo_Reply.JsonTypeOf("currency") <> 1) then
Write-Debug "The balance response is missing the amount or currency."
destroy loo_Http
destroy loo_Resp
destroy loo_Reply
return
end if
Write-Debug "Account balance: " + loo_Reply.StringOf("balance") + " " + loo_Reply.StringOf("currency")
destroy loo_Http
destroy loo_Resp
destroy loo_Reply