Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oVault
LOCAL oEntry
LOCAL oTokens
LOCAL nLoaded
LOCAL oHttp
LOCAL oResp
LOCAL oSelection
LOCAL cActivityId
LOCAL oTestMail
nSuccess := 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
oVault := CreateObject("Chilkat.Secrets")
oVault:Location := "local_manager"
oVault:AutoSplit := 1
oEntry := CreateObject("Chilkat.JsonObject")
oEntry:UpdateString("appName", "ConstantContactV3")
oEntry:UpdateString("service", "OAuth2")
oEntry:UpdateString("username", "my-account")
oTokens := CreateObject("Chilkat.JsonObject")
nLoaded := oVault:GetSecretJson(oEntry, oTokens)
IF (nLoaded != 1)
? "Run the desktop authorization example using this account and store."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
RETURN
ENDIF
IF (oTokens:JsonTypeOf("access_token") != 1)
? "The saved authorization has no access token."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
RETURN
ENDIF
oHttp := CreateObject("Chilkat.Http")
oHttp:RequireSslCertVerify := 1
oHttp:AuthToken := oTokens:StringOf("access_token")
oResp := CreateObject("Chilkat.HttpResponse")
// Use the selection file from the draft or campaign lookup example for this account.
oSelection := CreateObject("Chilkat.JsonObject")
nSuccess := oSelection:LoadFile("newsletter-selection.json")
cActivityId := oSelection:StringOf("campaign_activity_id")
IF ((nSuccess != 1) .OR. (cActivityId == ""))
? "Select a campaign and save its primary activity ID first."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oSelection:destroy()
RETURN
ENDIF
oHttp:SetUrlVar("activity", cActivityId)
oTestMail := CreateObject("Chilkat.JsonObject")
oTestMail:UpdateString("email_addresses[0]", "editor@example.com")
oTestMail:UpdateString("email_addresses[1]", "reviewer@example.com")
oTestMail:UpdateString("personal_message", "Please check the workshop dates and the registration link.")
nSuccess := oHttp:HttpJson("POST", "https://api.cc.email/v3/emails/activities/{$activity}/tests", oTestMail, "application/json", oResp)
IF (oResp:StatusCode == 429)
? "HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oSelection:destroy()
oTestMail:destroy()
RETURN
ENDIF
IF ((nSuccess != 1) .AND. (oResp:StatusCode <= 0))
? "Send reviewer test: HTTP request failed."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oSelection:destroy()
oTestMail:destroy()
RETURN
ENDIF
IF ((nSuccess != 1) .OR. (oResp:StatusCode != 204))
? "Send reviewer test: HTTP " + Str(oResp:StatusCode) + " " + oResp:BodyStr
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oSelection:destroy()
oTestMail:destroy()
RETURN
ENDIF
? "Test email accepted for the two reviewer addresses."
oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()
oSelection:destroy()
oTestMail:destroy()