Rust Requires Chilkat v11.0.0+
Rust
Constant Contact V3: Compare results for sent email activities
See more Constant Contact Examples
Compare one to ten sent primary_email or resend activities with status DONE. Supply activity IDs from your sent newsletters. Campaign IDs identify a different resource. This report requires campaign_data and permission to view campaign metrics.
Each row shows sends, unique opens, unique clicks, bounces and the last metrics refresh. The code matches results by activity ID, keeps the input order, and prints any partial-success errors alongside the available results. A missing result is reported separately from a measured zero.
Authorize the application using the same account and 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 ids = chilkat::JsonArray::new();
let _ = ids.add_string_at(-1, "FIRST_SENT_ACTIVITY_ID");
let _ = ids.add_string_at(-1, "SECOND_SENT_ACTIVITY_ID");
if (ids.size() < 1) || (ids.size() > 10) {
println!("Choose one to ten sent activity IDs.");
return;
}
let url = chilkat::StringBuilder::new();
let _ = url.append("https://api.cc.email/v3/reports/stats/email_campaign_activities/");
let mut i = 0;
while i < ids.size() {
if i > 0 {
let _ = url.append(",");
}
let _ = url.append(&ids.string_at(i).unwrap_or_default());
i = i + 1;
}
success = http.http_no_body("GET", &url.get_as_string().unwrap_or_default(), &resp).is_ok();
if (!success) && (resp.status_code() <= 0) {
println!("Read statistics: HTTP request failed.");
return;
}
if (!success) || ((resp.status_code() < 200) || (resp.status_code() >= 300)) {
println!("Read statistics: HTTP {} {}", resp.status_code(), resp.body_str());
return;
}
let report = chilkat::JsonObject::new();
if report.load(&resp.body_str()).is_err() {
println!("Expected a JSON object in the response.");
return;
}
i = 0;
while i < report.size_of_array("errors") {
report.set_i(i);
println!("{}: {}", report.string_of("errors[i].error_key").unwrap_or_default(), report.string_of("errors[i].error_message").unwrap_or_default());
i = i + 1;
}
println!("Activity ID | Sends | Unique opens | Unique clicks | Bounces | Last refresh");
let row = chilkat::JsonObject::new();
i = 0;
while i < ids.size() {
let id = ids.string_at(i).unwrap_or_default();
if report.find_record2("results", "campaign_activity_id", &id, true, &row).is_ok() {
// StringOf preserves a reported zero and leaves an unavailable individual metric blank.
println!("{} | {} | {} | {} | {} | {}", id, row.string_of("stats.em_sends").unwrap_or_default(), row.string_of("stats.em_opens").unwrap_or_default(), row.string_of("stats.em_clicks").unwrap_or_default(), row.string_of("stats.em_bounces").unwrap_or_default(), row.string_of("last_refresh_time").unwrap_or_default());
} else {
println!("{} | No statistics returned", id);
}
i = i + 1;
}