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

Constant Contact V3: Find a contact list by name

See more Constant Contact Examples

Start with the full list name from the Constant Contact account. Read its list_id and the number of active, mailable contacts. Use the ID for list membership operations or campaign targeting. This lookup requires contact_data.

Authorize the application using the same account and 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();

// Use the full display name. AddParam encodes spaces and punctuation.
let list_name = "Workshop announcements".to_string();
let query = chilkat::HttpRequest::new();
query.set_http_verb("GET");
query.add_param("name", &list_name);
query.add_param("status", "active");
query.add_param("include_membership_count", "active");
success = http.http_req("https://api.cc.email/v3/contact_lists", &query, &resp).is_ok();
if (!success) && (resp.status_code() <= 0) {
    println!("Look up list: HTTP request failed.");
    return;
}

if (!success) || (resp.status_code() != 200) {
    println!("Look up list: HTTP {} {}", resp.status_code(), resp.body_str());
    return;
}

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

if matches.size_of_array("lists") == 0 {
    println!("No active email list named {}", list_name);
    return;
}

if (matches.size_of_array("lists") != 1) || (!matches.string_of_equals("lists[0].name", &list_name, true)) {
    println!("Expected one exact list name.");
    return;
}

let list_id = matches.string_of("lists[0].list_id").unwrap_or_default();
if list_id == "" {
    println!("Missing list ID.");
    return;
}

println!("{} | List ID: {} | Mailable contacts: {}", list_name, list_id, matches.int_of("lists[0].membership_count"));