Rust
Rust
Constant Contact - Restore a Deleted Contact
See more Constant Contact Examples
Restores a previously deleted contact with a given id.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 -X PUT \
// https://api.cc.email/v3/contacts/{contact_id} \
// -H 'Accept: application/json' \
// -H 'Authorization: Bearer {access_token}' \
// -H 'Cache-Control: no-cache' \
// -H 'Content-Type: application/json' \
// -d '{
//
// "first_name": "John",
// "last_name": "Byrd",
// "email_address": {
// "address": "example@example.com",
// "permission_to_send": "explicit"
// },
// "update_source": "Contact",
// "list_memberships":["{list_id1}","{list_id2}"]
// }'
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "first_name": "John",
// "last_name": "Byrd",
// "email_address": {
// "address": "example@example.com",
// "permission_to_send": "explicit"
// },
// "update_source": "Contact",
// "list_memberships": [
// "{list_id1}",
// "{list_id2}"
// ]
// }
let json = chilkat::JsonObject::new();
let _ = json.update_string("first_name", "John");
let _ = json.update_string("last_name", "Byrd");
let _ = json.update_string("email_address.address", "example@example.com");
let _ = json.update_string("email_address.permission_to_send", "explicit");
let _ = json.update_string("update_source", "Contact");
let _ = json.update_string("list_memberships[0]", "{list_id1}");
let _ = json.update_string("list_memberships[1]", "{list_id2}");
// Adds the "Authorization: Bearer ACCESS_TOKEN" header.
http.set_auth_token("ACCESS_TOKEN");
http.set_request_header("Accept", "application/json");
http.set_request_header("Content-Type", "application/json");
http.set_request_header("Cache-Control", "no-cache");
let sb_request_body = chilkat::StringBuilder::new();
let _ = json.emit_sb(&sb_request_body);
let resp = chilkat::HttpResponse::new();
if http.http_sb("PUT", "https://api.cc.email/v3/contacts/{contact_id}", &sb_request_body, "utf-8", "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let sb_response_body = chilkat::StringBuilder::new();
let _ = resp.get_body_sb(&sb_response_body);
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 = resp.status_code();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", resp.header());
println!("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "contact_id": "{contact_id}",
// "first_name": "John",
// "last_name": "Byrd",
// "update_source": "Contact",
// "create_source": "Account",
// "created_at": "2013-04-01T15:07:07-04:00",
// "updated_at": "2018-02-20T16:47:40-05:00",
// "email_address": {
// "address": "example@example.com",
// "permission_to_send": "implicit",
// "created_at": "2013-04-01T15:07:07-04:00",
// "updated_at": "2018-02-20T16:47:40-05:00",
// "opt_in_source": "Account",
// "opt_in_date": "2015-03-17T11:13:28-04:00",
// "confirm_status": "off"
// }
// }
// 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 contact_id = j_resp.string_of("contact_id").unwrap_or_default();
let first_name = j_resp.string_of("first_name").unwrap_or_default();
let last_name = j_resp.string_of("last_name").unwrap_or_default();
let update_source = j_resp.string_of("update_source").unwrap_or_default();
let create_source = j_resp.string_of("create_source").unwrap_or_default();
let created_at = j_resp.string_of("created_at").unwrap_or_default();
let updated_at = j_resp.string_of("updated_at").unwrap_or_default();
let email_address_address = j_resp.string_of("email_address.address").unwrap_or_default();
let email_address_permission_to_send = j_resp.string_of("email_address.permission_to_send").unwrap_or_default();
let email_address_created_at = j_resp.string_of("email_address.created_at").unwrap_or_default();
let email_address_updated_at = j_resp.string_of("email_address.updated_at").unwrap_or_default();
let email_address_opt_in_source = j_resp.string_of("email_address.opt_in_source").unwrap_or_default();
let email_address_opt_in_date = j_resp.string_of("email_address.opt_in_date").unwrap_or_default();
let email_address_confirm_status = j_resp.string_of("email_address.confirm_status").unwrap_or_default();