javascript - Making an Ajax request in Amazon S3 using a Lambda function -
i'm trying fetch json response weatherdata coming netatmo cloud, using lambda function/javascript in amazon s3 aws. first trying fetch token using following method. seems dollar sign not recognized. gives?
function getnetatmodata(){ var clientid = "******"; var clientsecret = "******"; var userid="******@******.com"; var parola="******"; var formuserpass = { client_id: clientid, client_secret: clientsecret, username: userid, password: parola, scope: 'read_station', grant_type: 'password' }; $.ajax({ async: false, url: "https://api.netatmo.net/oauth2/token", type: "post", datatype: "json", data: formuserpass, success: function(token){ // awesome token.. } }); console.log("http request successful..."); }
looks trying use jquery ajax method. if jquery isn't loaded won't work. i'm not familiar aws lambda interface if possible load jquery before script run, seem best bet.
your other option vanilla javascript xmlhttprequest. peeked around @ netatmo's documentation , looks should work
function getnetatmodata(){ var clientid = "******"; var clientsecret = "******"; var userid="******@******.com"; var parola="******"; var formuserpass = { client_id: clientid, client_secret: clientsecret, username: userid, password: parola, scope: 'read_station', grant_type: 'password' }; var req = new xmlhttprequest(); req.open('post',"https://api.netatmo.net/oauth2/token", false); req.setrequestheader("content-type", "application/x-www-form-urlencoded;charset=utf-8"); req.onload = function (e) { if (req.status == 200) { console.log('http request successful', req.response) } else if (req.status == 400) { console.log('there error') } else { console.log('there else went wrong') } } req.onerror = function (e) { // error console.log("there error", req.response); } req.send(formuserpass); }
Comments
Post a Comment