Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
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 Delphi ActiveX Downloads
var
success: Integer;
vault: TChilkatSecrets;
entry: TChilkatJsonObject;
tokens: TChilkatJsonObject;
loaded: Integer;
http: TChilkatHttp;
resp: TChilkatHttpResponse;
begin
success := 0;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
vault := TChilkatSecrets.Create(Self);
vault.Location := 'local_manager';
vault.AutoSplit := 1;
entry := TChilkatJsonObject.Create(Self);
entry.UpdateString('appName','ConstantContactV3');
entry.UpdateString('service','OAuth2');
entry.UpdateString('username','my-account');
tokens := TChilkatJsonObject.Create(Self);
loaded := vault.GetSecretJson(entry.ControlInterface,tokens.ControlInterface);
if (loaded <> 1) then
begin
Memo1.Lines.Add('Run the desktop authorization example using this account and store.');
Exit;
end;
if (tokens.JsonTypeOf('access_token') <> 1) then
begin
Memo1.Lines.Add('The saved authorization has no access token.');
Exit;
end;
http := TChilkatHttp.Create(Self);
http.RequireSslCertVerify := 1;
http.AuthToken := tokens.StringOf('access_token');
resp := TChilkatHttpResponse.Create(Self);
// 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.ControlInterface);
if (resp.StatusCode = 404) then
begin
Memo1.Lines.Add('Contact ID not found in this account.');
Exit;
end;
if ((success <> 1) or (resp.StatusCode <> 204)) then
begin
Memo1.Lines.Add('Expected HTTP 204. Received ' + IntToStr(resp.StatusCode));
if (resp.StatusCode = 401) then
begin
Memo1.Lines.Add('Refresh the saved access token or authorize again.');
end;
Exit;
end;
Memo1.Lines.Add('Contact deleted and list memberships removed.');