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

C
#include <C_CkSecrets.h>
#include <C_CkJsonObject.h>
#include <C_CkHttp.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkSecrets vault;
    HCkJsonObject entry;
    HCkJsonObject tokens;
    BOOL loaded;
    HCkHttp http;
    HCkHttpResponse resp;

    success = FALSE;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    vault = CkSecrets_Create();
    CkSecrets_putLocation(vault,"local_manager");
    CkSecrets_putAutoSplit(vault,TRUE);
    entry = CkJsonObject_Create();
    CkJsonObject_UpdateString(entry,"appName","ConstantContactV3");
    CkJsonObject_UpdateString(entry,"service","OAuth2");
    CkJsonObject_UpdateString(entry,"username","my-account");
    tokens = CkJsonObject_Create();
    loaded = CkSecrets_GetSecretJson(vault,entry,tokens);
    if (loaded != TRUE) {
        printf("Run the desktop authorization example using this account and store.\n");
        CkSecrets_Dispose(vault);
        CkJsonObject_Dispose(entry);
        CkJsonObject_Dispose(tokens);
        return;
    }

    if (CkJsonObject_JsonTypeOf(tokens,"access_token") != 1) {
        printf("The saved authorization has no access token.\n");
        CkSecrets_Dispose(vault);
        CkJsonObject_Dispose(entry);
        CkJsonObject_Dispose(tokens);
        return;
    }

    http = CkHttp_Create();
    CkHttp_putRequireSslCertVerify(http,TRUE);
    CkHttp_putAuthToken(http,CkJsonObject_stringOf(tokens,"access_token"));
    resp = CkHttpResponse_Create();

    //  Obtain the selected contact ID from the email lookup example.
    CkHttp_SetUrlVar(http,"contactId","CONTACT_ID");
    success = CkHttp_HttpNoBody(http,"DELETE","https://api.cc.email/v3/contacts/{$contactId}",resp);
    if (CkHttpResponse_getStatusCode(resp) == 404) {
        printf("Contact ID not found in this account.\n");
        CkSecrets_Dispose(vault);
        CkJsonObject_Dispose(entry);
        CkJsonObject_Dispose(tokens);
        CkHttp_Dispose(http);
        CkHttpResponse_Dispose(resp);
        return;
    }

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

        CkSecrets_Dispose(vault);
        CkJsonObject_Dispose(entry);
        CkJsonObject_Dispose(tokens);
        CkHttp_Dispose(http);
        CkHttpResponse_Dispose(resp);
        return;
    }

    printf("Contact deleted and list memberships removed.\n");


    CkSecrets_Dispose(vault);
    CkJsonObject_Dispose(entry);
    CkJsonObject_Dispose(tokens);
    CkHttp_Dispose(http);
    CkHttpResponse_Dispose(resp);

    }