我首先使用Mailchimp API获取列表的marketing_permission_id。响应看起来像这样
[marketing_permission_id] => f878932739
然后在第二个api调用中使用此值来更新特定用户的设置。但是,我得到了错误:
字符串(227) “ {” type“:” http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/“,” title“:”错误 请求”,“状态”:400,“详细信息”:“营销许可ID”不正确 存在。”,[...]
我再次检查了第二个呼叫中正在发送的数据,并且其中具有正确的marketing_permission_id:
{"marketing_permissions":{"marketing_permission_id":"f878932739","enabled":true}}
我遵循https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#%20中的格式。
我不明白怎么了。希望这里有人这样做..:)
答案 0 :(得分:0)
只需将其留作以后参考-谷歌上没有具有营销许可的mailchimp API的提示... 这是我用于将联系人添加到列表的基本功能。
function syncMailchimp($userdata,
$apiKey, $listId)
{
$dataCenter = substr($apiKey,
strpos($apiKey, '-') +
1);
$url = 'https://'.$dataCenter.
'.api.mailchimp.com/3.0/lists/'
.$listId.
'/members/';
// This is the interesting part //
$json = json_encode([
'email_address' => $userdata[
'email'],
'status' => $userdata['status'], // "subscribed","unsubscribed","cleaned","pending"
'merge_fields' => [
'FNAME' => $userdata[
'firstname'
],
'LNAME' => $userdata['lastname']
],
'tags' => [
'added'
],
// How to build the Array -->
'marketing_permissions' =>
array(
0 =>
array(
'marketing_permission_id' =>
'1e5142bbce',
'enabled' =>
true,
),
),
]);
$ch = curl_init($url);
curl_setopt($ch,
CURLOPT_HTTPAUTH,
CURLAUTH_BASIC);
$headers = array(
'Content-Type:application/json',
'Authorization: apikey '
.$apiKey
);
curl_setopt($ch,
CURLOPT_HTTPHEADER,
$headers);
curl_setopt($ch,
CURLOPT_RETURNTRANSFER,
true);
curl_setopt($ch,
CURLOPT_TIMEOUT, 10);
curl_setopt($ch,
CURLOPT_CUSTOMREQUEST,
'POST');
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);
return $result;
}