我们正在将 Mailchimp 实施从 1.3 更新到 3.0。我们成功地更新了我们的代码,让某人订阅了一个列表。现在我们正在尝试添加电子商务订单。在 API v1.3 中,我们使用函数campaignEcommOrderAdd
. 我在 v3.0 中找到了这个功能:(/ecommerce/stores/{store_id}/orders
网站链接)。
但我无法让它工作。发布到 Mailchimp 时,我收到 404 错误,但我不知道我做错了什么。下面是我的代码。
$apiKey = "xxx"; //xxx for privacy reasons
$json = json_encode(array(
'id' => $mailchimp_order['id'],
'customer' => array(
'id' => $mailchimp_order['email_id'],
),
'campaign_id' => $mailchimp_order['campaign_id'],
'currency_code' => "EUR",
'order_total' => $mailchimp_order['total'],
'tax_total' => $mailchimp_order['tax'],
'lines' => $mailchimp_order['items'],
));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/ecommerce/stores/'.$mailchimp_order['store_id'].'/orders';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
这是我的$json
var 的输出:
{
"id":"10000003",
"customer":{
"id":"a90f52f710"
},
"campaign_id":"641657",
"currency_code":"EUR",
"order_total":"56.90",
"tax_total":"47.02",
"lines":[
{
"id":"224",
"product_id":"4427",
"product_title":"Product name",
"product_variant_id":0,
"quantity":"1",
"price":"49.95"
}
]
}
这是我得到的错误:
object(stdClass) {
type => 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/'
title => 'Resource Not Found'
status => (int) 404
detail => 'The requested resource could not be found.'
instance => ''
}