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

2

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

Chung answered 22/1, 2017 at 17:23 Comment(3)
Have you tested the same API key with the API playground? If so, does it work?Kruse
Yes, it does. @KruseChung
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.Lenticularis
L
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);
});
Lenticularis answered 27/1, 2017 at 6:47 Comment(0)
G
-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

Ghetto answered 6/3, 2020 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.