Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get MailChimp API listUpdateMember to change a user's email address

I'm trying to use the MailChimp API to update an email address of a member when they change their email in our web app.

I'm using the Laravel MailChimp bundle and it's been working great (I can subscribe users, update groupings, update name etc), but I must have the merge_vars or something incorrect.

I use this:

$member_details = array(
    // grabbed from config and working (also API key handled by bundle)
    'id' => $id,
    // passed from function - corresponds to the old email address
    'email_address' => $mailchimp_old_email,
    'merge_vars' => array(
        // Old email again?
        'EMAIL' => $mailchimp_old_email,     
        // new email address        
        'NEW-EMAIL' => $mailchimp_new_email, 
    ),
    'replace_interests' => FALSE,
);

$response = Mailchimp::listUpdateMember($member_details);

So "$response = 1", which made me think it had worked, but the user email has not changed when I view the subscriber list on MailChimp.

The 1.3 API docs have listSubscribe detailing the merge_vars "EMAIL" and "NEW-EMAIL" and I read about it on this stackoverflow post. I did try using listSubscribe again even though it was an existing member, but this failed with a $response saying the member is already subscribed.

Any recommendations on where I might be going wrong? I haven't found a clear example of this sort of listUpdateMember api usage.

like image 869
alexleonard Avatar asked Feb 17 '23 03:02

alexleonard


1 Answers

It turns out the answer is very simple.

https://twitter.com/MailChimp_API/status/351674145609748480

Apparently NEW-EMAIL isn't needed at all in the merge_vars - just EMAIL.

So the working code in my case is:

$member_details = array(
    // grabbed from config and working (also API key handled by bundle)
    'id' => $id,
    // passed from function - corresponds to the old email address
    'email_address' => $mailchimp_old_email,
    'merge_vars' => array(
        // new email address        
        'EMAIL' => $mailchimp_new_email,     
    ),
    'replace_interests' => FALSE,
);

$response = Mailchimp::listUpdateMember($member_details);

This works straight out. Feels like "NEW-EMAIL" really isn't necessary (or EMAIL should be removed and just use "NEW-EMAIL" as it's somewhat more descriptive of what's happening).

like image 103
alexleonard Avatar answered Feb 26 '23 21:02

alexleonard