CkJava Requires Chilkat v11.0.0+
CkJava
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 CkJava Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkSecrets vault = new CkSecrets();
vault.put_Location("local_manager");
vault.put_AutoSplit(true);
CkJsonObject entry = new CkJsonObject();
entry.UpdateString("appName","ConstantContactV3");
entry.UpdateString("service","OAuth2");
entry.UpdateString("username","my-account");
CkJsonObject tokens = new CkJsonObject();
boolean loaded = vault.GetSecretJson(entry,tokens);
if (loaded != true) {
System.out.println("Run the desktop authorization example using this account and store.");
return;
}
if (tokens.JsonTypeOf("access_token") != 1) {
System.out.println("The saved authorization has no access token.");
return;
}
CkHttp http = new CkHttp();
http.put_RequireSslCertVerify(true);
http.put_AuthToken(tokens.stringOf("access_token"));
CkHttpResponse resp = new CkHttpResponse();
CkJsonObject body = new CkJsonObject();
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.get_StatusCode() == 409) {
System.out.println("A conflicting list already exists. Check the existing lists before retrying.");
return;
}
if ((success != true) || (resp.get_StatusCode() != 201)) {
System.out.println("Expected HTTP 201. Received " + resp.get_StatusCode());
if (resp.get_StatusCode() == 401) {
System.out.println("Refresh the saved access token or authorize again.");
}
return;
}
CkJsonObject created = new CkJsonObject();
success = created.Load(resp.bodyStr());
if (success != true) {
System.out.println("Expected a JSON response.");
return;
}
if ((created.JsonTypeOf("list_id") != 1) || (created.StringOfEquals("list_id","",true) == true)) {
System.out.println("Missing list_id in the response.");
return;
}
System.out.println("Created " + created.stringOf("name") + ". List ID: " + created.stringOf("list_id"));
}
}