javascript - Google Calendar API Request not Going Through with Node.js (Express) + Request Library -


i writing server employs google calendar api. have made 1 successful request, post request is supposed create new calendar returns following error in http response body:

{  "error": {   "errors": [    {     "domain": "global",     "reason": "required",     "message": "required"    }   ],   "code": 400,   "message": "required"  } } 

i using node.js, express, , wrapper of node's http library called request (by mikeal) make requests google's api. ask question because error message quite cryptic. if figure out, great!

some code samples included below understand more:

setuptaskscalendar method (makes request create new calendar):

var setuptaskscalendar = function(req, callback) {     oauth.makeapicall({       method: 'post',       url: 'https://www.googleapis.com/calendar/v3/calendars',       body: json.stringify({         summary: "google calendar tasks"       })     }, req, function(e, body) {       if (e) console.log(e);       console.log(body);       callback();     });   }; 

makeapicall method (a wrapper method makes needed checks , adds auth token url):

this.makeapicall = function(parameters, req, callback) {     if (date.now() >= req.session.user.token_expiration_time) {       self.auth.updateaccesstoken(req, function() {         parameters.url = self.addaccesstoken(parameters.url, req);         request(parameters, function(e, r, body) {           if (e) console.log(e);           callback(e, body);         });       });     } else {       parameters.url = self.addaccesstoken(parameters.url, req);       request(parameters, function(e, r, body) {         if (e) console.log(e);         callback(e, body);       });     }   }; 

i figured out! turns out putting json in body wasn't enough: needed make sure request had application/json content-type. in request, had to...

replace this:

body: json.stringify({     summary: "google calendar tasks"     }) 

with this:

json: {     summary: "google calendar tasks"     } 

Comments