Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loReply
LOCAL lnParsed
lnSuccess = 0
* Assumes Chilkat is unlocked. See Global Unlock Sample.
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
* Supply the key for this One API integration from application configuration.
loHttp.SetRequestHeader("Authorization","ONE_API_KEY")
loHttp.SetRequestHeader("Accept","application/json")
loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpNoBody("GET","https://platform.clickatell.com/v1/balance",loResp)
IF (loResp.StatusCode = 0) THEN
? "No HTTP response. Check the connection and retry the lookup."
RELEASE loHttp
RELEASE loResp
CANCEL
ENDIF
loReply = CreateObject('Chilkat.JsonObject')
lnParsed = loReply.Load(loResp.BodyStr)
IF ((lnSuccess <> 1) OR ((loResp.StatusCode <> 200))) THEN
? "Clickatell returned HTTP " + STR(loResp.StatusCode)
IF (lnParsed = 1) THEN
IF (loReply.HasMember("error.description") = 1) THEN
? loReply.StringOf("error.description")
ENDIF
ENDIF
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
IF (lnParsed <> 1) THEN
? "Expected a JSON response."
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
* JsonTypeOf returns 2 for a number and 1 for a string. Zero is a valid amount.
IF ((loReply.JsonTypeOf("balance") <> 2) OR (loReply.JsonTypeOf("currency") <> 1)) THEN
? "The balance response is missing the amount or currency."
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
? "Account balance: " + loReply.StringOf("balance") + " " + loReply.StringOf("currency")
RELEASE loHttp
RELEASE loResp
RELEASE loReply