- [Resource: Subscription](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#Subscription)
  - [JSON representation](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#Subscription.SCHEMA_REPRESENTATION)
- [DriveOptions](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#DriveOptions)
  - [JSON representation](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#DriveOptions.SCHEMA_REPRESENTATION)
- [PayloadOptions](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#PayloadOptions)
  - [JSON representation](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#PayloadOptions.SCHEMA_REPRESENTATION)
- [NotificationEndpoint](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#NotificationEndpoint)
  - [JSON representation](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#NotificationEndpoint.SCHEMA_REPRESENTATION)
- [State](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#State)
- [ErrorType](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#ErrorType)
- [Methods](https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#METHODS_SUMMARY)

## Resource: Subscription

> [!WARNING]
> **Developer Preview:** Available as part of the [Google Workspace Developer Preview Program](https://developers.google.com/workspace/preview), which grants early access to certain features.

A subscription to receive events about a Google Workspace resource. To learn more about subscriptions, see the [Google Workspace Events API overview](https://developers.google.com/workspace/events).

| JSON representation |
|---|
| ``` { "name": string, "uid": string, "targetResource": string, "eventTypes": [ string ], "payloadOptions": { object (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#PayloadOptions`) }, "notificationEndpoint": { object (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#NotificationEndpoint`) }, "state": enum (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#State`), "suspensionReason": enum (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#ErrorType`), "authority": string, "createTime": string, "updateTime": string, "reconciling": boolean, "etag": string, "driveOptions": { object (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#DriveOptions`) } "userAuthority": string, "serviceAccountAuthority": string "expireTime": string, "ttl": string } ``` |

| Fields ||
|---|---|
| `name` | `string` Identifier. Resource name of the subscription. Format: `subscriptions/{subscription}` |
| `uid` | `string` Output only. System-assigned unique identifier for the subscription. |
| `targetResource` | `string` Required. Immutable. The Google Workspace resource that's monitored for events, formatted as the [full resource name](https://google.aip.dev/122#full-resource-names). To learn about target resources and the events that they support, see [Supported Google Workspace events](https://developers.google.com/workspace/events#supported-events). A user can only authorize your app to create one subscription for a given target resource. If your app tries to create another subscription with the same user credentials, the request returns an `ALREADY_EXISTS` error. |
| `eventTypes[]` | `string` Required. Unordered list. Input for creating a subscription. Otherwise, output only. One or more types of events to receive about the target resource. Formatted according to the CloudEvents specification. The supported event types depend on the target resource of your subscription. For details, see [Supported Google Workspace events](https://developers.google.com/workspace/events/guides#supported-events). By default, you also receive events about the [lifecycle of your subscription](https://developers.google.com/workspace/events/guides/events-lifecycle). You don't need to specify lifecycle events for this field. If you specify an event type that doesn't exist for the target resource, the request returns an HTTP `400 Bad Request` status code. |
| `payloadOptions` | ``object (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#PayloadOptions`)`` Optional. Options about what data to include in the event payload. Only supported for Google Chat and Google Drive events. |
| `notificationEndpoint` | ``object (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#NotificationEndpoint`)`` Required. Immutable. The endpoint where the subscription delivers events, such as a Pub/Sub topic. |
| `state` | ``enum (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#State`)`` Output only. The state of the subscription. Determines whether the subscription can receive events and deliver them to the notification endpoint. |
| `suspensionReason` | ``enum (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#ErrorType`)`` Output only. The error that suspended the subscription. To reactivate the subscription, resolve the error and call the `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions/reactivate#google.apps.events.subscriptions.v1beta.SubscriptionsService.ReactivateSubscription` method. |
| `authority` | `string` Output only. The user who authorized the creation of the subscription. When a user authorizes the subscription, this field and the `userAuthority` field have the same value and the format is: Format: `users/{user}` For Google Workspace users, the `{user}` value is the [`user.id`](https://developers.google.com/admin-sdk/directory/reference/rest/v1/users#User.FIELDS.ids) field from the Directory API. When a Chat app authorizes the subscription, only `serviceAccountAuthority` field populates and this field is empty. |
| `createTime` | ``string (`https://protobuf.dev/reference/protobuf/google.protobuf#timestamp` format)`` Output only. The time when the subscription is created. |
| `updateTime` | ``string (`https://protobuf.dev/reference/protobuf/google.protobuf#timestamp` format)`` Output only. The last time that the subscription is updated. |
| `reconciling` | `boolean` Output only. If `true`, the subscription is in the process of being updated. |
| `etag` | `string` Optional. This checksum is computed by the server based on the value of other fields, and might be sent on update requests to ensure the client has an up-to-date value before proceeding. |
| Union field `subscription_options`. Additional subscription options available to specific target resources for Google Workspace subscriptions. `subscription_options` can be only one of the following: ||
| `driveOptions` | ``object (`https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#DriveOptions`)`` Optional. Features that are supported only for subscriptions on Drive resources. |
| Union field `authority_info`. The identity that authorized the creation of the subscription. `authority_info` can be only one of the following: ||
| `userAuthority` | `string` Output only. The user who authorized the creation of the subscription. The user must be able to view the `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#Subscription.FIELDS.target_resource`. For Google Workspace users, the `{user}` value is the [`user.id`](https://developers.google.com/workspace/admin/directory/reference/rest/v1/users#User.FIELDS.id) field from the Directory API. Format: `users/{user}` |
| `serviceAccountAuthority` | `string` Output only. The service account that was used to authorize the creation of the subscription. This service account must be owned by the same Google Cloud project where you created this subscription. Format: `projects/{projectId}/serviceAccounts/{service_account_id}` |
| Union field `expiration`. The time when the subscription expires. The maximum expiration time depends on whether your subscription includes resource data in event payloads (specified in the `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#PayloadOptions` field): - If payloads omit resource data, up to 7 days. - If payloads include resource data, up to 4 hours. If your Google Workspace organization grants access to the resource through [domain-wide delegation](https://support.google.com/a/answer/162106), you can extend the subscription's expiration time to up to 24 hours. After a subscription expires, it's deleted automatically. You receive lifecycle events to the `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#Subscription.FIELDS.notification_endpoint` 12 hours and one hour before the subscription expires. For details, see [Receive and respond to lifecycle events](https://developers.google.com/workspace/events/guides/events-lifecycle). To prevent a subscription from expiring, you can use the `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions/patch#google.apps.events.subscriptions.v1beta.SubscriptionsService.UpdateSubscription` method to extend its expiration date. For details, see [Update or renew a subscription](https://developers.google.com/workspace/events/guides/update-subscription). `expiration` can be only one of the following: ||
| `expireTime` | ``string (`https://protobuf.dev/reference/protobuf/google.protobuf#timestamp` format)`` Non-empty default. The timestamp in UTC when the subscription expires. Always displayed on output, regardless of what was used on input. |
| `ttl` | ``string (`https://protobuf.dev/reference/protobuf/google.protobuf#duration` format)`` Input only. The time-to-live (TTL) or duration for the subscription. If unspecified or set to `0`, uses the maximum possible duration. |

## DriveOptions

Additional supported options for serving Drive events.

| JSON representation |
|---|
| ``` { "includeDescendants": boolean } ``` |

| Fields ||
|---|---|
| `includeDescendants` | `boolean` Optional. Immutable. For subscriptions to Google Drive events, whether to receive events about Drive files that are children of the target folder or shared drive. - If `false`, the subscription only receives events about changes to the folder or shared drive that's specified as the `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#Subscription.FIELDS.target_resource`. - If `true`, the `mimeType` field of the `file` resource must be set to `application/vnd.google-apps.folder`. For details, see [Google Drive event types](https://developers.google.com/workspace/events/guides/events-drive#event-types). |

## PayloadOptions

Options about what data to include in the event payload. Only supported for Google Chat and Google Drive events.

| JSON representation |
|---|
| ``` { "includeResource": boolean, "fieldMask": string } ``` |

| Fields ||
|---|---|
| `includeResource` | `boolean` Optional. Whether the event payload includes data about the resource that changed. For example, for an event where a Google Chat message was created, whether the payload contains data about the [`Message`](https://developers.google.com/chat/api/reference/rest/v1/spaces.messages) resource. If false, the event payload only includes the name of the changed resource. |
| `fieldMask` | ``string (`https://protobuf.dev/reference/protobuf/google.protobuf#field-mask` format)`` Optional. If `includeResource` is set to `true`, the list of fields to include in the event payload. Separate fields with a comma. For example, to include a Google Chat message's sender and create time, enter `message.sender,message.createTime`. If omitted, the payload includes all fields for the resource. If you specify a field that doesn't exist for the resource, the system ignores the field. |

## NotificationEndpoint

The endpoint where the subscription delivers events.

| JSON representation |
|---|
| ``` { "pubsubTopic": string } ``` |

| Fields ||
|---|---|
| Union field `endpoint`. `endpoint` can be only one of the following: ||
| `pubsubTopic` | `string` Immutable. The Pub/Sub topic that receives events for the subscription. Format: `projects/{project}/topics/{topic}` You must create the topic in the same Google Cloud project where you create this subscription. Note: The Google Workspace Events API uses [ordering keys](https://cloud.google.com/pubsub/docs/ordering) for the benefit of sequential events. If the Cloud Pub/Sub topic has a [message storage policy](https://cloud.google.com/pubsub/docs/resource-location-restriction#exceptions) configured to exclude the nearest Google Cloud region, publishing events with ordering keys will fail. When the topic receives events, the events are encoded as Pub/Sub messages. For details, see the [Google Cloud Pub/Sub Protocol Binding for CloudEvents](https://github.com/googleapis/google-cloudevents/blob/main/docs/spec/pubsub.md). |

## State

Possible states for the subscription.

| Enums ||
|---|---|
| `STATE_UNSPECIFIED` | Default value. This value is unused. |
| `ACTIVE` | The subscription is active and can receive and deliver events to its notification endpoint. |
| `SUSPENDED` | The subscription is unable to receive events due to an error. To identify the error, see the `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions#Subscription.FIELDS.suspension_reason` field. |
| `DELETED` | The subscription is deleted. |

## ErrorType

Possible errors for a subscription.

| Enums ||
|---|---|
| `ERROR_TYPE_UNSPECIFIED` | Default value. This value is unused. |
| `USER_SCOPE_REVOKED` | The authorizing user has revoked the grant of one or more OAuth scopes. To learn more about authorization for Google Workspace, see [Configure the OAuth consent screen](https://developers.google.com/workspace/guides/configure-oauth-consent#choose-scopes). |
| `APP_SCOPE_REVOKED` | The domain administrator has revoked the grant of one or more OAuth scopes for the app. |
| `RESOURCE_DELETED` | The target resource for the subscription no longer exists. |
| `USER_AUTHORIZATION_FAILURE` | The user that authorized the creation of the subscription no longer has access to the subscription's target resource. |
| `APP_AUTHORIZATION_FAILURE` | The app that authorized the creation of the subscription no longer has access to the subscription's target resource. |
| `ENDPOINT_PERMISSION_DENIED` | The Google Workspace application doesn't have access to deliver events to your subscription's notification endpoint. |
| `ENDPOINT_NOT_FOUND` | The subscription's notification endpoint doesn't exist, or the endpoint can't be found in the Google Cloud project where you created the subscription. |
| `ENDPOINT_RESOURCE_EXHAUSTED` | The subscription's notification endpoint failed to receive events due to insufficient quota or reaching rate limiting. |
| `OTHER` | An unidentified error has occurred. |

| ## Methods ||
|---|---|
| ### `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions/create` | Creates a Google Workspace subscription. |
| ### `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions/delete` | Deletes a Google Workspace subscription. |
| ### `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions/get` | Gets details about a Google Workspace subscription. |
| ### `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions/list` | Lists Google Workspace subscriptions. |
| ### `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions/patch` | Updates or renews a Google Workspace subscription. |
| ### `https://developers.google.com/workspace/events/reference/rest/v1beta/subscriptions/reactivate` | Reactivates a suspended Google Workspace subscription. |