I was recently a little puzzled about how to change the email address of a current subscriber to your MailChimp list via an API command.
I went slightly astray after reading a stackoverflow.com answer but ultimately it was a relatively simple procedure.
Whilst I’m using the Laravel-MailChimp bundle to process the API calls, the important part is the structure of the JSON array you send to MailChimp.
In my case the Laravel Mailchimp class processes a PHP array and sends it to MailChimp. Please note that the Mailchimp class adds my API key later. You’ll need to specify your API key for this to work.
$member_details = array( // I'm passing the ID in from a function 'id' => $id, // Here you need to specify the user's old email // It must correspond to a current subscriber on your MailChimp list 'email_address' => $old_email, 'merge_vars' => array( // Specify the NEW email address for the subscriber 'EMAIL' => $new_email, ), 'replace_interests' => FALSE, ); $response = Mailchimp::listUpdateMember($member_details);
And that’s it.
I’m a little perplexed as to why the MailChimp API documents merge_vars called EMAIL and NEW-EMAIL as they both appear to do the same thing 1. It seems like they could just have a single merge_var called “NEW-EMAIL” and that would cover it and make more sense at the same time! Still, I’ve got it working now so I’m happy!
You shouldn't set EMAIL and NEW-EMAIL – the docs say EMAIL always takes precedence. Also better to get support here: https://t.co/y5yLOc42eL
— MailChimp API (@MailChimp_API) July 1, 2013
- I believe NEW-EMAIL is for batch updates ↩
Comments