使用卷曲和Mailchimp API V3列表更新用户 [英] Updating subscribers in a list using cURL and Mailchimp API v3
问题描述
我有下面这code增加了一个用户在一个Mailchimp pre-现有的列表。
$ apikey ='<&API_KEY GT;';
$ AUTH = base64_en code('用户名:'$ apikey); $数据=阵列(
apikey'=> $ apikey,
EMAIL_ADDRESS'=> $电子邮件,
状态=> '认购',
merge_fields'=>阵列(
FNAME'=> $名称
)
);
$ json_data = json_en code($的数据); $ CH = curl_init();
curl_setopt($ CH,CURLOPT_URL,'https://us2.api.mailchimp.com/3.0/lists/<list_id>/members/');
curl_setopt($ CH,CURLOPT_HTTPHEADER,阵列('内容类型:应用程序/ JSON,
授权:基本'$ AUTH));
curl_setopt($ CH,CURLOPT_USERAGENT,PHP-MCAPI / 2.0');
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,真正的);
curl_setopt($ CH,CURLOPT_TIMEOUT,10);
curl_setopt($ CH,CURLOPT_POST,真正的);
curl_setopt($ CH,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ CH,CURLOPT_POSTFIELDS,$ json_data); $结果= curl_exec($ CH); 后续代码var_dump($结果);
死('Mailchimp执行');
这code只将用户添加到列表中,当我尝试添加同一用户的详细信息的两倍,它抛出在第二次尝试以下错误:
test@user.com已经是列表成员。使用Patch更新现有成员。
块引用>我如何去使用PATCH更新用户信息?我不知道在哪里可以指定它。
解决方案我想通了,我要去哪里错了。当用户最初添加到列表中的响应提供一个ID。我需要的ID存储在我的那些人的详细信息数据库和我在做的时候我想在Mailchimp列表更新用户的详细信息的调用URL引用的ID。
<$p$p><$c$c>https://us2.api.mailchimp.com/3.0/lists/<list_id_goes_here>/members/<members_id_goes_here>
感谢@TooMuchPete正确的curl命令。
curl_setopt($ CH,CURLOPT_CUSTOMREQUEST,补丁);
I have this code below that adds a user to a 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 only adds users to the list and when I try add the details of the same user twice it throws the following error on the second attempt:
test@user.com is already a list member. Use PATCH to update existing members.
How do I go about using PATCH to update user details? I'm not sure where to specify it.
解决方案I figured out where I'm going wrong. When the user is initially added to the list the response provides an ID. I need to store the ID in my database with those person's details and reference the ID in the url I'm making a call to when I want to update the user's details in the Mailchimp List.
https://us2.api.mailchimp.com/3.0/lists/<list_id_goes_here>/members/<members_id_goes_here>
Thanks @TooMuchPete for the correct curl command.
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
这篇关于使用卷曲和Mailchimp API V3列表更新用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!