Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.0.0+

Constant Contact V3: Create a contact list

See more Constant Contact Examples

Create a list with a unique name and a short description. Save the returned list_id with your application’s list record and use it in the membership examples. The new list starts empty. Authorize the app first and use the same 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;
body: HCkJsonObject;
created: 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();

body := CkJsonObject_Create();
CkJsonObject_UpdateString(body,'name','Workshop announcements');
CkJsonObject_UpdateString(body,'description','People who requested workshop updates');
success := CkHttp_HttpJson(http,'POST','https://api.cc.email/v3/contact_lists',body,'application/json',resp);
if (CkHttpResponse_getStatusCode(resp) = 409) then
  begin
    Memo1.Lines.Add('A conflicting list already exists. Check the existing lists before retrying.');
    Exit;
  end;
if ((success <> True) or (CkHttpResponse_getStatusCode(resp) <> 201)) then
  begin
    Memo1.Lines.Add('Expected HTTP 201. Received ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
    if (CkHttpResponse_getStatusCode(resp) = 401) then
      begin
        Memo1.Lines.Add('Refresh the saved access token or authorize again.');
      end;
    Exit;
  end;
created := CkJsonObject_Create();
success := CkJsonObject_Load(created,CkHttpResponse__bodyStr(resp));
if (success <> True) then
  begin
    Memo1.Lines.Add('Expected a JSON response.');
    Exit;
  end;
if ((CkJsonObject_JsonTypeOf(created,'list_id') <> 1) or (CkJsonObject_StringOfEquals(created,'list_id','',True) = True)) then
  begin
    Memo1.Lines.Add('Missing list_id in the response.');
    Exit;
  end;
Memo1.Lines.Add('Created ' + CkJsonObject__stringOf(created,'name') + '. List ID: ' + CkJsonObject__stringOf(created,'list_id'));

CkSecrets_Dispose(vault);
CkJsonObject_Dispose(entry);
CkJsonObject_Dispose(tokens);
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(body);
CkJsonObject_Dispose(created);