Rust Requires Chilkat v11.0.0+
Rust
Activix CRM Create a Communication
See more Activix CRM Examples
Create a communication. Returns the created communication.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": "LEAD_ID",
// "method": "phone",
// "type": "outgoing",
// "call_status": "calling"
// }
// 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_string("lead_id", "LEAD_ID");
let _ = json_request_body.update_string("method", "phone");
let _ = json_request_body.update_string("type", "outgoing");
let _ = json_request_body.update_string("call_status", "calling");
let url = "https://crm.activix.ca/api/v2/communications".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": 5411998,
// "created_at": "2019-06-10T13:01:40+00:00",
// "updated_at": "2019-06-10T13:01:40+00:00",
// "lead_id": 7135833,
// "user_id": 13705,
// "method": "phone",
// "type": "outgoing",
// "email_subject": null,
// "email_body": null,
// "email_client": null,
// "email_user": null,
// "call_duration": null,
// "call_phone": null,
// "call_status": "calling"
// }
// }
//
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_user_id = json_response.int_of("data.user_id");
let data_method = json_response.string_of("data.method").unwrap_or_default();
let data_type = json_response.string_of("data.type").unwrap_or_default();
let data_email_subject = json_response.string_of("data.email_subject").unwrap_or_default();
let data_email_body = json_response.string_of("data.email_body").unwrap_or_default();
let data_email_client = json_response.string_of("data.email_client").unwrap_or_default();
let data_email_user = json_response.string_of("data.email_user").unwrap_or_default();
let data_call_duration = json_response.string_of("data.call_duration").unwrap_or_default();
let data_call_phone = json_response.string_of("data.call_phone").unwrap_or_default();
let data_call_status = json_response.string_of("data.call_status").unwrap_or_default();