Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
basiliscus edited this page Sep 26, 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:

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;
	}
}

    ...

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

    // Subscribe a person
ListSubscribeMethod listSubscribeMethod = new ListSubscribeMethod();
listSubscribeMethod.apikey = "******";
listSubscribeMethod.id = "******";
listSubscribeMethod.email_address = "vasya-pupkin@example.com";
listSubscribeMethod.double_optin = false;
listSubscribeMethod.update_existing = true;
listSubscribeMethod.merge_vars = new MergeVars("vasya-pupkin@example.com", "Vasya", "Pupkin");
mailChimpClient.execute(listSubscribeMethod);

    // check his status
ListMemberInfoMethod listMemberInfoMethod = new ListMemberInfoMethod();
listMemberInfoMethod.apikey = apiKey;
listMemberInfoMethod.id = listId;
listMemberInfoMethod.email_address = Arrays.asList("vasya-pupkin@example.com");
	
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.2</version>
</dependency>
Clone this wiki locally