我在使用 Mailchimp API 批量取消标记订阅者时遇到问题。
在文档中https://mailchimp.com/developer/guides/how-to-use-tags/#Tag_multiple_contacts_in_bulk 是示例:
{
"members_to_remove": [
"john.smith@example.com",
"brad.hudson@example.com"
]
}
您可以在下面看到我的 PHP 代码,其中我使用 $methode 变量给出值members_to_remove并且 $email 值是一个包含电子邮件地址的数组。
但该脚本仅向订阅添加大量标签,而不是删除。
我错了什么?
public function tag_mailchimp($list_id, $email, $tag, $method) {
$authToken = 'HERE MY KEY';
// The data to send to the API
$postData = array(
$method => $email
);
// Setup cURL
$ch = curl_init('https://us2.api.mailchimp.com/3.0/lists/'.$list_id.'/segments/'.$tag);
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Authorization: apikey '.$authToken,
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($postData)
));
// Send the request
$response = curl_exec($ch);
return $response;
}