Rust
Rust
GetHarvest - Test Personal Access Token
See more GetHarvest Examples
Demonstrates how to test your GetHarvest Personal Access TokenChilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
http.set_request_header("User-Agent", "Harvest API Example");
http.set_request_header("Harvest-Account-ID", "ACCOUNT_ID");
http.set_request_header("Authorization", "Bearer ACCESS_TOKEN");
let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://api.harvestapp.com/api/v2/users/me.json", &sb_response_body).is_err() {
println!("{}", http.last_error_text());
return;
}
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
let resp_status_code = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", http.last_response_header());
return;
}
// Sample JSON response:
// {
// "id": 2826142,
// "first_name": "Joe",
// "last_name": "Johnson",
// "email": "joe@example.com",
// "telephone": "",
// "timezone": "Central Time (US & Canada)",
// "weekly_capacity": 126000,
// "has_access_to_all_future_projects": false,
// "is_contractor": false,
// "is_admin": true,
// "is_project_manager": false,
// "can_see_rates": true,
// "can_create_projects": true,
// "can_create_invoices": true,
// "is_active": true,
// "created_at": "2019-06-06T15:57:58Z",
// "updated_at": "2019-06-06T15:58:32Z",
// "default_hourly_rate": 175.0,
// "cost_rate": 60.0,
// "roles": [
// "role1",
// "role2"
// ],
// "avatar_url": "https://d3s3969qhosaug.cloudfront.net/default-avatars/4d46.png?1559836678"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let mut i: i32 = 0;
let id = j_resp.int_of("id");
let first_name = j_resp.string_of("first_name").unwrap_or_default();
let last_name = j_resp.string_of("last_name").unwrap_or_default();
let email = j_resp.string_of("email").unwrap_or_default();
let telephone = j_resp.string_of("telephone").unwrap_or_default();
let timezone = j_resp.string_of("timezone").unwrap_or_default();
let weekly_capacity = j_resp.int_of("weekly_capacity");
let has_access_to_all_future_projects = j_resp.bool_of("has_access_to_all_future_projects");
let is_contractor = j_resp.bool_of("is_contractor");
let is_admin = j_resp.bool_of("is_admin");
let is_project_manager = j_resp.bool_of("is_project_manager");
let can_see_rates = j_resp.bool_of("can_see_rates");
let can_create_projects = j_resp.bool_of("can_create_projects");
let can_create_invoices = j_resp.bool_of("can_create_invoices");
let is_active = j_resp.bool_of("is_active");
let created_at = j_resp.string_of("created_at").unwrap_or_default();
let updated_at = j_resp.string_of("updated_at").unwrap_or_default();
let default_hourly_rate = j_resp.string_of("default_hourly_rate").unwrap_or_default();
let cost_rate = j_resp.string_of("cost_rate").unwrap_or_default();
let avatar_url = j_resp.string_of("avatar_url").unwrap_or_default();
i = 0;
let count_i = j_resp.size_of_array("roles");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.string_of("roles[i]").unwrap_or_default();
i = i + 1;
}