Sample code for 30+ languages & platforms
.NET Core C# Requires Chilkat v11.0.0+

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 .NET Core C# Downloads

.NET Core C#
bool success = false;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
Chilkat.Secrets vault = new Chilkat.Secrets();
vault.Location = "local_manager";
vault.AutoSplit = true;
Chilkat.JsonObject entry = new Chilkat.JsonObject();
entry.UpdateString("appName","ConstantContactV3");
entry.UpdateString("service","OAuth2");
entry.UpdateString("username","my-account");
Chilkat.JsonObject tokens = new Chilkat.JsonObject();
bool loaded = vault.GetSecretJson(entry,tokens);
if (loaded != true) {
    Debug.WriteLine("Run the desktop authorization example using this account and store.");
    return;
}

if (tokens.JsonTypeOf("access_token") != 1) {
    Debug.WriteLine("The saved authorization has no access token.");
    return;
}

Chilkat.Http http = new Chilkat.Http();
http.RequireSslCertVerify = true;
http.AuthToken = tokens.StringOf("access_token");
Chilkat.HttpResponse resp = new Chilkat.HttpResponse();

Chilkat.HttpRequest query = new Chilkat.HttpRequest();
query.HttpVerb = "GET";
query.AddParam("email","reader+newsletter@example.com");
query.AddParam("status","all");
success = http.HttpReq("https://api.cc.email/v3/contacts",query,resp);
if ((success != true) || (resp.StatusCode != 200)) {
    Debug.WriteLine("Expected HTTP 200. Received " + Convert.ToString(resp.StatusCode));
    if (resp.StatusCode == 401) {
        Debug.WriteLine("Refresh the saved access token or authorize again.");
    }

    return;
}

Chilkat.JsonObject reply = new Chilkat.JsonObject();
success = reply.Load(resp.BodyStr);
if (success != true) {
    Debug.WriteLine("Expected a JSON response.");
    return;
}

int count = reply.SizeOfArray("contacts");
if (count < 0) {
    Debug.WriteLine("The reply contained no contacts array.");
    return;
}

if (count == 0) {
    Debug.WriteLine("No contact has that email address.");
    return;
}

int i = 0;
while ((i < count)) {
    reply.I = i;
    Debug.WriteLine("Contact ID: " + reply.StringOf("contacts[i].contact_id"));
    Debug.WriteLine("Email permission: " + reply.StringOf("contacts[i].email_address.permission_to_send"));
    if (reply.JsonTypeOf("contacts[i].deleted_at") == 1) {
        Debug.WriteLine("Deleted at: " + reply.StringOf("contacts[i].deleted_at"));
    }

    i = i + 1;
}