.NET Core C# Requires Chilkat v11.0.0+
.NET Core C#
Constant Contact V3: Create a contact list
See more Constant Contact Examples
Create a list with a unique name and a short description. Save the returned list_id with your application’s list record and use it in the membership examples. The new list starts empty. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat .NET Core 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();
Chilkat.JsonObject body = new Chilkat.JsonObject();
body.UpdateString("name","Workshop announcements");
body.UpdateString("description","People who requested workshop updates");
success = http.HttpJson("POST","https://api.cc.email/v3/contact_lists",body,"application/json",resp);
if (resp.StatusCode == 409) {
Debug.WriteLine("A conflicting list already exists. Check the existing lists before retrying.");
return;
}
if ((success != true) || (resp.StatusCode != 201)) {
Debug.WriteLine("Expected HTTP 201. Received " + Convert.ToString(resp.StatusCode));
if (resp.StatusCode == 401) {
Debug.WriteLine("Refresh the saved access token or authorize again.");
}
return;
}
Chilkat.JsonObject created = new Chilkat.JsonObject();
success = created.Load(resp.BodyStr);
if (success != true) {
Debug.WriteLine("Expected a JSON response.");
return;
}
if ((created.JsonTypeOf("list_id") != 1) || (created.StringOfEquals("list_id","",true) == true)) {
Debug.WriteLine("Missing list_id in the response.");
return;
}
Debug.WriteLine("Created " + created.StringOf("name") + ". List ID: " + created.StringOf("list_id"));