Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger script on Google calendar event

I want to trigger some script when new calendar event is created in Google Calendar (say calling some rest API that enters event information to my database). I do not want any kind of UI that triggers the script.
Is it possible to achieve this using Google gadget since I do not want any UI? I would really appreciate the help as I am new to Google API.

Thanks a lot
Shubhra

like image 835
Shubhra Avatar asked Jan 23 '14 07:01

Shubhra


People also ask

What is trigger in Google script?

Triggers let Apps Script run a function automatically when a certain event, like opening a document, occurs. Simple triggers are a set of reserved functions built into Apps Script, like the function onOpen(e) , which executes when a user opens a Google Docs, Sheets, Slides, or Forms file.


2 Answers

Calendar API has something like notifications. See this link: Push Notifications. From documentation:

The Google Calendar API provides push notifications that let you watch for changes to resources. You can use this feature to improve the performance of your application. It allows you to eliminate the extra network and compute costs involved with polling resources to determine if they have changed. Whenever a watched resource changes, the Google Calendar API notifies your application.

like image 104
Michał Ziober Avatar answered Nov 15 '22 10:11

Michał Ziober


Google Calendar API (relevant docs) provides a watch endpoint that allows you to specify a webhook upon certain events.

To set up the webhook, you can call the Calendar API endpoint a POST request to https://www.googleapis.com/calendar/v3/calendars/calendarId/events/watch with the body

{
  "id": string
  "type": string,
  "address": string
}

The "address" field tells Calendar what endpoint to call when there is a new Calendar event. You'll need to create and host this endpoint yourself.

Another option is to use a service like Zapier, which has fantastic integrations for Google Calendar and makes setting up a listener (i.e. a trigger) and corresponding action very simple.

like image 31
rayray Avatar answered Nov 15 '22 10:11

rayray