Swift Requires Chilkat v11.0.0+
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let vault = CkoSecrets()!
vault.location = "local_manager"
vault.autoSplit = true
let entry = CkoJsonObject()!
entry.updateString(jsonPath: "appName", value: "ConstantContactV3")
entry.updateString(jsonPath: "service", value: "OAuth2")
entry.updateString(jsonPath: "username", value: "my-account")
let tokens = CkoJsonObject()!
var loaded: Bool = vault.getSecretJson(jsonId: entry, jsonOut: tokens)
if loaded != true {
print("Run the desktop authorization example using this account and store.")
return
}
if tokens.jsonType(of: "access_token").intValue != 1 {
print("The saved authorization has no access token.")
return
}
let http = CkoHttp()!
http.requireSslCertVerify = true
http.authToken = tokens.string(of: "access_token")
let resp = CkoHttpResponse()!
// Use the selection file from the draft or campaign lookup example for this account.
let selection = CkoJsonObject()!
success = selection.loadFile(path: "newsletter-selection.json")
var activityId: String? = selection.string(of: "campaign_activity_id")
if (success != true) || (activityId == "") {
print("Select a campaign and save its primary activity ID first.")
return
}
http.setUrlVar(name: "activity", value: activityId)
let testMail = CkoJsonObject()!
testMail.updateString(jsonPath: "email_addresses[0]", value: "editor@example.com")
testMail.updateString(jsonPath: "email_addresses[1]", value: "reviewer@example.com")
testMail.updateString(jsonPath: "personal_message", value: "Please check the workshop dates and the registration link.")
success = http.httpJson(verb: "POST", url: "https://api.cc.email/v3/emails/activities/{$activity}/tests", json: testMail, contentType: "application/json", response: resp)
if resp.statusCode.intValue == 429 {
print("HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance.")
return
}
if (success != true) && (resp.statusCode.intValue <= 0) {
print("Send reviewer test: HTTP request failed.")
return
}
if (success != true) || (resp.statusCode.intValue != 204) {
print("Send reviewer test: HTTP \(resp.statusCode.intValue) \(resp.bodyStr!)")
return
}
print("Test email accepted for the two reviewer addresses.")
}