Search code examples
node.jsmailchimpmailchimp-api-v3.0

Mailchimp: The API key provided is linked to a different datacenter


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).


Solution

  • 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);
    });