CkPython Requires Chilkat v11.0.0+
CkPython
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 CkPython Downloads
import sys
import chilkat
success = False
# Assumes Chilkat is unlocked. See Global Unlock Sample.
http = chilkat.CkHttp()
http.put_RequireSslCertVerify(True)
# Supply the key for this One API integration from application configuration.
http.SetRequestHeader("Authorization","ONE_API_KEY")
http.SetRequestHeader("Accept","application/json")
resp = chilkat.CkHttpResponse()
success = http.HttpNoBody("GET","https://platform.clickatell.com/v1/balance",resp)
if (resp.get_StatusCode() == 0):
print("No HTTP response. Check the connection and retry the lookup.")
sys.exit()
reply = chilkat.CkJsonObject()
parsed = reply.Load(resp.bodyStr())
if ((success != True) or ((resp.get_StatusCode() != 200))):
print("Clickatell returned HTTP " + str(resp.get_StatusCode()))
if (parsed == True):
if (reply.HasMember("error.description") == True):
print(reply.stringOf("error.description"))
sys.exit()
if (parsed != True):
print("Expected a JSON response.")
sys.exit()
# 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)):
print("The balance response is missing the amount or currency.")
sys.exit()
print("Account balance: " + reply.stringOf("balance") + " " + reply.stringOf("currency"))