title: MailChimp Login API "bad request"
body: <p>This is similar to the following issue: <a href="https://stackoverflow.com/questions/24569769/mailchimp-api-login-returning-bad-request/29636055?noredirect=1#comment47416629_29636055">Mailchimp API login returning &quot;bad request&quot;</a></p>
  
  <p>I'm reposting with my results, as the solution on that question did not solve my problem. My app works fine when I use my self-generated API key, but when I try to use the token to verify, I get a 400 response with the following: </p>
  
  <p> 
  <H1>Bad Request</H1> 
  Your browser sent a request that this server could not understand.<P> 
   Reference&#32;&#35;7&#46;c2f0660&#46;1429044353&#46;139e2e94 
   </p>
  
  <p>I'm using Node.js with Express.js 4.x, with the following validation code: </p>
  
  <p>function getLogin(key, id, callback) {
      console.log(' mailchimp login ');</p>
  
  <pre><code>var currentDomain = 'http://xxxxxxx.com/api/mailchimp/redirect/redirect';
  var translatedDomain = encodeURIComponent(currentDomain);
  var secret = 'xxxxxxxxxxxx';
  var clientId = 'xxxx';
  
  var post_data = {
      grant_type : 'authorization_code',
      client_id : clientId,
      client_secret : secret,
      code : key,
      redirect_uri : translatedDomain
  };
  
  var post_options = {
        host: 'login.mailchimp.com',
        path: '/oauth2/token',
        method: 'POST',
        headers: {
            'User-Agent' : 'oauth2-draft-v10',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Accept': 'application/json'
        }
    };
  
  var errors = false;
  
  // Set up the request
  var post_req = http.request(post_options, function(res) {
    var str = '';
    res.on('data', function (chunk) {
          str += chunk;
  
      });
  
    res.on('error', function (error) {
          console.log("error: " + error.message); 
          errors = true;
    });
  
    res.on('end', function () {
      console.log(str);
      try {
          var accessToken = JSON.parse(str);
          getEndpoint(accessToken.access_token, callback);
      } catch (error) {
          console.log('error: Error parsing JSON answer from the MailChimp API.');
          console.log(error);
          callback(false);
      }
    });     
  });
  
  // post the data
  post_req.write(querystring.stringify(post_data));
  post_req.end();
  </code></pre>
  
  <p>}</p>
  
  <p>I am able to successfully generate the code, but the token is being a problem. Ideas?</p>