Tagged lists

Get email addresses for all members in your MailChimp lists

Yesterday at work I needed to quickly get all the members of our various MailChimp lists. I ended up writing this short script that might be helpful to someone else, so here it is:

include_once dirname(__FILE__) . '/MCAPI.class.php';
include_once dirname(__FILE__) . '/config.php'; //contains apikey

$api = new MCAPI($apikey);

//NB: last param is the # of lists to return. If you have more than
//40, make sure this parameter is high enough (max 100 lists)
$lists = $api->lists(null, 0, 40);

foreach($lists['data'] as $list){
	//you can also do 'unsubscribed', 'cleaned', or 'updated' to get those counts
       $members[] = $api->listMembers($list['id'], 'subscribed', null, null, 15000);

foreach($members as $member){
	foreach($member['data'] as $data){
		$emails[] = $data['email'];
//change this to a file path on your system
$fp = fopen('/www/mailchimp/mailchimp_members.csv', 'w');

fputcsv($fp, $emails);