Cannot get MailChimp API listUpdateMember to change user email address

I am trying to use the MailChimp API to update a member's email address when they change their email address in our web application.

I use the Laravel MailChimp kit and it works fine (I can subscribe to users, update groups, update name, etc.), but I must have merge_vars or something wrong.

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 that it worked, but the user email address did not change when I look at the list of subscribers in MailChimp.

The API 1.3 docs have a listSubscribe detailing the merge_vars "EMAIL" and "NEW-EMAIL" in detail , and I read about it on https://stackoverflow.com/a/168257/ ... I tried again using listSubscribe, even if it was an existing member, but that failed with the answer $ in which the user has already subscribed.

Any recommendations on where I might be wrong? I have not found a clear example of this kind of use of the api listUpdateMember api.

+4
source share
2 answers

It turns out that the answer is very simple.

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

Apparently NEW-EMAIL is not required at all in merge_vars - just EMAIL.

So, the working code in my case:

 $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); 

It works straight. It seems that "NEW-EMAIL" is really not required (or EMAIL should be deleted and just use "NEW-EMAIL", since it describes in more detail what is happening).

+8
source

If you upgraded to use MailChimp API v3, there is a new way to do this.

Use the patch or put method on the endpoint /lists/members .

email_address is the top level property for the object you click on (at the same level as merge_fields , which is called merge_vars in API 2) and represents the new email address.

MailChimp Documentation

0
source

Source: https://habr.com/ru/post/1488255/


All Articles