Rust
Rust
GetHarvest - Get Client Contacts
See more GetHarvest Examples
Returns a list of your contacts.Chilkat 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();
// Implements the following CURL command:
// curl "https://api.harvestapp.com/v2/contacts" \
// -H "Authorization: Bearer ACCESS_TOKEN" \
// -H "Harvest-Account-Id: ACCOUNT_ID" \
// -H "User-Agent: MyApp (yourname@example.com)"
http.set_request_header("User-Agent", "MyApp (yourname@example.com)");
http.set_request_header("Authorization", "Bearer ACCESS_TOKEN");
http.set_request_header("Harvest-Account-Id", "ACCOUNT_ID");
let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://api.harvestapp.com/v2/contacts", &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_header());
println!("Failed.");
return;
}
// Sample JSON response:
// {
// "contacts": [
// {
// "id": 4706479,
// "title": "Owner",
// "first_name": "Jane",
// "last_name": "Doe",
// "email": "janedoe@example.com",
// "phone_office": "(203) 697-8885",
// "phone_mobile": "(203) 697-8886",
// "fax": "(203) 697-8887",
// "created_at": "2017-06-26T21:20:07Z",
// "updated_at": "2017-06-26T21:27:07Z",
// "client": {
// "id": 5735774,
// "name": "ABC Corp"
// }
// },
// {
// "id": 4706453,
// "title": "Manager",
// "first_name": "Richard",
// "last_name": "Roe",
// "email": "richardroe@example.com",
// "phone_office": "(318) 515-5905",
// "phone_mobile": "(318) 515-5906",
// "fax": "(318) 515-5907",
// "created_at": "2017-06-26T21:06:55Z",
// "updated_at": "2017-06-26T21:27:20Z",
// "client": {
// "id": 5735776,
// "name": "123 Industries"
// }
// }
// ],
// "per_page": 100,
// "total_pages": 1,
// "total_entries": 2,
// "next_page": null,
// "previous_page": null,
// "page": 1,
// "links": {
// "first": "https://api.harvestapp.com/v2/contacts?page=1&per_page=100",
// "next": null,
// "previous": null,
// "last": "https://api.harvestapp.com/v2/contacts?page=1&per_page=100"
// }
// }
// 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 per_page = j_resp.int_of("per_page");
let total_pages = j_resp.int_of("total_pages");
let total_entries = j_resp.int_of("total_entries");
let next_page = j_resp.string_of("next_page").unwrap_or_default();
let previous_page = j_resp.string_of("previous_page").unwrap_or_default();
let page = j_resp.int_of("page");
let links_first = j_resp.string_of("links.first").unwrap_or_default();
let links_next = j_resp.string_of("links.next").unwrap_or_default();
let links_previous = j_resp.string_of("links.previous").unwrap_or_default();
let links_last = j_resp.string_of("links.last").unwrap_or_default();
i = 0;
let count_i = j_resp.size_of_array("contacts");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.int_of("contacts[i].id");
let _ = j_resp.string_of("contacts[i].title").unwrap_or_default();
let _ = j_resp.string_of("contacts[i].first_name").unwrap_or_default();
let _ = j_resp.string_of("contacts[i].last_name").unwrap_or_default();
let _ = j_resp.string_of("contacts[i].email").unwrap_or_default();
let _ = j_resp.string_of("contacts[i].phone_office").unwrap_or_default();
let _ = j_resp.string_of("contacts[i].phone_mobile").unwrap_or_default();
let _ = j_resp.string_of("contacts[i].fax").unwrap_or_default();
let _ = j_resp.string_of("contacts[i].created_at").unwrap_or_default();
let _ = j_resp.string_of("contacts[i].updated_at").unwrap_or_default();
let _ = j_resp.int_of("contacts[i].client.id");
let _ = j_resp.string_of("contacts[i].client.name").unwrap_or_default();
i = i + 1;
}