6

I am trying to update a Mailchimp list but receive the following error:

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

However, the data-center referenced in my request URL is the same (us14) as the one suffixing my API key.

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'
    }
}

I have tried generating new API keys to no avail (they're all in us14).

Will
  • 546
  • 5
  • 16
  • Have you tested the same API key with the [API playground](https://us1.api.mailchimp.com/playground/)? If so, does it work? – ekad Jan 23 '17 at 09:14
  • Yes, it does. @ekad – Will Jan 23 '17 at 19:56
  • 4
    I'm having the same issue. For how great mailchimp is their API and docs are pretty awful. Wasting so much time to do a basic thing. – ndimatteo Jan 26 '17 at 22:53

2 Answers2

7

Ok I was able to get this to work by first passing your API Key via the headers object. Second, I wrapped my data in JSON.stringify to ensure MailChimp was receiving a proper JSON Object on post. See below for sample code, hope this helps:

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);
});
ndimatteo
  • 498
  • 5
  • 22
-1
const options = {
    method: "POST",
    auth: "uname:apikey656a******d2dfdb37c071a7cc-us19" //Should not give a space after a colon after uname
  }

I had given a Space after the colon of uname. Now the API is working fine