DataFlex Requires Chilkat v11.0.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoVault
Variant vEntry
Handle hoEntry
Variant vTokens
Handle hoTokens
Boolean iLoaded
Handle hoHttp
Variant vResp
Handle hoResp
Handle hoSelection
String sActivityId
Variant vTestMail
Handle hoTestMail
String sTemp1
Integer iTemp1
Move False To iSuccess
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Get Create (RefClass(cComChilkatSecrets)) To hoVault
If (Not(IsComObjectCreated(hoVault))) Begin
Send CreateComObject of hoVault
End
Set ComLocation Of hoVault To "local_manager"
Set ComAutoSplit Of hoVault To True
Get Create (RefClass(cComChilkatJsonObject)) To hoEntry
If (Not(IsComObjectCreated(hoEntry))) Begin
Send CreateComObject of hoEntry
End
Get ComUpdateString Of hoEntry "appName" "ConstantContactV3" To iSuccess
Get ComUpdateString Of hoEntry "service" "OAuth2" To iSuccess
Get ComUpdateString Of hoEntry "username" "my-account" To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoTokens
If (Not(IsComObjectCreated(hoTokens))) Begin
Send CreateComObject of hoTokens
End
Get pvComObject of hoEntry to vEntry
Get pvComObject of hoTokens to vTokens
Get ComGetSecretJson Of hoVault vEntry vTokens To iLoaded
If (iLoaded <> True) Begin
Showln "Run the desktop authorization example using this account and store."
Procedure_Return
End
Get ComJsonTypeOf Of hoTokens "access_token" To iTemp1
If (iTemp1 <> 1) Begin
Showln "The saved authorization has no access token."
Procedure_Return
End
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComRequireSslCertVerify Of hoHttp To True
Get ComStringOf Of hoTokens "access_token" To sTemp1
Set ComAuthToken Of hoHttp To sTemp1
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
// Use the selection file from the draft or campaign lookup example for this account.
Get Create (RefClass(cComChilkatJsonObject)) To hoSelection
If (Not(IsComObjectCreated(hoSelection))) Begin
Send CreateComObject of hoSelection
End
Get ComLoadFile Of hoSelection "newsletter-selection.json" To iSuccess
Get ComStringOf Of hoSelection "campaign_activity_id" To sActivityId
If ((iSuccess <> True) Or (sActivityId = "")) Begin
Showln "Select a campaign and save its primary activity ID first."
Procedure_Return
End
Get ComSetUrlVar Of hoHttp "activity" sActivityId To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoTestMail
If (Not(IsComObjectCreated(hoTestMail))) Begin
Send CreateComObject of hoTestMail
End
Get ComUpdateString Of hoTestMail "email_addresses[0]" "editor@example.com" To iSuccess
Get ComUpdateString Of hoTestMail "email_addresses[1]" "reviewer@example.com" To iSuccess
Get ComUpdateString Of hoTestMail "personal_message" "Please check the workshop dates and the registration link." To iSuccess
Get pvComObject of hoTestMail to vTestMail
Get pvComObject of hoResp to vResp
Get ComHttpJson Of hoHttp "POST" "https://api.cc.email/v3/emails/activities/{$activity}/tests" vTestMail "application/json" vResp To iSuccess
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 = 429) Begin
Showln "HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance."
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
If ((iSuccess <> True) And (iTemp1 <= 0)) Begin
Showln "Send reviewer test: HTTP request failed."
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
If ((iSuccess <> True) Or (iTemp1 <> 204)) Begin
Get ComStatusCode Of hoResp To iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln "Send reviewer test: HTTP " iTemp1 " " sTemp1
Procedure_Return
End
Showln "Test email accepted for the two reviewer addresses."
End_Procedure