我正在运行MailChimp subscribe
API调用。发送的JSON对象如下所示:
{
"apikey":"someAPIkey-us10",
"id":"someID",
"email":{
"email":"example@su.vi"
},
"merge_vars":{
"products":[
{
"name":"prod",
"url":"https:\/\/www.example.co.uk\/properties\/link\/sub\/res",
"price":"\u00a3378.00",
"location":"loc",
"area":"are"
}
]
},
"double_optin":false
}
和执行curl
对象的php代码如下所示:
$curl = curl_init(SEED_URL);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array(
"Accept: application/json",
"Content-Type: application/json",
"Content-Length: " . strlen($jsonStr)
)
);
$response = curl_exec($curl);
var_dump($response);
$responseCode = curl_getinfo ($curl , CURLINFO_HTTP_CODE);
if ($responseCode !== 201) {
throw new Exception("post failed with response code " . $responseCode . " " . $jsonStr, 1);
}
$response
转储有效,如下所示:
"{"email":"example@su.vi","euid":"someEUID","leid":"someLEID"}"
然而
抛出发布失败,回复代码为200。
,并且没有在mailChimp服务器中填充订户列表。