Rust Requires Chilkat v11.0.0+
Rust
Xero Update Account Details
See more Xero Examples
Update some details of an account in a Xero company (Accounting API)Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/xero-access-token.json").is_err() {
println!("{}", json_token.last_error_text());
return;
}
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());
// Replace the value here with an actual tenant ID obtained from this example:
// Get Xero Tenant IDs
http.set_request_header("Xero-tenant-id", "83299b9e-5747-4a14-a18a-a6c94f824eb7");
http.set_accept("application/json");
// The following JSON is sent in the request body:
// {
// "AccountID": "54ddab14-4a8d-45cf-86be-076c99a0cea0",
// "Name": "Sales account",
// "Type": "REVENUE",
// "TaxType": "OUTPUT",
// "Description": "Income from any normal business trading activity",
// "EnablePaymentsToAccount": "false",
// "ShowInExpenseClaims": "false"
// }
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
let json_request_body = chilkat::JsonObject::new();
let _ = json_request_body.update_string("AccountID", "54ddab14-4a8d-45cf-86be-076c99a0cea0");
let _ = json_request_body.update_string("Name", "Sales account");
let _ = json_request_body.update_string("Type", "REVENUE");
let _ = json_request_body.update_string("TaxType", "OUTPUT");
let _ = json_request_body.update_string("Description", "Income from any normal business trading activity");
let _ = json_request_body.update_string("EnablePaymentsToAccount", "false");
let _ = json_request_body.update_string("ShowInExpenseClaims", "false");
let url = "https://api.xero.com/api.xro/2.0/Accounts/54ddab14-4a8d-45cf-86be-076c99a0cea0".to_string();
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", &url, &json_request_body, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
println!("Response Status Code: {}", resp.status_code());
let json_response = chilkat::JsonObject::new();
let _ = json_response.load(&resp.body_str());
json_response.set_emit_compact(false);
println!("{}", json_response.emit().unwrap_or_default());
if resp.status_code() >= 300 {
println!("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
// {
// "Id": "430e92a8-de02-41d5-a00e-3ef899188aea",
// "Status": "OK",
// "ProviderName": "Chilkat2222",
// "DateTimeUTC": "\/Date(1587162517005)\/",
// "Accounts": [
// {
// "AccountID": "54ddab14-4a8d-45cf-86be-076c99a0cea0",
// "Code": "201",
// "Name": "Sales account",
// "Status": "ACTIVE",
// "Type": "REVENUE",
// "TaxType": "OUTPUT",
// "Description": "Income from any normal business trading activity",
// "Class": "REVENUE",
// "EnablePaymentsToAccount": false,
// "ShowInExpenseClaims": false,
// "ReportingCode": "REV",
// "ReportingCodeName": "Revenue",
// "UpdatedDateUTC": "\/Date(1587162517090+0000)\/",
// "AddToWatchlist": false
// }
// ]
// }
//
let id = json_response.string_of("Id").unwrap_or_default();
let mut status = json_response.string_of("Status").unwrap_or_default();
let provider_name = json_response.string_of("ProviderName").unwrap_or_default();
let date_time_utc = json_response.string_of("DateTimeUTC").unwrap_or_default();
let mut i = 0;
let count_i = json_response.size_of_array("Accounts");
while i < count_i {
json_response.set_i(i);
let _ = json_response.string_of("Accounts[i].AccountID").unwrap_or_default();
let _ = json_response.string_of("Accounts[i].Code").unwrap_or_default();
let _ = json_response.string_of("Accounts[i].Name").unwrap_or_default();
status = json_response.string_of("Accounts[i].Status").unwrap_or_default();
let _ = json_response.string_of("Accounts[i].Type").unwrap_or_default();
let _ = json_response.string_of("Accounts[i].TaxType").unwrap_or_default();
let _ = json_response.string_of("Accounts[i].Description").unwrap_or_default();
let _ = json_response.string_of("Accounts[i].Class").unwrap_or_default();
let _ = json_response.bool_of("Accounts[i].EnablePaymentsToAccount");
let _ = json_response.bool_of("Accounts[i].ShowInExpenseClaims");
let _ = json_response.string_of("Accounts[i].ReportingCode").unwrap_or_default();
let _ = json_response.string_of("Accounts[i].ReportingCodeName").unwrap_or_default();
let _ = json_response.string_of("Accounts[i].UpdatedDateUTC").unwrap_or_default();
let _ = json_response.bool_of("Accounts[i].AddToWatchlist");
i = i + 1;
}