1

I am trying to update a subscriber's email address using PHP cURL and Mailchimp API v3. I based my code on this:

Updating subscribers in a list using cURL and Mailchimp API v3

But somehow I can't update the email address. I can update the other fields but not email address. This is what I have:

$data = array(
    'apikey'        => $mailchimp_api_key,
    'email_address' => $orig_email,
    //'status'      => $status,
    'merge_fields'  => array(
        'EMAIL' => $email // also used NEW-EMAIL but it didn't work either
    )
);
$json_data = json_encode($data, JSON_NUMERIC_CHECK);
$url = $mailchimp_api_url.'lists/'.$mailchimp_list_id.'/members/'.md5($orig_email);
$request = 'PATCH';
$result = $this->curl_request($url, $json_data, $request); // in here is basically the cURL request based on VenomRush's question above, in the link

I'm thinking I'm doing something wrong with the data request. Can anyone point me in the right direction? Thanks.

Community
  • 1
  • 1

1 Answers1

0

You cannot update a user's email address in API v3. Even in v2, it's not substantially different from just subscribing a new address, so that's the way to do it now. Unsubscribe or delete the old email address, subscribe the new one.

Also: you don't need to pass the API Key in the body of your request (and shouldn't). Use HTTP Basic Auth for authentication.

TooMuchPete
  • 4,583
  • 2
  • 17
  • 21
  • What happens if the user has a bunch of email preferences? Creating a new subscriber seems odd; how do you migrate all that data over to the "new" subscriber? The API docs for v3 even says request body, email_address, read only = false. – Jamie Taniguchi Nov 12 '15 at 03:24
  • Any concept of a user that is independent from an email address will need to come from outside of the system, as that's not really how MailChimp is setup. – TooMuchPete Nov 13 '15 at 03:45
  • @TooMuchPete That may be, but MailChimp allows subscribers to "update" their own email address through their web interface *and* the whole point of the API is to interface with other systems, a great many of whom do not understand changing an email address to mean "DELETE this account and create a new one with almost the exact same data." – samh Sep 09 '16 at 19:33
  • @TooMuchPete It's extremely poor design to not allow users to update their email via the api. I've read your logic and reasoning in this thread at least one more and while it sounds great on paper, in reality it's just poor design. If it's such a rare scenario, then why allow it in the MC dashboard but not the api? Just stating my opinion with others and stating a lot more clients need this feature than you are realizing. I've had multiple clients need this functionality. It use to be possible with the `new-email` parameter. – Justin Kimbrell Sep 29 '16 at 19:22
  • Everyone is certainly entitled to an opinion. It's possible that future changes in MailChimp's architecture will make this a reasonable change in the future. You'll want to express these feelings to MailChimp directly, though, through their apihelp address. – TooMuchPete Sep 30 '16 at 17:13