React Native Requires Chilkat v11.0.0+
React Native
Xero Get Accounts
See more Xero Examples
Download Xero accounts informationChilkat React Native Downloads
import { Http, HttpResponse, JsonObject } from '@chilkat/react-native'
async function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new Http();
const jsonToken = new JsonObject();
try {
jsonToken.loadFile('qa_data/tokens/xero-access-token.json');
} catch {
console.log(jsonToken.lastErrorText);
return;
}
http.authToken = jsonToken.stringOf('access_token');
// Replace the value here with an actual tenant ID obtained from this example:
// Get Xero Tenant IDs
http.setRequestHeader('Xero-tenant-id', '83299b9e-5747-4a14-a18a-a6c94f824eb7');
http.accept = 'application/json';
const resp = new HttpResponse();
try {
await http.httpNoBodyAsync('GET', 'https://api.xero.com/api.xro/2.0/Accounts', resp);
} catch {
console.log(http.lastErrorText);
return;
}
console.log(`Response Status Code: ${resp.statusCode}`);
const jsonResponse = new JsonObject();
jsonResponse.load(resp.bodyStr);
jsonResponse.emitCompact = false;
console.log(jsonResponse.emit());
if (resp.statusCode !== 200) {
console.log('Failed.');
return;
}
// Sample output...
// (See the parsing code below..)
//
// Use the this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "Accounts": [
// {
// "AccountID": "ebd06280-af70-4bed-97c6-7451a454ad85",
// "Code": "091",
// "Name": "Business Savings Account",
// "Type": "BANK",
// "TaxType": "NONE",
// "EnablePaymentsToAccount": false,
// "BankAccountNumber": "0209087654321050",
// "BankAccountType": "BANK",
// "CurrencyCode": "NZD"
// },
// {
// "AccountID": "7d05a53d-613d-4eb2-a2fc-dcb6adb80b80",
// "Code": "200",
// "Name": "Sales",
// "Type": "REVENUE",
// "TaxType": "OUTPUT2",
// "Description": "Income from any normal business activity",
// "EnablePaymentsToAccount": false
// }
// ]
// }
//
let accountID = '';
let code = '';
let name = '';
let typeArg = '';
let taxType = '';
let bankAccountNumber = '';
let bankAccountType = '';
let currencyCode = '';
let description = '';
let i = 0;
const countI = jsonResponse.sizeOfArray('Accounts');
while (i < countI) {
jsonResponse.i = i;
accountID = jsonResponse.stringOf('Accounts[i].AccountID');
code = jsonResponse.stringOf('Accounts[i].Code');
name = jsonResponse.stringOf('Accounts[i].Name');
typeArg = jsonResponse.stringOf('Accounts[i].Type');
taxType = jsonResponse.stringOf('Accounts[i].TaxType');
jsonResponse.boolOf('Accounts[i].EnablePaymentsToAccount');
bankAccountNumber = jsonResponse.stringOf('Accounts[i].BankAccountNumber');
bankAccountType = jsonResponse.stringOf('Accounts[i].BankAccountType');
currencyCode = jsonResponse.stringOf('Accounts[i].CurrencyCode');
description = jsonResponse.stringOf('Accounts[i].Description');
i++;
}
}