Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
basiliscus edited this page Nov 17, 2012 · 51 revisions

General info

Ecwid-mailchimp provides access to MailChimp API v1.3 methods from Java code.

Refer to the javadoc pages to learn how to use Ecwid-mailchimp.

Currently Ecwid-mailchimp itself has wrappers for a limited number of MailChimp API methods only. However, it is very easy to extend the API and add support for any method you need.

Sample code

Here is some sample code showing how to use the wrapper.

Suppose you want to subscribe a person to your list and then check his status. That's easy:

// Holds a subscriber's merge_vars info (see http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php )
public static class MergeVars extends MailChimpObject {
	@Field
	public String EMAIL, FNAME, LNAME;

	public MergeVars() { }
	
	public MergeVars(String email, String fname, String lname) {
		this.EMAIL = email;
		this.FNAME = fname;
		this.LNAME = lname;
	}
}

...

// reuse the same MailChimpClient object whenever possible
MailChimpClient mailChimpClient = new MailChimpClient(); 

// Subscribe a person
ListSubscribeMethod listSubscribeMethod = new ListSubscribeMethod();
listSubscribeMethod.apikey = "******";
listSubscribeMethod.id = "******";
listSubscribeMethod.email_address = "[email protected]";
listSubscribeMethod.double_optin = false;
listSubscribeMethod.update_existing = true;
listSubscribeMethod.merge_vars = new MergeVars("[email protected]", "Vasya", "Pupkin");
mailChimpClient.execute(listSubscribeMethod);

// check his status
ListMemberInfoMethod listMemberInfoMethod = new ListMemberInfoMethod();
listMemberInfoMethod.apikey = "******";
listMemberInfoMethod.id = "******";
listMemberInfoMethod.email_address = Arrays.asList("[email protected]");
	
ListMemberInfoResult listMemberInfoResult = mailChimpClient.execute(listMemberInfoMethod);
MemberInfo info = listMemberInfoResult.data.get(0);
System.out.println(info.email + ": "+  info.status);

Maven integration

Ecwid-mailchimp is accessible as maven artifact, just add the following dependency declaration to your pom:

<dependency>
    <groupId>com.ecwid</groupId>
    <artifactId>ecwid-mailchimp</artifactId>
    <version>1.3.0.3</version>
</dependency>
Clone this wiki locally