PowerBuilder Requires Chilkat v11.0.0+
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Vault
oleobject loo_Entry
oleobject loo_Tokens
long li_Loaded
oleobject loo_Http
oleobject loo_Resp
oleobject loo_Selection
string ls_ActivityId
oleobject loo_TestMail
li_Success = 0
// Assumes Chilkat is unlocked. See Global Unlock Sample.
loo_Vault = create oleobject
li_rc = loo_Vault.ConnectToNewObject("Chilkat.Secrets")
if li_rc < 0 then
destroy loo_Vault
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Vault.Location = "local_manager"
loo_Vault.AutoSplit = 1
loo_Entry = create oleobject
li_rc = loo_Entry.ConnectToNewObject("Chilkat.JsonObject")
loo_Entry.UpdateString("appName","ConstantContactV3")
loo_Entry.UpdateString("service","OAuth2")
loo_Entry.UpdateString("username","my-account")
loo_Tokens = create oleobject
li_rc = loo_Tokens.ConnectToNewObject("Chilkat.JsonObject")
li_Loaded = loo_Vault.GetSecretJson(loo_Entry,loo_Tokens)
if li_Loaded <> 1 then
Write-Debug "Run the desktop authorization example using this account and store."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
return
end if
if loo_Tokens.JsonTypeOf("access_token") <> 1 then
Write-Debug "The saved authorization has no access token."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
return
end if
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
loo_Http.RequireSslCertVerify = 1
loo_Http.AuthToken = loo_Tokens.StringOf("access_token")
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")
// Use the selection file from the draft or campaign lookup example for this account.
loo_Selection = create oleobject
li_rc = loo_Selection.ConnectToNewObject("Chilkat.JsonObject")
li_Success = loo_Selection.LoadFile("newsletter-selection.json")
ls_ActivityId = loo_Selection.StringOf("campaign_activity_id")
if (li_Success <> 1) OR (ls_ActivityId = "") then
Write-Debug "Select a campaign and save its primary activity ID first."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Selection
return
end if
loo_Http.SetUrlVar("activity",ls_ActivityId)
loo_TestMail = create oleobject
li_rc = loo_TestMail.ConnectToNewObject("Chilkat.JsonObject")
loo_TestMail.UpdateString("email_addresses[0]","editor@example.com")
loo_TestMail.UpdateString("email_addresses[1]","reviewer@example.com")
loo_TestMail.UpdateString("personal_message","Please check the workshop dates and the registration link.")
li_Success = loo_Http.HttpJson("POST","https://api.cc.email/v3/emails/activities/{$activity}/tests",loo_TestMail,"application/json",loo_Resp)
if loo_Resp.StatusCode = 429 then
Write-Debug "HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Selection
destroy loo_TestMail
return
end if
if (li_Success <> 1) AND (loo_Resp.StatusCode <= 0) then
Write-Debug "Send reviewer test: HTTP request failed."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Selection
destroy loo_TestMail
return
end if
if (li_Success <> 1) OR (loo_Resp.StatusCode <> 204) then
Write-Debug "Send reviewer test: HTTP " + string(loo_Resp.StatusCode) + " " + loo_Resp.BodyStr
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Selection
destroy loo_TestMail
return
end if
Write-Debug "Test email accepted for the two reviewer addresses."
destroy loo_Vault
destroy loo_Entry
destroy loo_Tokens
destroy loo_Http
destroy loo_Resp
destroy loo_Selection
destroy loo_TestMail