Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.0.0+

Constant Contact V3: Send a test email to reviewers

See more Constant Contact Examples

Read the primary activity ID from newsletter-selection.json. Replace the two reviewer addresses and send a preview with a personal note. Only the specified reviewers receive it. The request leaves the campaign schedule and contact lists alone.

Use up to five addresses per request. Each recipient counts toward the 50 daily test emails. Contact personalization and custom field values are not expanded in test messages. Success is HTTP 204 with an empty body.

Authorize the application using the same account and credential store.

Constant Contact developer guide

Chilkat Objective-C Downloads

Objective-C
#import <CkoSecrets.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoHttpResponse.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];

//  Use the selection file from the draft or campaign lookup example for this account.
CkoJsonObject *selection = [[CkoJsonObject alloc] init];
success = [selection LoadFile: @"newsletter-selection.json"];
NSString *activityId = [selection StringOf: @"campaign_activity_id"];
if ((success != YES) || (activityId == @"")) {
    NSLog(@"%@",@"Select a campaign and save its primary activity ID first.");
    return;
}

[http SetUrlVar: @"activity" value: activityId];
CkoJsonObject *testMail = [[CkoJsonObject alloc] init];
[testMail UpdateString: @"email_addresses[0]" value: @"editor@example.com"];
[testMail UpdateString: @"email_addresses[1]" value: @"reviewer@example.com"];
[testMail UpdateString: @"personal_message" value: @"Please check the workshop dates and the registration link."];
success = [http HttpJson: @"POST" url: @"https://api.cc.email/v3/emails/activities/{$activity}/tests" json: testMail contentType: @"application/json" response: resp];
if ([resp.StatusCode intValue] == 429) {
    NSLog(@"%@",@"HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance.");
    return;
}

if ((success != YES) && ([resp.StatusCode intValue] <= 0)) {
    NSLog(@"%@",@"Send reviewer test: HTTP request failed.");
    return;
}

if ((success != YES) || ([resp.StatusCode intValue] != 204)) {
    NSLog(@"%@%d%@%@",@"Send reviewer test: HTTP ",[resp.StatusCode intValue],@" ",resp.BodyStr);
    return;
}

NSLog(@"%@",@"Test email accepted for the two reviewer addresses.");