Downloading emails from Mailchimp

Asked

Viewed 46 times

0

Good afternoon

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

Currently there is not a very faithful control of Campaigns, Segments and Lists (Mailchimp only has a huge list of emails and to send a campaign, it is usually created directly in Mailchimp, sending emails to a list from a .csv file)so in order for me to generate a mailing list, I need to filter these errors so that a contact that has been unsubscribed does not receive any email.

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

1 answer

1


I figured out how to download the emails. It is necessary to use the CURL library to access version 3.0 of the API that Mailchimp provides. Below 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;

This way, all the necessary information will come in json format, then just turn into object and work on the result. The only problem is that the result set only returns 10 results.

  • 1

    "It is necessary to use the CURL library" - I believe that using Curl is one of several ways, not "necessary".

  • Well, certainly... I expressed myself badly

Browser other questions tagged

You are not signed in. Login or sign up in order to post.