AppsScriptPulse

Modernising Drive Monitoring: The Google Drive Events API is Now in Public Preview

Google Drive is now integrated with the Workspace Events API, which allows third-party developers to create subscriptions on Drive items and receive notifications via Cloud Pub/Sub when those resources change. This offers developers a more reliable, featureful way of receiving events over the current files.watch and changes.watch methods that exist today.

Good news for developers working with Google Drive! Google has just announced that the Google Drive Events API is now available in a Developer Public Preview. This is a significant update for anyone who needs to track changes to files in Google Drive, offering a more robust and feature-rich way to receive notifications.

For a long time, developers have relied on the files.watch and changes.watch methods to monitor file changes. Whilst these methods have been useful, the new Drive Events API, integrated with the Google Workspace Events API, promises a more reliable and scalable solution.

What can you do with the new API?

The new API allows you to subscribe to events on Drive items and receive notifications through Cloud Pub/Sub. In this initial public preview, the following events are supported:

  • A file has been added to a folder or shared drive.
  • A file has been moved to a folder or shared drive.
  • A file has been edited, or a new revision is uploaded.
  • A file has been trashed or restored from the trash.
  • An access proposal has been created or resolved for a file.

This opens up a whole range of possibilities for building powerful applications that react in real-time to changes in Google Drive. Imagine creating automated workflows that trigger when a new file is added to a specific folder, or a security tool that alerts you when a sensitive document is moved or trashed.

How to get started

To start using the new Google Drive Events API, you’ll need to be enrolled in the Workspace Developer Public Preview program. Once you’re in, you can find the relevant documentation and getting started guides on the Google Developers site.

A Note for Google Apps Script Developers

You can absolutely use Google Apps Script to make the API calls to create and manage your event subscriptions. However, it is important to be aware that receiving the actual notifications requires a different approach to traditional Apps Script triggers.

The Drive Events API delivers all notifications to a Cloud Pub/Sub topic. This means you will need a Google Cloud Platform (GCP) project to handle these incoming messages. It’s also important to note that, according to the documentation, the Pub/Sub topic you use for notifications must be in the same Google Cloud project that you use to create the event subscription itself.

These new capabilities hopefully unlock some more efficient ways for developers and third parties to monitor Google Drive content.

Source: Google Drive Events API now available in Developer Public Preview

New Advanced Google Workspace Events service for Google Apps Script


To subscribe to events using Apps Script, you can now use the Advanced Google Workspace Events service.

In the May 02, 2024 Google Apps Script release notes it was announced that a new Advanced Google Workspace Events service is available to let developers use the Google Workspace Events API directly in Google Apps Script. The Google Workspace Events API is a relatively new API, which was released to developer preview in January, 2024. The Google Workspace Events API uses a subscription model to handle resource changes. When you create a subscription, you specify the target resource (such as a Google Chat space or Google Meet meeting space) and the event types that you want to subscribe to. The API then sends notifications to your specified endpoint whenever an event occurs for that resource and event type.

In the case of the new Advanced Google Workspace Events service the linked documentation includes samples for using the new service with Google Chat. It’s worth noting that the Advanced Google Workspace Events service is designed specifically on managing subscriptions to events. While it lets you to control the flow of information and manage event subscriptions in your Apps Script projects, the actual processing and handling of event data occurs separately.

The linked documentation page provides sample code as well as outlines all the prerequisites.

Source: Advanced Google Workspace Events Service