Sample code for 30+ languages & platforms
CkJava 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 CkJava Downloads

CkJava
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    CkSecrets vault = new CkSecrets();
    vault.put_Location("local_manager");
    vault.put_AutoSplit(true);
    CkJsonObject entry = new CkJsonObject();
    entry.UpdateString("appName","ConstantContactV3");
    entry.UpdateString("service","OAuth2");
    entry.UpdateString("username","my-account");
    CkJsonObject tokens = new CkJsonObject();
    boolean loaded = vault.GetSecretJson(entry,tokens);
    if (loaded != true) {
        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;
        }

    CkHttp http = new CkHttp();
    http.put_RequireSslCertVerify(true);
    http.put_AuthToken(tokens.stringOf("access_token"));
    CkHttpResponse 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.get_StatusCode() == 404) {
        System.out.println("Contact ID not found in this account.");
        return;
        }

    if ((success != true) || (resp.get_StatusCode() != 204)) {
        System.out.println("Expected HTTP 204. Received " + resp.get_StatusCode());
        if (resp.get_StatusCode() == 401) {
            System.out.println("Refresh the saved access token or authorize again.");
            }

        return;
        }

    System.out.println("Contact deleted and list memberships removed.");
  }
}