Objective-C Requires Chilkat v11.0.0+
Objective-C
Constant Contact V3: Create a contact list
See more Constant Contact Examples
Create a list with a unique name and a short description. Save the returned list_id with your application’s list record and use it in the membership examples. The new list starts empty. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat Objective-C Downloads
#import <CkoSecrets.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoHttpResponse.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];
CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateString: @"name" value: @"Workshop announcements"];
[body UpdateString: @"description" value: @"People who requested workshop updates"];
success = [http HttpJson: @"POST" url: @"https://api.cc.email/v3/contact_lists" json: body contentType: @"application/json" response: resp];
if ([resp.StatusCode intValue] == 409) {
NSLog(@"%@",@"A conflicting list already exists. Check the existing lists before retrying.");
return;
}
if ((success != YES) || ([resp.StatusCode intValue] != 201)) {
NSLog(@"%@%d",@"Expected HTTP 201. Received ",[resp.StatusCode intValue]);
if ([resp.StatusCode intValue] == 401) {
NSLog(@"%@",@"Refresh the saved access token or authorize again.");
}
return;
}
CkoJsonObject *created = [[CkoJsonObject alloc] init];
success = [created Load: resp.BodyStr];
if (success != YES) {
NSLog(@"%@",@"Expected a JSON response.");
return;
}
if (([[created JsonTypeOf: @"list_id"] intValue] != 1) || ([created StringOfEquals: @"list_id" value: @"" caseSensitive: YES] == YES)) {
NSLog(@"%@",@"Missing list_id in the response.");
return;
}
NSLog(@"%@%@%@%@",@"Created ",[created StringOf: @"name"],@". List ID: ",[created StringOf: @"list_id"]);