Dart Requires Chilkat v11.0.0+
Dart
Xero Get Accounts
See more Xero Examples
Download Xero accounts informationChilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
final jsonToken = CkJsonObject();
try {
jsonToken.loadFile('qa_data/tokens/xero-access-token.json');
} on ChilkatException catch (e) {
print(e.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';
final resp = CkHttpResponse();
try {
http.httpNoBody('GET', 'https://api.xero.com/api.xro/2.0/Accounts', resp);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Response Status Code: ${resp.statusCode}');
final jsonResponse = CkJsonObject();
jsonResponse.load(resp.bodyStr);
jsonResponse.emitCompact = false;
print(jsonResponse.emit());
if (resp.statusCode != 200) {
print('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
// }
// ]
// }
//
var accountID = '';
var code = '';
var name = '';
var type = '';
var taxType = '';
var bankAccountNumber = '';
var bankAccountType = '';
var currencyCode = '';
var description = '';
var i = 0;
final 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');
type = 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++;
}
}