Unicode C Requires Chilkat v11.0.0+
Unicode C
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
#include <C_CkSecretsW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
BOOL success;
HCkSecretsW vault;
HCkJsonObjectW entry;
HCkJsonObjectW tokens;
BOOL loaded;
HCkHttpW http;
HCkHttpResponseW resp;
success = FALSE;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
vault = CkSecretsW_Create();
CkSecretsW_putLocation(vault,L"local_manager");
CkSecretsW_putAutoSplit(vault,TRUE);
entry = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(entry,L"appName",L"ConstantContactV3");
CkJsonObjectW_UpdateString(entry,L"service",L"OAuth2");
CkJsonObjectW_UpdateString(entry,L"username",L"my-account");
tokens = CkJsonObjectW_Create();
loaded = CkSecretsW_GetSecretJson(vault,entry,tokens);
if (loaded != TRUE) {
wprintf(L"Run the desktop authorization example using this account and store.\n");
CkSecretsW_Dispose(vault);
CkJsonObjectW_Dispose(entry);
CkJsonObjectW_Dispose(tokens);
return;
}
if (CkJsonObjectW_JsonTypeOf(tokens,L"access_token") != 1) {
wprintf(L"The saved authorization has no access token.\n");
CkSecretsW_Dispose(vault);
CkJsonObjectW_Dispose(entry);
CkJsonObjectW_Dispose(tokens);
return;
}
http = CkHttpW_Create();
CkHttpW_putRequireSslCertVerify(http,TRUE);
CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(tokens,L"access_token"));
resp = CkHttpResponseW_Create();
// Obtain the selected contact ID from the email lookup example.
CkHttpW_SetUrlVar(http,L"contactId",L"CONTACT_ID");
success = CkHttpW_HttpNoBody(http,L"DELETE",L"https://api.cc.email/v3/contacts/{$contactId}",resp);
if (CkHttpResponseW_getStatusCode(resp) == 404) {
wprintf(L"Contact ID not found in this account.\n");
CkSecretsW_Dispose(vault);
CkJsonObjectW_Dispose(entry);
CkJsonObjectW_Dispose(tokens);
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
return;
}
if ((success != TRUE) || (CkHttpResponseW_getStatusCode(resp) != 204)) {
wprintf(L"Expected HTTP 204. Received %d\n",CkHttpResponseW_getStatusCode(resp));
if (CkHttpResponseW_getStatusCode(resp) == 401) {
wprintf(L"Refresh the saved access token or authorize again.\n");
}
CkSecretsW_Dispose(vault);
CkJsonObjectW_Dispose(entry);
CkJsonObjectW_Dispose(tokens);
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
return;
}
wprintf(L"Contact deleted and list memberships removed.\n");
CkSecretsW_Dispose(vault);
CkJsonObjectW_Dispose(entry);
CkJsonObjectW_Dispose(tokens);
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
}