Mailchimp API 3.0 batch/bulk 取消标记
Mailchimp API 3.0 batch/bulk untag
我在使用 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 代码,其中我使用 $method 变量给出值 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;
}
有效,但我不知道我还能做什么..,代码:
foreach($members as $member) {
$list[] = $member->email;
}
$Mailer->tag_mailchimp('12345678', $list, 123456, 'members_to_remove');
在 class 中我有下一个函数:
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;
}
我在使用 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 代码,其中我使用 $method 变量给出值 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;
}
有效,但我不知道我还能做什么..,代码:
foreach($members as $member) {
$list[] = $member->email;
}
$Mailer->tag_mailchimp('12345678', $list, 123456, 'members_to_remove');
在 class 中我有下一个函数:
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;
}