PHP Requires Chilkat v11.0.0+
PHP
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 PHP Downloads
<?php
use Chilkat2\Http;
use Chilkat2\HttpResponse;
use Chilkat2\JsonObject;
use Chilkat2\Secrets;
$success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
$vault = new Secrets();
$vault->Location = 'local_manager';
$vault->AutoSplit = true;
$entry = new JsonObject();
$entry->UpdateString('appName', 'ConstantContactV3');
$entry->UpdateString('service', 'OAuth2');
$entry->UpdateString('username', 'my-account');
$tokens = new JsonObject();
try {
$vault->GetSecretJson($entry, $tokens);
} catch (\Chilkat2\Exception $e) {
echo "Run the desktop authorization example using this account and store.\n";
exit;
}
if ($tokens->JsonTypeOf('access_token') != 1) {
echo "The saved authorization has no access token.\n";
exit;
}
$http = new Http();
$http->RequireSslCertVerify = true;
$http->AuthToken = $tokens->StringOf('access_token');
$resp = new HttpResponse();
// Obtain the selected contact ID from the email lookup example.
$http->SetUrlVar('contactId', 'CONTACT_ID');
try {
$http->HttpNoBody('DELETE', 'https://api.cc.email/v3/contacts/{$contactId}', $resp);
$success = true;
} catch (\Chilkat2\Exception $e) {
$success = false;
}
if ($resp->StatusCode == 404) {
echo "Contact ID not found in this account.\n";
exit;
}
if ((!$success) || ($resp->StatusCode != 204)) {
echo 'Expected HTTP 204. Received ', $resp->StatusCode, "\n";
if ($resp->StatusCode == 401) {
echo "Refresh the saved access token or authorize again.\n";
}
exit;
}
echo "Contact deleted and list memberships removed.\n";