Sample code for 30+ languages & platforms
PowerShell 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 PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

#  Assumes Chilkat is unlocked. See Global Unlock Sample.
$vault = New-Object Chilkat.Secrets
$vault.Location = "local_manager"
$vault.AutoSplit = $true
$entry = New-Object Chilkat.JsonObject
$entry.UpdateString("appName","ConstantContactV3")
$entry.UpdateString("service","OAuth2")
$entry.UpdateString("username","my-account")
$tokens = New-Object Chilkat.JsonObject
$loaded = $vault.GetSecretJson($entry,$tokens)
if ($loaded -ne $true) {
    $("Run the desktop authorization example using this account and store.")
    exit
}

if ($tokens.JsonTypeOf("access_token") -ne 1) {
    $("The saved authorization has no access token.")
    exit
}

$http = New-Object Chilkat.Http
$http.RequireSslCertVerify = $true
$http.AuthToken = $tokens.StringOf("access_token")
$resp = New-Object Chilkat.HttpResponse

#  Use the selection file from the draft or campaign lookup example for this account.
$selection = New-Object Chilkat.JsonObject
$success = $selection.LoadFile("newsletter-selection.json")
$activityId = $selection.StringOf("campaign_activity_id")
if (($success -ne $true) -or ($activityId -eq "")) {
    $("Select a campaign and save its primary activity ID first.")
    exit
}

$http.SetUrlVar("activity",$activityId)
$testMail = New-Object Chilkat.JsonObject
$testMail.UpdateString("email_addresses[0]","editor@example.com")
$testMail.UpdateString("email_addresses[1]","reviewer@example.com")
$testMail.UpdateString("personal_message","Please check the workshop dates and the registration link.")
$success = $http.HttpJson("POST","https://api.cc.email/v3/emails/activities/{$activity}/tests",$testMail,"application/json",$resp)
if ($resp.StatusCode -eq 429) {
    $("HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance.")
    exit
}

if (($success -ne $true) -and ($resp.StatusCode -le 0)) {
    $("Send reviewer test: HTTP request failed.")
    exit
}

if (($success -ne $true) -or ($resp.StatusCode -ne 204)) {
    $("Send reviewer test: HTTP " + $resp.StatusCode + " " + $resp.BodyStr)
    exit
}

$("Test email accepted for the two reviewer addresses.")