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

Delphi DLL
var
success: Boolean;
vault: HCkSecrets;
entry: HCkJsonObject;
tokens: HCkJsonObject;
loaded: Boolean;
http: HCkHttp;
resp: HCkHttpResponse;
selection: HCkJsonObject;
activityId: PWideChar;
testMail: HCkJsonObject;

begin
success := False;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
vault := CkSecrets_Create();
CkSecrets_putLocation(vault,'local_manager');
CkSecrets_putAutoSplit(vault,True);
entry := CkJsonObject_Create();
CkJsonObject_UpdateString(entry,'appName','ConstantContactV3');
CkJsonObject_UpdateString(entry,'service','OAuth2');
CkJsonObject_UpdateString(entry,'username','my-account');
tokens := CkJsonObject_Create();
loaded := CkSecrets_GetSecretJson(vault,entry,tokens);
if (loaded <> True) then
  begin
    Memo1.Lines.Add('Run the desktop authorization example using this account and store.');
    Exit;
  end;
if (CkJsonObject_JsonTypeOf(tokens,'access_token') <> 1) then
  begin
    Memo1.Lines.Add('The saved authorization has no access token.');
    Exit;
  end;
http := CkHttp_Create();
CkHttp_putRequireSslCertVerify(http,True);
CkHttp_putAuthToken(http,CkJsonObject__stringOf(tokens,'access_token'));
resp := CkHttpResponse_Create();

//  Use the selection file from the draft or campaign lookup example for this account.
selection := CkJsonObject_Create();
success := CkJsonObject_LoadFile(selection,'newsletter-selection.json');
activityId := CkJsonObject__stringOf(selection,'campaign_activity_id');
if ((success <> True) or (activityId = '')) then
  begin
    Memo1.Lines.Add('Select a campaign and save its primary activity ID first.');
    Exit;
  end;
CkHttp_SetUrlVar(http,'activity',activityId);
testMail := CkJsonObject_Create();
CkJsonObject_UpdateString(testMail,'email_addresses[0]','editor@example.com');
CkJsonObject_UpdateString(testMail,'email_addresses[1]','reviewer@example.com');
CkJsonObject_UpdateString(testMail,'personal_message','Please check the workshop dates and the registration link.');
success := CkHttp_HttpJson(http,'POST','https://api.cc.email/v3/emails/activities/{$activity}/tests',testMail,'application/json',resp);
if (CkHttpResponse_getStatusCode(resp) = 429) then
  begin
    Memo1.Lines.Add('HTTP 429: Test-send limit reached. Each reviewer counts toward the daily allowance.');
    Exit;
  end;
if ((success <> True) and (CkHttpResponse_getStatusCode(resp) <= 0)) then
  begin
    Memo1.Lines.Add('Send reviewer test: HTTP request failed.');
    Exit;
  end;
if ((success <> True) or (CkHttpResponse_getStatusCode(resp) <> 204)) then
  begin
    Memo1.Lines.Add('Send reviewer test: HTTP ' + IntToStr(CkHttpResponse_getStatusCode(resp)) + ' ' + CkHttpResponse__bodyStr(resp));
    Exit;
  end;
Memo1.Lines.Add('Test email accepted for the two reviewer addresses.');

CkSecrets_Dispose(vault);
CkJsonObject_Dispose(entry);
CkJsonObject_Dispose(tokens);
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(selection);
CkJsonObject_Dispose(testMail);