calendar.events.watch not working
Hi
A few days ago I started working with the Google Calendar API. First I went through the nodeJS quickstart guide and got the example working on my local environment. Now my goal is to get notified on my server when a new event is created or an existing event changes. If I understand the Google Calendar docs correctly I should use the watch endpoint which can be accessed by the calendar.events.watch method in the context of the quickstart guide.
Currently I'm trying to invoke calendar.events.watch like this:
import {google} from 'googleapis' // v 36.0.0
import uuid from 'uuid/v1'
const SCOPES = ['https://www.googleapis.com/auth/calendar']
// I didn't include the code which is doing the auth related stuff as it is exactly
// the same code as in the quickstarte guide
function watch () {
const calendar = google.calendar({version: 'v3', auth});
const options = {
"id": uuid(),
"token": "myToken123",
"type": "web_hook", // Don't know if web_hook is a valid type. I just copied it from other examples.
"address": "http://mywebsite.com",
"params": {
"ttl": "3600"
}
}
calendar.events.watch({calendarId: 'primary'}, options, (err, res) => {
console.log({err})
console.log({res})
return null
})
}
watch()
When I run the code above, the logged err-object contains "Error: entity.resource" and the res-object is undefined. Am I doing something wrong or is this a bug?
Thanks in advance!
You are passing options as parameter. Use requestBody instead.
Try the following format
calendar.events.watch({
calendarId: "primary",
token: "myToken123",
requestBody: {
id : "aasdf-123-fghj-qwer-5467a-333",
type: "web_hook",
address: "https://mywebsite.com",
}
}, (error, result) => {
if (error) throw error;
console.log(result);
});
the param has to be called requestBody, not options. please use requestBody specifically
and refer to this documentation
https://www.google.com/url?q=https://github.com/googleapis/google-api-nodejs-client%23specifying-request-body&sa=D&source=hangouts&ust=1545946160876000&usg=AFQjCNFmzljKGJn27Gw8s6DbtQ78J9Uutw
Let me know if it does solve your issue.
@vishald123 Worked! I missed that part completely. Many Thanks!
@DeCryptinWeb Glad that helped you!