Rust
Rust
MYOB: Get List of Company Files
See more MYOB Examples
Gets a list of company files.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();
http.set_auth_token("ACCESS_TOKEN");
http.set_accept("application/json");
http.set_request_header("x-myobapi-key", "MYOB_API_KEY");
http.set_request_header("x-myobapi-version", "v2");
let Ok(str_resp) = http.quick_get_str("https://ar1.api.myob.com/accountright") else {
println!("{}", http.last_error_text());
return;
};
println!("Response Status Code: {}", http.last_status());
let json_response = chilkat::JsonObject::new();
let _ = json_response.load(&str_resp);
json_response.set_emit_compact(false);
println!("{}", json_response.emit().unwrap_or_default());
if http.last_status() != 200 {
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": "d2014f64-ffdf-487b-8d12-67a20976aca6",
// "Name": "Internal Sandbox API",
// "LibraryPath": "Internal Sandbox API",
// "ProductVersion": "2013.0",
// "ProductLevel": {
// "Code": 20,
// "Name": "Standard"
// },
// "CheckedOutDate": "2013-06-11T01:47:47.0065514",
// "CheckedOutBy": "developers@myob.com",
// "Uri": "{cf_uri}",
// "Country": "AU"
// }
//
let id = json_response.string_of("Id").unwrap_or_default();
let name = json_response.string_of("Name").unwrap_or_default();
let library_path = json_response.string_of("LibraryPath").unwrap_or_default();
let product_version = json_response.string_of("ProductVersion").unwrap_or_default();
let product_level_code = json_response.int_of("ProductLevel.Code");
let product_level_name = json_response.string_of("ProductLevel.Name").unwrap_or_default();
let checked_out_date = json_response.string_of("CheckedOutDate").unwrap_or_default();
let checked_out_by = json_response.string_of("CheckedOutBy").unwrap_or_default();
let uri = json_response.string_of("Uri").unwrap_or_default();
let country = json_response.string_of("Country").unwrap_or_default();