Rust Requires Chilkat v11.0.0+
Rust
Constant Contact V3: Read every page of list members
See more Constant Contact Examples
Filter the contacts collection with lists and a list ID. To query multiple lists together, supply their comma-separated IDs. Follow the returned cursor links and report the total after the last page. The default contacts query excludes deleted records. A list member can still have unsubscribed email permission. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat Rust Downloads
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 _ = http.set_url_var("list", "LIST_ID");
let url = chilkat::StringBuilder::new();
let _ = url.append("https://api.cc.email/v3/contacts?lists={$list}&limit=50");
let page = chilkat::JsonObject::new();
let mut total = 0;
while url.length() > 0 {
success = http.http_no_body("GET", &url.get_as_string().unwrap_or_default(), &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;
}
success = page.load(&resp.body_str()).is_ok();
let count = page.size_of_array("contacts");
if (!success) || (count < 0) {
println!("Expected a page of contacts.");
return;
}
let mut i = 0;
while i < count {
page.set_i(i);
println!("{} {}", page.string_of("contacts[i].contact_id").unwrap_or_default(), page.string_of("contacts[i].email_address.address").unwrap_or_default());
i = i + 1;
}
total = total + count;
url.clear();
if page.json_type_of("_links.next.href") == 1 {
let _ = url.append(&page.string_of("_links.next.href").unwrap_or_default());
// The documented cursor link is relative to api.cc.email.
if !url.starts_with("/v3/contacts?", true) {
println!("Unexpected pagination link. Stopped before following it.");
return;
}
let _ = url.prepend("https://api.cc.email");
}
}
println!("List members read: {}", total);