googleapis / googleapis/google-api-nodejs-client

How can I find out which event was added, changed or deleted from Google Calendar in my webhook?

Open
#3,202 1 comment 4 reactions 0 assignees View on GitHub
priority: p3 type: question
Dominant language
TypeScript
Stars
12.2k
Forks
2k
Avg merge
1d 9h
Merged PRs (30d)
24

Description

I added a watcher to events
```
calendar.events.watch({
calendarId: 'primary',
requestBody: {
id: 'my-unique-id',
type: 'web_hook',
address: 'https://my-server.com/api/events/calendar/webhook'
}
})
```
This returns me a data object as in the documentation.

```
{
"kind": "api#channel",
"id": string,
"resourceId": string,
"resourceUri": string,
"token": string,
"expiration": long
}
```
So, it works I think.

Then, I created a route for the webhook.
```
router.post('/calendar/webhook', async ctx => {
try {
console.log(ctx.request);
ctx.ok();
} catch (err) {
ctx.bad(400);
}
});
```

When I add a new event to the Google Calendar, I can see next in the console
This is the `ctx.request`
```
{
method: 'POST',
url: '/api/events/calendar/webhook',
header: {
host: 'my-server.com',
'user-agent': 'APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)',
'content-length': '0',
accept: '*/*',
'accept-encoding': 'gzip, deflate, br',
'x-forwarded-for': '',
'x-forwarded-proto': 'https',
'x-goog-channel-expiration': 'Fri, 31 Mar 2023 14:56:37 GMT',
'x-goog-channel-id': 'my-unique-id',
'x-goog-message-number': '9712313484225',
'x-goog-resource-id': 'resource-id',
'x-goog-resource-state': 'exists',
'x-goog-resource-uri': 'https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json'
}
}
```

How do I find out what exactly was changed in Google Calendar? whether an event was added or deleted or changed, what exactly the event was, such as its id?

I would be grateful for any help.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.