React Native
React Native
Clickatell Get Account Balance
See more Clickatell Examples
This will return the balance for the account associated with the given API-key.Chilkat React Native Downloads
import { Http, JsonObject, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new Http();
// 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('Authorization', 'API_KEY');
http.setRequestHeader('Accept', 'application/json');
const sbResponseBody = new StringBuilder();
try {
await http.quickGetSbAsync('https://platform.clickatell.com/public-client/balance', sbResponseBody);
} catch {
console.log(http.lastErrorText);
return;
}
const jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
jResp.emitCompact = false;
console.log('Response Body:');
console.log(jResp.emit());
const respStatusCode = http.lastStatus;
console.log(`Response Status Code = ${respStatusCode}`);
if (respStatusCode >= 400) {
console.log('Response Header:');
console.log(http.lastHeader);
console.log('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
const balance = jResp.stringOf('balance');
const currency = jResp.stringOf('currency');
}