Objective-C Requires Chilkat v11.0.0+
Objective-C
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 Objective-C Downloads
#import <CkoSecrets.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoJsonArray.h>
#import <CkoStringBuilder.h>
#import <NSString.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkoSecrets *vault = [[CkoSecrets alloc] init];
vault.Location = @"local_manager";
vault.AutoSplit = YES;
CkoJsonObject *entry = [[CkoJsonObject alloc] init];
[entry UpdateString: @"appName" value: @"ConstantContactV3"];
[entry UpdateString: @"service" value: @"OAuth2"];
[entry UpdateString: @"username" value: @"my-account"];
CkoJsonObject *tokens = [[CkoJsonObject alloc] init];
BOOL loaded = [vault GetSecretJson: entry jsonOut: tokens];
if (loaded != YES) {
NSLog(@"%@",@"Run the desktop authorization example using this account and store.");
return;
}
if ([[tokens JsonTypeOf: @"access_token"] intValue] != 1) {
NSLog(@"%@",@"The saved authorization has no access token.");
return;
}
CkoHttp *http = [[CkoHttp alloc] init];
http.RequireSslCertVerify = YES;
http.AuthToken = [tokens StringOf: @"access_token"];
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
CkoJsonArray *ids = [[CkoJsonArray alloc] init];
[ids AddStringAt: [NSNumber numberWithInt: -1] value: @"FIRST_SENT_ACTIVITY_ID"];
[ids AddStringAt: [NSNumber numberWithInt: -1] value: @"SECOND_SENT_ACTIVITY_ID"];
if (([ids.Size intValue] < 1) || ([ids.Size intValue] > 10)) {
NSLog(@"%@",@"Choose one to ten sent activity IDs.");
return;
}
CkoStringBuilder *url = [[CkoStringBuilder alloc] init];
[url Append: @"https://api.cc.email/v3/reports/stats/email_campaign_activities/"];
int i = 0;
while ((i < [ids.Size intValue])) {
if (i > 0) {
[url Append: @","];
}
[url Append: [ids StringAt: [NSNumber numberWithInt: i]]];
i = i + 1;
}
success = [http HttpNoBody: @"GET" url: [url GetAsString] response: resp];
if ((success != YES) && ([resp.StatusCode intValue] <= 0)) {
NSLog(@"%@",@"Read statistics: HTTP request failed.");
return;
}
if ((success != YES) || (([resp.StatusCode intValue] < 200) || ([resp.StatusCode intValue] >= 300))) {
NSLog(@"%@%d%@%@",@"Read statistics: HTTP ",[resp.StatusCode intValue],@" ",resp.BodyStr);
return;
}
CkoJsonObject *report = [[CkoJsonObject alloc] init];
success = [report Load: resp.BodyStr];
if (success != YES) {
NSLog(@"%@",@"Expected a JSON object in the response.");
return;
}
i = 0;
while ((i < [[report SizeOfArray: @"errors"] intValue])) {
report.I = [NSNumber numberWithInt: i];
NSLog(@"%@%@%@",[report StringOf: @"errors[i].error_key"],@": ",[report StringOf: @"errors[i].error_message"]);
i = i + 1;
}
NSLog(@"%@",@"Activity ID | Sends | Unique opens | Unique clicks | Bounces | Last refresh");
CkoJsonObject *row = [[CkoJsonObject alloc] init];
i = 0;
while ((i < [ids.Size intValue])) {
NSString *id = [ids StringAt: [NSNumber numberWithInt: i]];
success = [report FindRecord2: @"results" relPath: @"campaign_activity_id" value: id caseSensitive: YES jsonObj: row];
if (success == YES) {
// StringOf preserves a reported zero and leaves an unavailable individual metric blank.
NSLog(@"%@%@%@%@%@%@%@%@%@%@%@",id,@" | ",[row StringOf: @"stats.em_sends"],@" | ",[row StringOf: @"stats.em_opens"],@" | ",[row StringOf: @"stats.em_clicks"]
,@" | ",[row StringOf: @"stats.em_bounces"],@" | ",[row StringOf: @"last_refresh_time"]);
}
else {
NSLog(@"%@%@",id,@" | No statistics returned");
}
i = i + 1;
}