This guide explains how to use the
list()
method on the Membership
resource of the Google Chat API to list members in a
space as a paginated, filterable list of memberships in a space.
- Listing memberships with app authentication lists memberships in spaces that the Chat app has access to, but excludes Chat app memberships, including its own.
- Listing memberships with user authentication lists memberships in spaces that the authenticated user has access to.
- Listing memberships as a Google Workspace administrator with user authentication using administrator privileges lists memberships in all spaces in your Google Workspace organization.
The
Membership
resource
represents whether a human user or Google Chat app is invited to,
part of, or absent from a space.
Prerequisites
Node.js
- A Business or Enterprise Google Workspace account with access to Google Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Node.js Cloud Client Library.
- Create access credentials based on how you want to authenticate in your Google Chat API
request:
- To authenticate as a Chat user,
create OAuth client ID
credentials and save the credentials as a JSON file named
credentials.json
to your local directory. - To authenticate as the Chat app,
create service account
credentials and save the credentials as a JSON file named
credentials.json
.
- To authenticate as a Chat user,
create OAuth client ID
credentials and save the credentials as a JSON file named
- Choose an authorization scope based on whether you want to authenticate as a user or the Chat app.
- A Google Chat space where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, add the Chat app to the space.
Python
- A Business or Enterprise Google Workspace account with access to Google Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Python Cloud Client Library.
- Create access credentials based on how you want to authenticate in your Google Chat API
request:
- To authenticate as a Chat user,
create OAuth client ID
credentials and save the credentials as a JSON file named
credentials.json
to your local directory. - To authenticate as the Chat app,
create service account
credentials and save the credentials as a JSON file named
credentials.json
.
- To authenticate as a Chat user,
create OAuth client ID
credentials and save the credentials as a JSON file named
- Choose an authorization scope based on whether you want to authenticate as a user or the Chat app.
- A Google Chat space where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, add the Chat app to the space.
Java
- A Business or Enterprise Google Workspace account with access to Google Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Java Cloud Client Library.
- Create access credentials based on how you want to authenticate in your Google Chat API
request:
- To authenticate as a Chat user,
create OAuth client ID
credentials and save the credentials as a JSON file named
credentials.json
to your local directory. - To authenticate as the Chat app,
create service account
credentials and save the credentials as a JSON file named
credentials.json
.
- To authenticate as a Chat user,
create OAuth client ID
credentials and save the credentials as a JSON file named
- Choose an authorization scope based on whether you want to authenticate as a user or the Chat app.
- A Google Chat space where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, add the Chat app to the space.
Apps Script
- A Business or Enterprise Google Workspace account with access to Google Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Create a standalone Apps Script project, and turn on the Advanced Chat Service.
- In this guide, you must use either user or app authentication. To authenticate as the Chat app, create service account credentials. For steps, see Authenticate and authorize as a Google Chat app.
- Choose an authorization scope based on whether you want to authenticate as a user or the Chat app.
- A Google Chat space where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, add the Chat app to the space.
List members in a space with user authentication
To list users, Google Groups, and Chat app in a space that the authenticated user has access to, pass the following in your request:
- With
user authentication,
specify the
chat.memberships.readonly
orchat.memberships
authorization scope. - Call the
ListMemberships()
method. - To list Google Groups, set the query parameter
showGroups
totrue
.
The following example lists Google Group, human, and app members visible to the authenticated user.
Node.js
Python
Java
Apps Script
To run this sample, replace SPACE_NAME
with the ID from
the space's
name
field. You can obtain the ID by calling the
ListSpaces()
method or from the space's URL.
The Google Chat API returns a list of Google Group, human, and app members from the specified space.
List members in a space with app authentication
To list users and Chat app in a space that the authenticated app has access to, pass the following in your request:
- With
app authentication,
specify the
chat.bot
authorization scope. - Call the
ListMemberships()
method. - To list Google Groups, set the query parameter
showGroups
totrue
.
The following example lists human space members (not space managers) visible to the Chat app:
Node.js
Python
Java
Apps Script
To run this sample, replace SPACE_NAME
with the ID from
the space's
name
field. You can obtain the ID by calling the
ListSpaces()
method or from the space's URL.
The Google Chat API returns a list of human space members (excluding space managers) from the specified space.
List members as a Google Workspace administrator
If you're a Google Workspace administrator, you can call the
ListMemberships()
method to list memberships for any space in your
Google Workspace organization. The Chat API only returns
memberships about users��both internal and external—or Google Groups from your
organization, and therefore omits memberships for any Chat apps.
To call this method as a Google Workspace administrator, do the following:
- Call the method using user authentication, and specify an authorization scope that supports calling the method using administrator privileges.
- In your request, specify the following query parameters:
- Set
useAdminAccess
totrue
. - To return only users, set the
filter
formember.type
equal toHUMAN
. - To return users and groups, set the
filter
formember.type
not equal toBOT
AND
showGroups
equal totrue
.
- Set
For more information and examples, see Manage Google Chat spaces as a Google Workspace administrator.
Customize pagination or filter the list
To list the memberships, pass the following query parameters to customize pagination of, or filter, listed memberships:
pageSize
: The maximum number of memberships to return. The service might return fewer than this value. If unspecified, at most 100 spaces are returned. The maximum value is 1,000; values more than 1,000 are automatically changed to 1,000.pageToken
: A page token, received from a previous list spaces call. Provide this token to retrieve the subsequent page. When paginating, the filter value should match the call that provided the page token. Passing a different value might lead to unexpected results.filter
: A query filter. Requires user authentication. For supported query details, see theListMembershipsRequest
reference.
Related topics
- Get details about a user's or Chat app's membership.
- Invite or add a user or Chat app to a space.
- Update a user's membership in a Google Chat space.
- Remove a user or Chat app from a space.