Downloading emails from Mailchimp

0

Good afternoon

I'm doing an integration of Mailchimp with PHP and need to download from Mailchimp the emails that are as "unsubscribed" and "cleaned" to update in the bank.

There is currently very tight control of Campaigns, Segments and Lists (in Mailchimp you only have a huge list of emails and to send a campaign, it is usually created directly in Mailchimp, sending emails to a list from a file .csv), so for me to generate a mailing list, I need to filter these errors so that a contact that has been unsubscribed receives no email.

Do you have any API function or any means that I can download only those emails to my bank?

    
asked by anonymous 16.03.2016 / 17:20

1 answer

1

I discovered how to download the emails. You must use the CURL library to access version 3.0 of the API that Mailchimp provides. Here is an example:

$apikey = 'sua_api_key';
$listid = 'sua_list_id';
$server = 'seu_server.';
$auth = base64_encode( 'user:'.$apikey );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.$listid.'/members/?status=unsubscribed');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: application/json', 'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_post);
$result = curl_exec($ch);
echo $result;

In this way, all the necessary information will come in json format, from there it's just turning into an object and working on the result. The only problem is that the result set only returns 10 results.

    
17.03.2016 / 15:05