php - Updating subscribers in a list using cURL and Mailchimp API v3 -
i have code below adds user pre-existing list in mailchimp.
$apikey = '<api_key>'; $auth = base64_encode( 'user:'.$apikey ); $data = array( 'apikey' => $apikey, 'email_address' => $email, 'status' => 'subscribed', 'merge_fields' => array( 'fname' => $name ) ); $json_data = json_encode($data); $ch = curl_init(); curl_setopt($ch, curlopt_url, 'https://us2.api.mailchimp.com/3.0/lists/<list_id>/members/'); 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_postfields, $json_data); $result = curl_exec($ch); var_dump($result); die('mailchimp executed');
this code adds users list , when try add details of same user twice throws following error on second attempt:
test@user.com list member. use patch update existing members.
how go using patch update user details? i'm not sure specify it.
i figured out i'm going wrong. when user added list response provides id. need store id in database person's details , reference id in url i'm making call when want update user's details in mailchimp list.
https://us2.api.mailchimp.com/3.0/lists/<list_id_goes_here>/members/<members_id_goes_here>
thanks @toomuchpete correct curl command.
curl_setopt($ch, curlopt_customrequest, "patch");
Comments
Post a Comment