JavaScript Requires Chilkat v11.0.0+
JavaScript
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
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
var vault = new CkSecrets();
vault.Location = "local_manager";
vault.AutoSplit = true;
var entry = new CkJsonObject();
entry.UpdateString("appName","ConstantContactV3");
entry.UpdateString("service","OAuth2");
entry.UpdateString("username","my-account");
var tokens = new CkJsonObject();
var loaded = vault.GetSecretJson(entry,tokens);
if (loaded !== true) {
console.log("Run the desktop authorization example using this account and store.");
return;
}
if (tokens.JsonTypeOf("access_token") !== 1) {
console.log("The saved authorization has no access token.");
return;
}
var http = new CkHttp();
http.RequireSslCertVerify = true;
http.AuthToken = tokens.StringOf("access_token");
var resp = new CkHttpResponse();
// 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) {
console.log("Contact ID not found in this account.");
return;
}
if ((success !== true) || (resp.StatusCode !== 204)) {
console.log("Expected HTTP 204. Received " + resp.StatusCode);
if (resp.StatusCode == 401) {
console.log("Refresh the saved access token or authorize again.");
}
return;
}
console.log("Contact deleted and list memberships removed.");