List Google Workspace subscriptions Stay organized with collections Save and categorize content based on your preferences.
Page Summary
This page provides instructions on how to list Google Workspace subscriptions using the
subscriptions.list()method.The method returns a list of authorized subscriptions when using user authentication and may return any app subscription when using app authentication.
Code samples are provided for both Apps Script and Python to demonstrate listing subscriptions based on event type and target resource.
Prerequisites include having a Google Workspace subscription, proper authentication and setup for the chosen scripting language.
The response is a paginated array of
Subscriptionobjects matching the query filter.
This page explains how to list Google Workspace subscriptions using thesubscriptions.list()method.
When you call this method with user authentication, the method returnsa list of subscriptions authorized by the user. When you use app authentication,the method can return a list that contains any subscription for the app.
Prerequisites
Apps Script
- A Google Workspace subscription. To create one,seeCreate a subscription.
- An Apps Script project:
- Use your Google Cloud project instead of the default one created automatically by Apps Script.
- For all scopes that you added to configure the OAuth consent screen, you must also add the scopes to the
appsscript.jsonfile in your Apps Script project. For example, if you specified thechat.messagesscope, then add the following: - Enable the
Google Workspace Eventsadvanced service.
"oauthScopes": [ "https://www.googleapis.com/auth/chat.messages"]
Requires authentication and anappropriate authorization scope for each event type in the subscription:
- For user authentication, requires a scope that supports at least one of the event types for the subscription. To identify a scope, seeScopes by event type.Note: To run the code sample in this guide, you must use the sameOAuth client ID credentials that you used to create the subscription.
- For app authentication, requires the
chat.botscope (Google Chat apps only).
Python
- Python 3.6 or greater
- Thepip package management tool
- The latest Google client libraries for Python. To install or update them, run the following command in your command-line interface:
pip3 install --upgrade google-api-python-client google-auth-oauthlib
- A Google Workspace subscription. To create one,seeCreate a subscription.
Requires authentication and anappropriate authorization scope for each event type in the subscription:
- For user authentication, requires a scope that supports at least one of the event types for the subscription. To identify a scope, seeScopes by event type.Note: To run the code sample in this guide, you must use the sameOAuth client ID credentials that you used to create the subscription.
- For app authentication, requires the
chat.botscope (Google Chat apps only).
List subscriptions authorized by a user
To list subscriptions, you must filter by at least one event type. You can alsofilter your query by one or more target resources. To learn about supportedquery filters, see thelist() methoddocumentation.
The following code sample returns an array ofSubscription objectsfiltered by event type and target resource. When authenticated as a user, themethod only returns a list of subscriptions that the user authorized the app tocreate.
To list subscriptions for a specified event type and target resource:
Apps Script
In your Apps Script project, create a new script filenamed
listSubscriptionsand add the following code:functionlistSubscriptions(){// Filter for event type (required).consteventType='EVENT_TYPE';// Filter for target resource (optional).consttargetResource='TARGET_RESOURCE';constfilter=`event_types:"${eventType}" AND target_resource="${targetResource}"`// Call the Workspace Events API using the advanced service.constresponse=WorkspaceEvents.Subscriptions.list({filter});console.log(response);}Replace the following:
EVENT_TYPE: Anevent typeformatted according to the CloudEvents specification. For example,to filter for subscriptions that receive events about new membershipsto a Google Chat space,google.workspace.chat.message.v1.created.TARGET_RESOURCE: Atarget resource,formatted as its full resource name. For example, to filter bysubscriptions for a Google Chat space, use//chat.googleapis.com/spaces/SPACE_IDwherespaces/SPACE_IDrepresents thenamefield for theSpaceresource.
To list subscriptions, run the function
listSubscriptionsinyour Apps Script project.
Python
In your working directory, create a file named
list_subscriptions.pyand add the following code:"""List subscriptions."""fromgoogle_auth_oauthlib.flowimportInstalledAppFlowfromgoogleapiclient.discoveryimportbuild# Specify required scopes.SCOPES=['SCOPE']# Authenticate with Google Workspace and get user authentication.flow=InstalledAppFlow.from_client_secrets_file('credentials.json',SCOPES)CREDENTIALS=flow.run_local_server()# Call the Workspace Events API using the service endpoint.service=build('workspaceevents','v1',credentials=CREDENTIALS,)# Filter for event type (required).EVENT_TYPE='EVENT_TYPE'# Filter for target resource (optional).TARGET_RESOURCE='TARGET_RESOURCE'FILTER=f'event_types:"{EVENT_TYPE}" AND target_resource="{TARGET_RESOURCE}"'response=service.subscriptions().list(filter=FILTER).execute()print(response)Replace the following:
SCOPE: An OAuth scope thatsupports at leastone event type from the subscription. For example, if your subscription receives eventsan updated Chat space,https://www.googleapis.com/auth/chat.spaces.readonly.EVENT_TYPE: Anevent typeformatted according to the CloudEvents specification. For example,to filter for subscriptions that receive events about new membershipsto a Google Chat space,google.workspace.chat.message.v1.created.TARGET_RESOURCE: Atarget resource,formatted as its full resource name. For example, to filter bysubscriptions for a Google Chat space, use//chat.googleapis.com/spaces/SPACE_IDwherespaces/SPACE_IDrepresents thenamefield for theSpaceresource.
In your working directory, make sure you've stored your OAuth client ID credentials and named the file
credentials.json. The code sample uses this JSON file to authenticate with Google Workspace and get user credentials. For instructions, seeCreate OAuth client ID credentials.To list subscriptions, run the following in your terminal:
python3list_subscriptions.py
The Google Workspace Events API returns apaginated array ofSubscriptionobjectsthat match the filter for your query.
Related topics
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.