Unicode C++ Requires Chilkat v11.0.0+
Unicode C++
Constant Contact V3: Find a contact by email address
See more Constant Contact Examples
Look up an exact email address across contact states, including deleted contacts. Pass the address as a query parameter so a literal plus sign survives URL encoding. Read the stored contact ID, email permission, and deletion marker. An empty contacts array means no match. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat Unicode C++ Downloads
#include <CkSecretsW.h>
#include <CkJsonObjectW.h>
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkHttpRequestW.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;
CkHttpRequestW query;
query.put_HttpVerb(L"GET");
query.AddParam(L"email",L"reader+newsletter@example.com");
query.AddParam(L"status",L"all");
success = http.HttpReq(L"https://api.cc.email/v3/contacts",query,resp);
if ((success != true) || (resp.get_StatusCode() != 200)) {
wprintf(L"Expected HTTP 200. Received %d\n",resp.get_StatusCode());
if (resp.get_StatusCode() == 401) {
wprintf(L"Refresh the saved access token or authorize again.\n");
}
return;
}
CkJsonObjectW reply;
success = reply.Load(resp.bodyStr());
if (success != true) {
wprintf(L"Expected a JSON response.\n");
return;
}
int count = reply.SizeOfArray(L"contacts");
if (count < 0) {
wprintf(L"The reply contained no contacts array.\n");
return;
}
if (count == 0) {
wprintf(L"No contact has that email address.\n");
return;
}
int i = 0;
while ((i < count)) {
reply.put_I(i);
wprintf(L"Contact ID: %s\n",reply.stringOf(L"contacts[i].contact_id"));
wprintf(L"Email permission: %s\n",reply.stringOf(L"contacts[i].email_address.permission_to_send"));
if (reply.JsonTypeOf(L"contacts[i].deleted_at") == 1) {
wprintf(L"Deleted at: %s\n",reply.stringOf(L"contacts[i].deleted_at"));
}
i = i + 1;
}
}