Sample code for 30+ languages & platforms
Rust

GetHarvest - List Clients

See more GetHarvest Examples

Returns a list of your clients.

Chilkat Rust Downloads

Rust

// 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/clients" \
//   -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/clients", &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:

// {
//   "clients": [
//     {
//       "id": 5735776,
//       "name": "123 Industries",
//       "is_active": true,
//       "address": "123 Main St.\r\nAnytown, LA 71223",
//       "created_at": "2017-06-26T21:02:12Z",
//       "updated_at": "2017-06-26T21:34:11Z",
//       "currency": "EUR"
//     },
//     {
//       "id": 5735774,
//       "name": "ABC Corp",
//       "is_active": true,
//       "address": "456 Main St.\r\nAnytown, CT 06467",
//       "created_at": "2017-06-26T21:01:52Z",
//       "updated_at": "2017-06-26T21:27:07Z",
//       "currency": "USD"
//     }
//   ],
//   "per_page": 100,
//   "total_pages": 1,
//   "total_entries": 2,
//   "next_page": null,
//   "previous_page": null,
//   "page": 1,
//   "links": {
//     "first": "https://api.harvestapp.com/v2/clients?page=1&per_page=100",
//     "next": null,
//     "previous": null,
//     "last": "https://api.harvestapp.com/v2/clients?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("clients");
while i < count_i {
    j_resp.set_i(i);
    let _ = j_resp.int_of("clients[i].id");
    let _ = j_resp.string_of("clients[i].name").unwrap_or_default();
    let _ = j_resp.bool_of("clients[i].is_active");
    let _ = j_resp.string_of("clients[i].address").unwrap_or_default();
    let _ = j_resp.string_of("clients[i].created_at").unwrap_or_default();
    let _ = j_resp.string_of("clients[i].updated_at").unwrap_or_default();
    let _ = j_resp.string_of("clients[i].currency").unwrap_or_default();
    i = i + 1;
}