Mailchimp:提供的API密钥链接到不同的数据中心

时间:2017-01-22 17:23:07

标签: node.js mailchimp mailchimp-api-v3.0

我正在尝试update a Mailchimp list,但收到以下错误:

{
 "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":""
}

但是,我的请求网址中引用的数据中心与后缀我的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 中)。

2 个答案:

答案 0 :(得分:4)

好的,我可以通过首先通过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);
});




答案 1 :(得分:0)

const options = {
    method: "POST",
    auth: "uname:apikey656a******d2dfdb37c071a7cc-us19" //Should not give a space after a colon after uname
  }

我在联盟的冒号后面给了一个空格。现在,API可以正常工作了