List Google Workspace subscriptions

  • This page provides instructions on how to list Google Workspace subscriptions using thesubscriptions.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 ofSubscription objects 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

  • 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 theappsscript.json file in your Apps Script project. For example, if you specified thechat.messages scope, then add the following:
    • "oauthScopes": [  "https://www.googleapis.com/auth/chat.messages"]
    • Enable theGoogle Workspace Events advanced service.

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

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

  1. In your Apps Script project, create a new script filenamedlistSubscriptions and 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_ID wherespaces/SPACE_ID represents thenamefield for theSpace resource.
  2. To list subscriptions, run the functionlistSubscriptions inyour Apps Script project.

Python

  1. In your working directory, create a file namedlist_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_ID wherespaces/SPACE_ID represents thenamefield for theSpace resource.
  2. In your working directory, make sure you've stored your OAuth client ID credentials and named the filecredentials.json. The code sample uses this JSON file to authenticate with Google Workspace and get user credentials. For instructions, seeCreate OAuth client ID credentials.

  3. 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.