title: Linking Netatmo Weather Station to Amazon Echo (Alexa)
body: <p>[Full tutorial in the answered question below. Feedback welcome!]</p>
  
  <p>I am trying to create an AWS Lambda function to use for an Amazon Alexa skill to fetch weather information from my Netatmo weatherstation. Basically, I need to connect to the Netatmo cloud via http request. </p>
  
  <p>Here's a snippet of my code, the http request is done for the temporary access token, the request is ok but the result body is body: {"error":"invalid_request"}. What could be the problem here?</p>
  
  <pre><code>var clientId = "";
  var clientSecret = "";
  var userId="a@google.ro"; 
  var pass=""; 
  
  function getNetatmoData(callback, cardTitle){
      var sessionAttributes = {};
  
      var formUserPass = { client_id: clientId, 
      client_secret: clientSecret, 
      username: userId, 
      password: pass, 
      scope: 'read_station', 
      grant_type: 'password' };
  
      shouldEndSession = false;
      cardTitle = "Welcome";
      speechOutput =""; 
      repromptText ="";
  
      var options = {
          host: 'api.netatmo.net',
          path: '/oauth2/token',
          method: 'POST',
          headers: {
              'Content-Type': 'application/x-www-form-urlencoded',
              'client_id': clientId,
              'client_secret': clientSecret,
              'username': userId, 
              'password': pass, 
              'scope': 'read_station', 
              'grant_type': 'password'
          }
      };
      var req = http.request(options, function(res) {
              res.setEncoding('utf8');
              res.on('data', function (chunk) {
                  console.log("body: " + chunk);
  
              });
  
              res.on('error', function (chunk) {
                  console.log('Error: '+chunk);
              });
  
              res.on('end', function() {
  
                  speechOutput = "Request successfuly processed."
                  console.log(speechOutput);
                  repromptText = ""
                  callback(sessionAttributes, buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
              });
  
          });
  
          req.on('error', function(e){console.log('error: '+e)});
  
          req.end();
  }
  </code></pre>