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

Visual FoxPro
LOCAL lnSuccess
LOCAL loVault
LOCAL loEntry
LOCAL loTokens
LOCAL lnLoaded
LOCAL loHttp
LOCAL loResp
LOCAL loSelection
LOCAL lcActivityId
LOCAL loTestMail

lnSuccess = 0

*  Assumes Chilkat is unlocked. See Global Unlock Sample.
loVault = CreateObject('Chilkat.Secrets')
loVault.Location = "local_manager"
loVault.AutoSplit = 1
loEntry = CreateObject('Chilkat.JsonObject')
loEntry.UpdateString("appName","ConstantContactV3")
loEntry.UpdateString("service","OAuth2")
loEntry.UpdateString("username","my-account")
loTokens = CreateObject('Chilkat.JsonObject')
lnLoaded = loVault.GetSecretJson(loEntry,loTokens)
IF (lnLoaded <> 1) THEN
    ? "Run the desktop authorization example using this account and store."
    RELEASE loVault
    RELEASE loEntry
    RELEASE loTokens
    CANCEL
ENDIF

IF (loTokens.JsonTypeOf("access_token") <> 1) THEN
    ? "The saved authorization has no access token."
    RELEASE loVault
    RELEASE loEntry
    RELEASE loTokens
    CANCEL
ENDIF

loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
loHttp.AuthToken = loTokens.StringOf("access_token")
loResp = CreateObject('Chilkat.HttpResponse')

*  Use the selection file from the draft or campaign lookup example for this account.
loSelection = CreateObject('Chilkat.JsonObject')
lnSuccess = loSelection.LoadFile("newsletter-selection.json")
lcActivityId = loSelection.StringOf("campaign_activity_id")
IF ((lnSuccess <> 1) OR (lcActivityId = "")) THEN
    ? "Select a campaign and save its primary activity ID first."
    RELEASE loVault
    RELEASE loEntry
    RELEASE loTokens
    RELEASE loHttp
    RELEASE loResp
    RELEASE loSelection
    CANCEL
ENDIF

loHttp.SetUrlVar("activity",lcActivityId)
loTestMail = CreateObject('Chilkat.JsonObject')
loTestMail.UpdateString("email_addresses[0]","editor@example.com")
loTestMail.UpdateString("email_addresses[1]","reviewer@example.com")
loTestMail.UpdateString("personal_message","Please check the workshop dates and the registration link.")
lnSuccess = loHttp.HttpJson("POST","https://api.cc.email/v3/emails/activities/{$activity}/tests",loTestMail,"application/json",loResp)
IF (loResp.StatusCode = 429) THEN
    ? "HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance."
    RELEASE loVault
    RELEASE loEntry
    RELEASE loTokens
    RELEASE loHttp
    RELEASE loResp
    RELEASE loSelection
    RELEASE loTestMail
    CANCEL
ENDIF

IF ((lnSuccess <> 1) AND (loResp.StatusCode <= 0)) THEN
    ? "Send reviewer test: HTTP request failed."
    RELEASE loVault
    RELEASE loEntry
    RELEASE loTokens
    RELEASE loHttp
    RELEASE loResp
    RELEASE loSelection
    RELEASE loTestMail
    CANCEL
ENDIF

IF ((lnSuccess <> 1) OR (loResp.StatusCode <> 204)) THEN
    ? "Send reviewer test: HTTP " + STR(loResp.StatusCode) + " " + loResp.BodyStr
    RELEASE loVault
    RELEASE loEntry
    RELEASE loTokens
    RELEASE loHttp
    RELEASE loResp
    RELEASE loSelection
    RELEASE loTestMail
    CANCEL
ENDIF

? "Test email accepted for the two reviewer addresses."

RELEASE loVault
RELEASE loEntry
RELEASE loTokens
RELEASE loHttp
RELEASE loResp
RELEASE loSelection
RELEASE loTestMail