【发布时间】:2020-05-26 10:23:13
【问题描述】:
我在尝试添加/更新现有用户的标签时遇到了一些问题。
当我更新现有成员信息时,它不会更新标签(使用方法“PATCH”)。它更新所有字段,但不更新标签。当我在列表中创建一个新成员(使用方法“POST”)时,它会创建标签。
我使用的代码是:
function add_suscriber($data)
{
//Data Format:
//$data = array(
//'apikey' => $api_key,
//'listid' => $list_id,
//'email_address' => $email,
//'status' => $suscripcion,
//'tags' => array($tags),
//'merge_fields' => array(
// 'FNAME' => $nombre, //nombre
// 'LNAME' => $apellido, //apellido
// 'PAIS' => $pais //pais de residencia
// )
//);
$API_URL = 'https://' . substr($data['apikey'],strpos($data['apikey'],'-') + 1 ) . '.api.mailchimp.com/3.0/lists/' . $data['listid'] . '/members/' . md5(strtolower($data['email_address']));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.base64_encode( 'user:'.$data['apikey'] )));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
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_encode($data) );
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result);
}
有了这个,当它是一个新用户时我没有问题;但如果用户已经存在(在任何受众中),所有内容都会更新,但标签不会更新。
提前感谢您的帮助!
【问题讨论】: