Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Constant Contact V3: Delete a contact by ID
See more Constant Contact Examples
Use the ID of the contact selected for deletion. Deletion removes all list memberships and sets the deletion timestamp. Unsubscribing is a separate operation that changes permission to send. A successful delete returns HTTP 204 with an empty body. To bring the record back, see Restore a deleted contact. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.Secrets,
Chilkat.HttpResponse,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
vault: TSecrets;
entry: TJsonObject;
tokens: TJsonObject;
loaded: Boolean;
http: THttp;
resp: THttpResponse;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
vault := TSecrets.Create;
vault.Location := 'local_manager';
vault.AutoSplit := True;
entry := TJsonObject.Create;
entry.UpdateString('appName','ConstantContactV3');
entry.UpdateString('service','OAuth2');
entry.UpdateString('username','my-account');
tokens := TJsonObject.Create;
loaded := vault.GetSecretJson(entry,tokens);
if (loaded <> True) then
begin
WriteLn('Run the desktop authorization example using this account and store.');
Exit;
end;
if (tokens.JsonTypeOf('access_token') <> 1) then
begin
WriteLn('The saved authorization has no access token.');
Exit;
end;
http := THttp.Create;
http.RequireSslCertVerify := True;
http.AuthToken := tokens.StringOf('access_token');
resp := THttpResponse.Create;
// Obtain the selected contact ID from the email lookup example.
http.SetUrlVar('contactId','CONTACT_ID');
success := http.HttpNoBody('DELETE','https://api.cc.email/v3/contacts/{$contactId}',resp);
if (resp.StatusCode = 404) then
begin
WriteLn('Contact ID not found in this account.');
Exit;
end;
if ((success <> True) or (resp.StatusCode <> 204)) then
begin
WriteLn('Expected HTTP 204. Received ' + resp.StatusCode);
if (resp.StatusCode = 401) then
begin
WriteLn('Refresh the saved access token or authorize again.');
end;
Exit;
end;
WriteLn('Contact deleted and list memberships removed.');
vault.Free;
entry.Free;
tokens.Free;
http.Free;
resp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.