Java Requires Chilkat v11.0.0+
Java
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 Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Secrets;
public class ChilkatExample {
public static void main(String[] args) {
boolean success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Secrets vault = new Secrets();
vault.setLocation("local_manager");
vault.setAutoSplit(true);
JsonObject entry = new JsonObject();
entry.updateString("appName", "ConstantContactV3");
entry.updateString("service", "OAuth2");
entry.updateString("username", "my-account");
JsonObject tokens = new JsonObject();
try {
vault.getSecretJson(entry, tokens);
} catch (ChilkatException e) {
System.out.println("Run the desktop authorization example using this account and store.");
return;
}
if (tokens.jsonTypeOf("access_token") != 1) {
System.out.println("The saved authorization has no access token.");
return;
}
Http http = new Http();
http.setRequireSslCertVerify(true);
http.setAuthToken(tokens.stringOf("access_token"));
HttpResponse 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 (ChilkatException e) {
success = false;
}
if (resp.getStatusCode() == 404) {
System.out.println("Contact ID not found in this account.");
return;
}
if ((!success) || (resp.getStatusCode() != 204)) {
System.out.println("Expected HTTP 204. Received " + resp.getStatusCode());
if (resp.getStatusCode() == 401) {
System.out.println("Refresh the saved access token or authorize again.");
}
return;
}
System.out.println("Contact deleted and list memberships removed.");
}
}