B4X Requires Chilkat v11.0.0+
B4X
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 B4X Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim vault As ChilkatSecrets
vault.Initialize("vault")
vault.Location = "local_manager"
vault.AutoSplit = True
Dim entry As ChilkatJsonObject
entry.Initialize
entry.UpdateString("appName", "ConstantContactV3")
entry.UpdateString("service", "OAuth2")
entry.UpdateString("username", "my-account")
Dim tokens As ChilkatJsonObject
tokens.Initialize
Dim loaded As Boolean = vault.GetSecretJson(entry, tokens)
If loaded <> True Then
Log("Run the desktop authorization example using this account and store.")
Return
End If
If tokens.JsonTypeOf("access_token") <> 1 Then
Log("The saved authorization has no access token.")
Return
End If
Dim http As ChilkatHttp
http.Initialize("http")
http.RequireSslCertVerify = True
http.AuthToken = tokens.StringOf("access_token")
Dim resp As ChilkatHttpResponse
resp.Initialize
' Use the selection file from the draft or campaign lookup example for this account.
Dim selection As ChilkatJsonObject
selection.Initialize
success = selection.LoadFile("newsletter-selection.json")
Dim activityId As String = selection.StringOf("campaign_activity_id")
If (success <> True) Or (activityId = "") Then
Log("Select a campaign and save its primary activity ID first.")
Return
End If
http.SetUrlVar("activity", activityId)
Dim testMail As ChilkatJsonObject
testMail.Initialize
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 = 429 Then
Log("HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance.")
Return
End If
If (success <> True) And (resp.StatusCode <= 0) Then
Log("Send reviewer test: HTTP request failed.")
Return
End If
If (success <> True) Or (resp.StatusCode <> 204) Then
Log("Send reviewer test: HTTP " & resp.StatusCode & " " & resp.BodyStr)
Return
End If
Log("Test email accepted for the two reviewer addresses.")