Read MailChimp Contacts
Updated: Jan 31, 2023
This example shows you how to read MailChimp contacts using DataPipeline.
You can see similar MailChimp examples here.
Java Code Listing
package com.northconcepts.datapipeline.mailchimp; import com.northconcepts.datapipeline.core.DataReader; import com.northconcepts.datapipeline.core.DataWriter; import com.northconcepts.datapipeline.core.StreamWriter; import com.northconcepts.datapipeline.job.Job; import com.northconcepts.datapipeline.mailchimp.list.ListMemberStatus; public class ReadMailChimpContacts { private static final String apiKey = "api-key"; private static final String listId = "list-id"; public static void main(String[] args) { DataReader reader = new MailChimpListMemberReader(apiKey, listId) .setStatus(ListMemberStatus.subscribed); DataWriter writer = StreamWriter.newSystemOutWriter(); Job.run(reader, writer); } }
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.- MailChimpListMemberReader is used to read all the contacts in the given
listId
. .setStatus(ListMemberStatus.subscribed)
this method is used to specify the type of contacts that you want to fetch e.g. for this case, all the subscribed contacts will be fetched.- The status can either be subscribed, unsubscribed, cleaned, pending, or archived.
StreamWriter.newSystemOutWriter()
is used to print the output records to the console.- Job.run() is then used to transfer data from the
reader
to StreamWriter.