Sample code for 30+ languages & platforms
Swift

Clickatell Get Account Balance

See more Clickatell Examples

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

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

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

    let http = CkoHttp()!

    // Implements the following CURL command:

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

    http.setRequestHeader(name: "Authorization", value: "API_KEY")
    http.setRequestHeader(name: "Accept", value: "application/json")

    let sbResponseBody = CkoStringBuilder()!
    success = http.quickGetSb(url: "https://platform.clickatell.com/public-client/balance", sbContent: sbResponseBody)
    if success == false {
        print("\(http.lastErrorText!)")
        return
    }

    let jResp = CkoJsonObject()!
    jResp.loadSb(sb: sbResponseBody)
    jResp.emitCompact = false

    print("Response Body:")
    print("\(jResp.emit()!)")

    var respStatusCode: Int = http.lastStatus.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(http.lastHeader!)")
        print("Failed.")
        return
    }

    // 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

    var balance: String?
    var currency: String?

    balance = jResp.string(of: "balance")
    currency = jResp.string(of: "currency")

}