C# Requires Chilkat v11.0.0+
C#
Constant Contact V3: Read every page of list members
See more Constant Contact Examples
Filter the contacts collection with lists and a list ID. To query multiple lists together, supply their comma-separated IDs. Follow the returned cursor links and report the total after the last page. The default contacts query excludes deleted records. A list member can still have unsubscribed email permission. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat C# Downloads
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();
http.SetUrlVar("list","LIST_ID");
Chilkat.StringBuilder url = new Chilkat.StringBuilder();
url.Append("https://api.cc.email/v3/contacts?lists={$list}&limit=50");
Chilkat.JsonObject page = new Chilkat.JsonObject();
int total = 0;
while ((url.Length > 0)) {
success = http.HttpNoBody("GET",url.GetAsString(),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;
}
success = page.Load(resp.BodyStr);
int count = page.SizeOfArray("contacts");
if ((success != true) || (count < 0)) {
Debug.WriteLine("Expected a page of contacts.");
return;
}
int i = 0;
while ((i < count)) {
page.I = i;
Debug.WriteLine(page.StringOf("contacts[i].contact_id") + " " + page.StringOf("contacts[i].email_address.address"));
i = i + 1;
}
total = total + count;
url.Clear();
if (page.JsonTypeOf("_links.next.href") == 1) {
url.Append(page.StringOf("_links.next.href"));
// The documented cursor link is relative to api.cc.email.
if (url.StartsWith("/v3/contacts?",true) != true) {
Debug.WriteLine("Unexpected pagination link. Stopped before following it.");
return;
}
url.Prepend("https://api.cc.email");
}
}
Debug.WriteLine("List members read: " + Convert.ToString(total));