Rust Requires Chilkat v11.0.0+
Rust
Activix CRM Create a Phone
See more Activix CRM Examples
Create a phone. Returns the created phone.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");
// The following JSON is sent in the request body:
// {
// "lead_id": 7135833,
// "number": "+15141234455",
// "type": "home"
// }
// Use this online tool to generate the code from sample JSON:
// Generate Code to Create JSON
let json_request_body = chilkat::JsonObject::new();
let _ = json_request_body.update_int("lead_id", 7135833);
let _ = json_request_body.update_string("number", "+15141234455");
let _ = json_request_body.update_string("type", "home");
let url = "https://crm.activix.ca/api/v2/lead-phones".to_string();
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", &url, &json_request_body, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
println!("Response Status Code: {}", resp.status_code());
let json_response = chilkat::JsonObject::new();
let _ = json_response.load(&resp.body_str());
json_response.set_emit_compact(false);
println!("{}", json_response.emit().unwrap_or_default());
if resp.status_code() >= 300 {
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
// {
// "data": {
// "id": 34566,
// "created_at": "2018-04-09T18:05:00+00:00",
// "updated_at": "2018-04-09T18:05:00+00:00",
// "lead_id": 3466512,
// "number": "+15141234455",
// ...
// }
// }
let data_id = json_response.int_of("data.id");
let data_created_at = json_response.string_of("data.created_at").unwrap_or_default();
let data_updated_at = json_response.string_of("data.updated_at").unwrap_or_default();
let data_lead_id = json_response.int_of("data.lead_id");
let data_extension = json_response.string_of("data.extension").unwrap_or_default();
let data_number = json_response.string_of("data.number").unwrap_or_default();
let data_type = json_response.string_of("data.type").unwrap_or_default();
let data_valid = json_response.bool_of("data.valid");
let data_validated = json_response.string_of("data.validated").unwrap_or_default();
let data_mobile = json_response.bool_of("data.mobile");