The Advanced Google Workspace Events service lets you use the Google Workspace Events API in Apps Script. This API lets you subscribe to Google Workspace resources so that you receive relevant events that you're interested in. Events represent changes to resources, such as when resources are created, updated, or deleted.
Prerequisites
- An Apps Script project using a standard Google Cloud project instead of the default one created automatically by Apps Script.
- A Pub/Sub topic created in the same Google Cloud project to receive subscription events. To create a Pub/Sub topic, see Create and subscribe to a Pub/Sub topic.
- To subscribe to Chat events, you must have a Google Chat app configured on the Chat API configuration page in the Google Cloud console. To create a Google Chat app, see Build a Google Chat app with Apps Script.
The necessary authorization scopes added to the Apps Script project's
appsscript.json
file. The necessary scopes depend on the types of the subscriptions' target resources and events. For details, see Choose Google Workspace Events API scopes. For example:"oauthScopes": [ "https://www.googleapis.com/auth/chat.messages.readonly" ]
Reference
For more information about this service, see the Google Workspace Events API reference documentation. Like all advanced services in Apps Script, the Google Workspace Events service uses the same objects, methods, and parameters as the public API.
Sample code
These samples show you how to perform common Google Workspace Events API actions using the advanced service.
Create a subscription
To create a subscription to a Google Workspace resource, add the following function to the Apps Script project's code:
List subscriptions
To list subscriptions filtered by event types and target resource, add the following function to the Apps Script project's code:
Get subscription
To get information about a subscription, add the following function to the Apps Script project's code:
Update subscription
To update or renew a subscription, add the following function to the Apps Script project's code:
Reactivate subscription
To reactivate a subscription, add the following function to the Apps Script project's code:
Delete subscription
To delete a subscription, add the following function to the Apps Script project's code:
Get operation
Most Google Workspace Events API methods return a
long-running operation.
To determine the status of the operation, you can use the
operations.get()
method.
To get information about an operation, add the following function to the Apps Script project's code:
To get the name of an operation, use the value from the name
field returned
from one of the Google Workspace Events API methods, such as
subscriptions.create()
or
subscriptions.patch()
.