Sample code for 30+ languages & platforms
Lianja

Clickatell Get Account Balance

See more Clickatell Examples

This will return the balance for the account associated with the given API-key.

Chilkat Lianja Downloads

Lianja
llSuccess = .F.

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loHttp = createobject("CkHttp")

// Implements the following CURL command:

// curl -X GET --header 'Accept: application/json' \
//  --header 'Authorization: API_KEY' 
//  https://platform.clickatell.com/public-client/balance

loHttp.SetRequestHeader("Authorization","API_KEY")
loHttp.SetRequestHeader("Accept","application/json")

loSbResponseBody = createobject("CkStringBuilder")
llSuccess = loHttp.QuickGetSb("https://platform.clickatell.com/public-client/balance",loSbResponseBody)
if (llSuccess = .F.) then
    ? loHttp.LastErrorText
    release loHttp
    release loSbResponseBody
    return
endif

loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    release loHttp
    release loSbResponseBody
    release loJResp
    return
endif

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "balance": 1267.92865,
//   "currency": "ZAR"
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

lcBalance = loJResp.StringOf("balance")
lcCurrency = loJResp.StringOf("currency")


release loHttp
release loSbResponseBody
release loJResp