我正在尝试更新Mailchimp列表,但收到以下错误:
{ "type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/", "title":"Wrong Datacenter", "status":403, "detail":"The API key provided is linked to a different datacenter", "instance":"" }
但是,我的请求URL中引用的数据中心与后缀我的API密钥的数据中心相同(us14)。
request.put({ url: 'https://us14.api.mailchimp.com/3.0/lists/xxxxxxxxx/members/', auth: { user: 'apikey:xxxxxxxxxxxxxxxxxxxxx-us14' }, data: { email_address: email, status_if_new: 'subscribed', email_type: 'html' } }
我尝试生成新的API密钥无济于事(它们全部在us14中)。
好的,我能够通过首先通过headers
对象传递API密钥来使其工作。其次,我包装了数据JSON.stringify
以确保MailChimp在发布时收到正确的JSON对象。参见下面的示例代码,希望对您有所帮助:
request.post({
url: 'https://usXX.api.mailchimp.com/3.0/lists/xxxxxxx/members',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic xxxxxxxxxxxxxxxxxxxxxxxxx-usXX'
},
form: JSON.stringify({
email_address: req.body.email,
status: 'subscribed',
interests: { 'xxxxxxx': true } // Interest Group
})
}, function(err, httpResponse, body) {
res.send(body);
});