I am using a Google API library for Racket to try to update a Google Calendar. (The API is incomplete so I'm extending it as I go.)
I seem to have trouble with adding events to a calendar using the events.insert put call. The code that does the put looks like:
(define (insert-events calendar-id
event
#:token [t #f]
#:max-attendees [max-attendees #f]
#:send-notifications [send-notifications #f]
#:supports-attachments [supports-attachments #f])
(json-api-post (string->url
(format
"https://www.googleapis.com/calendar/v3/calendars/~a/events"
(form-urlencoded-encode calendar-id)))
event
#:token t))
(define (json-api-post u b
#:token [t #f]
#:headers [headers '()])
(define b* (jsexpr->bytes b))
(let retry ([t t]
[retry-counter 0])
(parse-json-response
(POST-string u b* (if t (cons (token->authorization-header t) headers) headers))
retry
t
retry-counter)))
(define (POST-string u b headers)
(port->string (post-pure-port u b headers)))
However, no matter how I use the call, I always get back an error 400 with the message: "Missing End Time". I checked out this question to ensure that I was sending my request correctly. Which I appear to be. For reference, the JSON object I am sending is:
{
"end": {
"dateTime": "2016-05-30T14:00:00-04:00"
},
"start": {
"dateTime": "2016-05-30T13:00:00-04:00"
}
}
Also, to make sure I was properly accessing the correct key and calendar id, I setup up an echo server for my local machine, and changed the url from google.com
to localhost
, my response seems normal:
POST /<Calendar-Id-Redacted> HTTP/1.1
Host: localhost
User-Agent: Racket/6.5.0.5 (net/http-client)
Content-Length: 116
Authorization: Bearer <Key-Redacted>
{
"end": {
"dateTime": "2016-05-30T14:00:00-04:00"
},
"start": {
"dateTime": "2016-05-30T13:00:00-04:00"
}
}
I seem to be doing everything correct. And even if there was a bug in my Racket code, sending in the exact same JSON object via Google's developer web console seems to work as intended. So why does sending this particular POST not work?