[英]Can't add user to a group using MailChimp API 3.0
I'm trying to update my code for subscribing new users to my MailChimp newsletter. 我正在尝试更新我的代码以订阅新用户到我的MailChimp时事通讯。
I would like it to add the user to a group, so that I can distinguish between users when sending out newsletters. 我希望将用户添加到一个组中,这样我就可以在发送简报时区分用户。 This code, however, subscribes the user but does not add it to any group.
但是,此代码订阅用户,但不会将其添加到任何组。 What am I doing wrong?
我究竟做错了什么? I am using the MailChimp API 3.0.
我正在使用MailChimp API 3.0。
My code: 我的代码:
$apiKey = 'XXXX';
$list_id = 'XXXX';
$memberId = md5(strtolower($data['email']));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . $memberId;
$json = json_encode(array(
'email_address' => $data['email'],
'status' => $data['status'], // "subscribed","unsubscribed","cleaned","pending"
'merge_fields' => array(
'FNAME' => $data['firstname'],
'LNAME' => $data['lastname'],
'GROUPINGS' => array(
0 => array(
'name' => 'Interests',
'groups' => array( $data['tag'] ),
),
),
),
));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
You are passing Interest grouping in the wrong array. 您正在错误的数组中传递兴趣分组。 you need to pass the interest group id in
interests
array with value as true
. 你需要传递
interests
数组中的兴趣组ID,其值为true
。
$json = json_encode(array(
'email_address' => 'test@example.com',
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => 'FirstName',
'LNAME' => 'LastName',
),
'interests' => array(
'9143cf3bd1' => true,
'789cf3bds1' => true
),
));
You will get the id of interest groups [ 9143cf3bd1,789cf3bds1
in above example] of the list by requesting to this URL 您将通过请求此URL获取列表中的兴趣组[
9143cf3bd1,789cf3bds1
]的ID
/lists/{list_id}/interest-categories
If you want to remove the subscriber from the group, you need to set its value to false
in your update request. 如果要从组中删除订户,则需要在更新请求中将其值设置为
false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.