Get details about a space

  • This guide explains how to use the get() method to retrieve details about a specific Google Chat space, such as its display name, description, and guidelines.

  • Google Workspace administrators can use the get() method to access details about any space within their organization by using user authentication with administrator privileges and setting useAdminAccess to true.

  • Chat apps can retrieve space details using app authentication with the chat.bot or chat.app.spaces scope, provided the app is a member of the space.

  • You need a Google Workspace account with access to Google Chat and must set up your environment with necessary credentials and authorization scopes before using the get() method.

  • The space name, which is required for the get() method, can be obtained from the Space resource, a space's URL, or by calling the ListSpaces() method.

This guide explains how to use the get() method on a Space resource of the Google Chat API to see details about a space, like its display name, description, and guidelines.

If you're a Google Workspace administrator, you can call the get() method to retrieve details about any space in your Google Workspace organization.

The Space resource represents a place where people and Chat apps can send messages, share files, and collaborate. There are several types of spaces:

  • Direct messages (DMs) are conversations between two users or a user and a Chat app.
  • Group chats are conversations between three or more users and Chat apps.
  • Named spaces are persistent places where people send messages, share files, and collaborate.

Authenticating with app authentication lets a Chat app get details about a space where the Chat app is a member. Authenticating with user authentication lets you get spaces that the authenticated user has access to, either as a space member or a Google Workspace administrator.

Prerequisites

Node.js

Python

Java

Apps Script

Get a space

To get a space in Google Chat, pass the following in your request:

  • An authorization scope:
  • Call the GetSpace() method, passing the name of the space to get. Obtain the space name from the Space resource of Google Chat, or from a space's URL.

Get space details as a user

Here's how to get space details with user authentication:

Node.js

chat/client-libraries/cloud/get-space-user-cred.js
import{createClientWithUserCredentials}from'./authentication-utils.js';
constUSER_AUTH_OAUTH_SCOPES=[
'https://www.googleapis.com/auth/chat.spaces.readonly',
];
// This sample shows how to get space with user credential
asyncfunctionmain(){
// Create a client
constchatClient=awaitcreateClientWithUserCredentials(
USER_AUTH_OAUTH_SCOPES,
);
// Initialize request argument(s)
constrequest={
// Replace SPACE_NAME here
name:'spaces/SPACE_NAME',
};
// Make the request
constresponse=awaitchatClient.getSpace(request);
// Handle the response
console.log(response);
}
awaitmain();

Python

chat/client-libraries/cloud/get_space_user_cred.py
fromauthentication_utilsimport create_client_with_user_credentials
fromgoogle.appsimport chat_v1 as google_chat
SCOPES = ["https://www.googleapis.com/auth/chat.spaces.readonly"]
# This sample shows how to get space with user credential
defget_space_with_user_cred():
 # Create a client
 client = create_client_with_user_credentials(SCOPES)
 # Initialize request argument(s)
 request = google_chat.GetSpaceRequest(
 # Replace SPACE_NAME here
 name = "spaces/SPACE_NAME",
 )
 # Make the request
 response = client.get_space(request)
 # Handle the response
 print(response)
get_space_with_user_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/GetSpaceUserCred.java
importcom.google.chat.v1.ChatServiceClient;
importcom.google.chat.v1.GetSpaceRequest;
importcom.google.chat.v1.Space;
// This sample shows how to get space with user credential.
publicclass GetSpaceUserCred{
privatestaticfinalStringSCOPE=
"https://www.googleapis.com/auth/chat.spaces.readonly";
publicstaticvoidmain(String[]args)throwsException{
try(ChatServiceClientchatServiceClient=
AuthenticationUtils.createClientWithUserCredentials(
ImmutableList.of(SCOPE))){
GetSpaceRequest.Builderrequest=GetSpaceRequest.newBuilder()
// Replace SPACE_NAME here
.setName("spaces/SPACE_NAME");
Spaceresponse=chatServiceClient.getSpace(request.build());
System.out.println(JsonFormat.printer().print(response));
}
}
}

Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to get space with user credential
 * 
 * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces.readonly'
 * referenced in the manifest file (appsscript.json).
 */
functiongetSpaceUserCred(){
// Initialize request argument(s)
// TODO(developer): Replace SPACE_NAME here
constname='spaces/SPACE_NAME';
// Make the request
constresponse=Chat.Spaces.get(name);
// Handle the response
console.log(response);
}

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 Chat API returns an instance of Space that details the specified space.

Get space details as a Google Workspace administrator

If you're a Google Workspace administrator, you can call the GetSpace method to retrieve details about any space in your Google Workspace organization.

To call this method as a Google Workspace administrator, do the following:

For more information and examples, see Manage Google Chat spaces as a Google Workspace administrator.

Get space details as a Chat app

Here's how to get space details with app authentication:

Node.js

chat/client-libraries/cloud/get-space-app-cred.js
import{createClientWithAppCredentials}from'./authentication-utils.js';
// This sample shows how to get space with app credential
asyncfunctionmain(){
// Create a client
constchatClient=createClientWithAppCredentials();
// Initialize request argument(s)
constrequest={
// Replace SPACE_NAME here
name:'spaces/SPACE_NAME',
};
// Make the request
constresponse=awaitchatClient.getSpace(request);
// Handle the response
console.log(response);
}
awaitmain();

Python

chat/client-libraries/cloud/get_space_app_cred.py
fromauthentication_utilsimport create_client_with_app_credentials
fromgoogle.appsimport chat_v1 as google_chat
# This sample shows how to get space with app credential
defget_space_with_app_cred():
 # Create a client
 client = create_client_with_app_credentials()
 # Initialize request argument(s)
 request = google_chat.GetSpaceRequest(
 # Replace SPACE_NAME here
 name = "spaces/SPACE_NAME",
 )
 # Make the request
 response = client.get_space(request)
 # Handle the response
 print(response)
get_space_with_app_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/GetSpaceAppCred.java
importcom.google.chat.v1.ChatServiceClient;
importcom.google.chat.v1.GetSpaceRequest;
importcom.google.chat.v1.Space;
// This sample shows how to get space with app credential.
publicclass GetSpaceAppCred{
publicstaticvoidmain(String[]args)throwsException{
try(ChatServiceClientchatServiceClient=
AuthenticationUtils.createClientWithAppCredentials()){
GetSpaceRequest.Builderrequest=GetSpaceRequest.newBuilder()
// Replace SPACE_NAME here
.setName("spaces/SPACE_NAME");
Spaceresponse=chatServiceClient.getSpace(request.build());
System.out.println(JsonFormat.printer().print(response));
}
}
}

Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to get space with app credential
 * 
 * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.bot'
 * used by service accounts.
 */
functiongetSpaceAppCred(){
// Initialize request argument(s)
// TODO(developer): Replace SPACE_NAME here
constname='spaces/SPACE_NAME';
constparameters={};
// Make the request
constresponse=Chat.Spaces.get(name,parameters,getHeaderWithAppCredentials());
// Handle the response
console.log(response);
}

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 Chat API returns an instance of Space that details the specified space.

Limitations and considerations

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月13日 UTC.