Read MailChimp Contacts Using the RESTful Client API
Updated: Jan 31, 2023
This example shows you how to read MailChimp contacts using the RESTful client API in DataPipeline.
You can see similar MailChimp examples here.
Java Code Listing
package com.northconcepts.datapipeline.mailchimp; import com.northconcepts.datapipeline.mailchimp.list.ListMember; import com.northconcepts.datapipeline.mailchimp.list.ListMemberStatus; import com.northconcepts.datapipeline.mailchimp.list.ListMembers; public class ReadMailChimpContactsUsingClientAPI { private static final String apiKey = "api-key"; private static final String listId = "list-id"; private static final MailChimpClient client = MailChimpClient.Proxy.get(apiKey); public static void main(String[] args) { ListMembers listMembers = client.getListMembersObject(listId, ListMemberStatus.subscribed, 0, 5); System.out.println("Total contacts :"+listMembers.getMembers().size()); for (ListMember listMember: listMembers.getMembers()) { System.out.println("---------------------------"); System.out.println("Id :"+listMember.getId()); System.out.println("Email :"+listMember.getEmailAddress()); System.out.println("Status :"+listMember.getStatus()); } } }
Code Walkthrough
apiKey
is your MailChimp token which you can easily learn how to generate in https://mailchimp.com/help/about-api-keys/.listId
is your audience id.- An instance of MailChimpClient is created and will be used to fetch the list of members/contacts.
getListMembersObject
returns a list of members.ListMemberStatus.subscribed
is the status of the contact.- The status can either be subscribed, unsubscribed, cleaned, pending, or archived.
0
is the offset and5
is the number of records you want to fetch.- The output is finally printed after looping through the members.