Rust
Rust
SMSAPI - List Contacts
See more SMSAPI Examples
List ContactsChilkat 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 -X GET -H "Authorization: Bearer token_api_oauth" https://api.smsapi.com/contacts?phone_number=48500000000
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Adds the "Authorization: Bearer token_api_oauth" header.
http.set_auth_token("token_api_oauth");
let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://api.smsapi.com/contacts?phone_number=48500000000", &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:
// (Sample code for parsing the JSON response is shown below)
// {
// "size": 1,
// "collection": [
// {
// "id": "5b83ba81a788494a0469490f",
// "first_name": "name",
// "last_name": "surname",
// "phone_number": "48500000000",
// "email": "bok@smsapi.com",
// "gender": "male",
// "city": "City",
// "country": "Poland",
// "source": "source",
// "date_created": "2018-08-27T10:46:57+02:00",
// "date_updated": "2018-08-27T10:46:57+02:00",
// "groups": [
// {
// "id": "59a3ca1fa78849062837cd0c",
// "name": "default",
// "date_created": "2017-08-28T09:45:35+02:00",
// "date_updated": "2017-08-28T09:45:35+02:00",
// "description": "",
// "created_by": "login",
// "idx": null,
// "contact_expire_after": null,
// "contacts_count": null
// }
// ]
// }
// ]
// }
// 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 date_created = chilkat::DtObj::new();
let date_updated = chilkat::DtObj::new();
let mut j: i32 = 0;
let mut count_j: i32 = 0;
let size = j_resp.int_of("size");
let mut i = 0;
let count_i = j_resp.size_of_array("collection");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.string_of("collection[i].id").unwrap_or_default();
let _ = j_resp.string_of("collection[i].first_name").unwrap_or_default();
let _ = j_resp.string_of("collection[i].last_name").unwrap_or_default();
let _ = j_resp.string_of("collection[i].phone_number").unwrap_or_default();
let _ = j_resp.string_of("collection[i].email").unwrap_or_default();
let _ = j_resp.string_of("collection[i].gender").unwrap_or_default();
let _ = j_resp.string_of("collection[i].city").unwrap_or_default();
let _ = j_resp.string_of("collection[i].country").unwrap_or_default();
let _ = j_resp.string_of("collection[i].source").unwrap_or_default();
let _ = j_resp.dt_of("collection[i].date_created", false, &date_created);
let _ = j_resp.dt_of("collection[i].date_updated", false, &date_updated);
j = 0;
count_j = j_resp.size_of_array("collection[i].groups");
while j < count_j {
j_resp.set_j(j);
let _ = j_resp.string_of("collection[i].groups[j].id").unwrap_or_default();
let _ = j_resp.string_of("collection[i].groups[j].name").unwrap_or_default();
let _ = j_resp.dt_of("collection[i].groups[j].date_created", false, &date_created);
let _ = j_resp.dt_of("collection[i].groups[j].date_updated", false, &date_updated);
let _ = j_resp.string_of("collection[i].groups[j].description").unwrap_or_default();
let _ = j_resp.string_of("collection[i].groups[j].created_by").unwrap_or_default();
let _ = j_resp.string_of("collection[i].groups[j].idx").unwrap_or_default();
let _ = j_resp.string_of("collection[i].groups[j].contact_expire_after").unwrap_or_default();
let _ = j_resp.string_of("collection[i].groups[j].contacts_count").unwrap_or_default();
j = j + 1;
}
i = i + 1;
}