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

Unicode C++
#include <CkSecretsW.h>
#include <CkJsonObjectW.h>
#include <CkHttpW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    CkSecretsW vault;
    vault.put_Location(L"local_manager");
    vault.put_AutoSplit(true);
    CkJsonObjectW entry;
    entry.UpdateString(L"appName",L"ConstantContactV3");
    entry.UpdateString(L"service",L"OAuth2");
    entry.UpdateString(L"username",L"my-account");
    CkJsonObjectW tokens;
    bool loaded = vault.GetSecretJson(entry,tokens);
    if (loaded != true) {
        wprintf(L"Run the desktop authorization example using this account and store.\n");
        return;
    }

    if (tokens.JsonTypeOf(L"access_token") != 1) {
        wprintf(L"The saved authorization has no access token.\n");
        return;
    }

    CkHttpW http;
    http.put_RequireSslCertVerify(true);
    http.put_AuthToken(tokens.stringOf(L"access_token"));
    CkHttpResponseW resp;

    //  Obtain the selected contact ID from the email lookup example.
    http.SetUrlVar(L"contactId",L"CONTACT_ID");
    success = http.HttpNoBody(L"DELETE",L"https://api.cc.email/v3/contacts/{$contactId}",resp);
    if (resp.get_StatusCode() == 404) {
        wprintf(L"Contact ID not found in this account.\n");
        return;
    }

    if ((success != true) || (resp.get_StatusCode() != 204)) {
        wprintf(L"Expected HTTP 204. Received %d\n",resp.get_StatusCode());
        if (resp.get_StatusCode() == 401) {
            wprintf(L"Refresh the saved access token or authorize again.\n");
        }

        return;
    }

    wprintf(L"Contact deleted and list memberships removed.\n");
    }