mercredi 18 février 2015

"Missing end time." in good calendar API request

I am trying to connect my node application to the google calendar API, this is working fine when requesting events however if I try and insert one I keep getting a 400 response "Missing end time."


I am using nodes request module to handle the request and passing in my OAuth token from passport.


Here is my code:



return request({
method: 'POST',
url: this.url+req.params.calendarId+'/events', //http://ift.tt/1BlRtw4
json: true,
body: JSON.stringify({
"end": {
"dateTime": "2015-03-01T16:00:00",
"date": "2014-03-01",
"timeZone": "Europe/London"
},
"start": {
"dateTime": "2015-03-01T15:00:00",
"date": "2014-03-01",
"timeZone": "Europe/London"
}
}),
auth: {
bearer: req.session.passport.user.token //OAuth token
},
qs: {
key: apiKey //API key
}
});


And this is the response:



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


And this is the requests headers:



POST /api/calendar/heathwallace.com_gpupieshkuc85dd832m9gjrh9g@group.calendar.google.com HTTP/1.1
Host: localhost:3000
Connection: keep-alive
Content-Length: 155
Accept: */*
Origin: http://localhost:3000
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost:3000/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Cookie: [session data]


I have spent a few hours trying to figure out where I am going wrong but I can't see any issues in my code or request. Has anyone got any ideas what might be happening?


2 commentaires: