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

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 CkPerl Downloads

CkPerl
use chilkat();

$success = 0;

#  Assumes Chilkat is unlocked. See Global Unlock Sample.
$vault = chilkat::CkSecrets->new();
$vault->put_Location("local_manager");
$vault->put_AutoSplit(1);
$entry = chilkat::CkJsonObject->new();
$entry->UpdateString("appName","ConstantContactV3");
$entry->UpdateString("service","OAuth2");
$entry->UpdateString("username","my-account");
$tokens = chilkat::CkJsonObject->new();
$loaded = $vault->GetSecretJson($entry,$tokens);
if ($loaded != 1) {
    print "Run the desktop authorization example using this account and store." . "\r\n";
    exit;
}

if ($tokens->JsonTypeOf("access_token") != 1) {
    print "The saved authorization has no access token." . "\r\n";
    exit;
}

$http = chilkat::CkHttp->new();
$http->put_RequireSslCertVerify(1);
$http->put_AuthToken($tokens->stringOf("access_token"));
$resp = chilkat::CkHttpResponse->new();

#  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->get_StatusCode() == 404) {
    print "Contact ID not found in this account." . "\r\n";
    exit;
}

if (($success != 1) or ($resp->get_StatusCode() != 204)) {
    print "Expected HTTP 204. Received " . $resp->get_StatusCode() . "\r\n";
    if ($resp->get_StatusCode() == 401) {
        print "Refresh the saved access token or authorize again." . "\r\n";
    }

    exit;
}

print "Contact deleted and list memberships removed." . "\r\n";