Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

Constant Contact V3: Find a contact by email address

See more Constant Contact Examples

Look up an exact email address across contact states, including deleted contacts. Pass the address as a query parameter so a literal plus sign survives URL encoding. Read the stored contact ID, email permission, and deletion marker. An empty contacts array means no match. Authorize the app first and use the same credential store.

Constant Contact developer guide

Chilkat Rust Downloads

Rust
let mut success = false;

// Assumes Chilkat is unlocked. See Global Unlock Sample.
let vault = chilkat::Secrets::new();
vault.set_location("local_manager");
vault.set_auto_split(true);
let entry = chilkat::JsonObject::new();
let _ = entry.update_string("appName", "ConstantContactV3");
let _ = entry.update_string("service", "OAuth2");
let _ = entry.update_string("username", "my-account");
let tokens = chilkat::JsonObject::new();
if vault.get_secret_json(&entry, &tokens).is_err() {
    println!("Run the desktop authorization example using this account and store.");
    return;
}

if tokens.json_type_of("access_token") != 1 {
    println!("The saved authorization has no access token.");
    return;
}

let http = chilkat::Http::new();
http.set_require_ssl_cert_verify(true);
http.set_auth_token(&tokens.string_of("access_token").unwrap_or_default());
let resp = chilkat::HttpResponse::new();

let query = chilkat::HttpRequest::new();
query.set_http_verb("GET");
query.add_param("email", "reader+newsletter@example.com");
query.add_param("status", "all");
success = http.http_req("https://api.cc.email/v3/contacts", &query, &resp).is_ok();
if (!success) || (resp.status_code() != 200) {
    println!("Expected HTTP 200. Received {}", resp.status_code());
    if resp.status_code() == 401 {
        println!("Refresh the saved access token or authorize again.");
    }

    return;
}

let reply = chilkat::JsonObject::new();
if reply.load(&resp.body_str()).is_err() {
    println!("Expected a JSON response.");
    return;
}

let count = reply.size_of_array("contacts");
if count < 0 {
    println!("The reply contained no contacts array.");
    return;
}

if count == 0 {
    println!("No contact has that email address.");
    return;
}

let mut i = 0;
while i < count {
    reply.set_i(i);
    println!("Contact ID: {}", reply.string_of("contacts[i].contact_id").unwrap_or_default());
    println!("Email permission: {}", reply.string_of("contacts[i].email_address.permission_to_send").unwrap_or_default());
    if reply.json_type_of("contacts[i].deleted_at") == 1 {
        println!("Deleted at: {}", reply.string_of("contacts[i].deleted_at").unwrap_or_default());
    }

    i = i + 1;
}