This guide explains how to use the
[`get`](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetSpace)
method on a `Space` resource of the Google Chat API to see details about a space,
like its display name, description, and guidelines.

Space owners and managers can
[restrict who can see the member list](https://developers.google.com/workspace/chat/space-target-audience#make-space)
in a space.

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](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces)
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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app)
lets a Chat app get details about a space
where the Chat app is a member. Authenticating with
[user authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user)
lets you get spaces that the authenticated user has access to, either as
a space member or a
[Google Workspace administrator](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user#admin-privileges).

## Prerequisites


### Node.js

- A Business or Enterprise [Google Workspace](https://support.google.com/a/answer/6043576) account with access to [Google Chat](https://workspace.google.com/products/chat/).

<!-- -->

- Set up your environment:
  - [Create a Google Cloud project](https://developers.google.com/workspace/guides/create-project).
  - [Configure the OAuth consent screen](https://developers.google.com/workspace/guides/configure-oauth-consent).
  - [Enable and configure the Google Chat API](https://developers.google.com/workspace/chat/configure-chat-api) with a name, icon, and description for your Chat app.
  - Install the Node.js [Cloud Client Library](https://developers.google.com/workspace/chat/libraries?tab=nodejs#cloud-client-libraries).
  - 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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user) 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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app) and save the credentials as a JSON file named `credentials.json`.
- [Choose an authorization scope](https://developers.google.com/workspace/chat/authenticate-authorize#asynchronous-chat-calls) based on whether you want to authenticate as a user or the Chat app.

<!-- -->

- A [Google Chat space](https://developers.google.com/workspace/chat/set-up-spaces) where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, [add the
  Chat app to the space](https://developers.google.com/workspace/chat/test-interactive-features).

### Python

- A Business or Enterprise [Google Workspace](https://support.google.com/a/answer/6043576) account with access to [Google Chat](https://workspace.google.com/products/chat/).

<!-- -->

- Set up your environment:
  - [Create a Google Cloud project](https://developers.google.com/workspace/guides/create-project).
  - [Configure the OAuth consent screen](https://developers.google.com/workspace/guides/configure-oauth-consent).
  - [Enable and configure the Google Chat API](https://developers.google.com/workspace/chat/configure-chat-api) with a name, icon, and description for your Chat app.
  - Install the Python [Cloud Client Library](https://developers.google.com/workspace/chat/libraries?tab=python#cloud-client-libraries).
  - 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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user) 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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app) and save the credentials as a JSON file named `credentials.json`.
- [Choose an authorization scope](https://developers.google.com/workspace/chat/authenticate-authorize#asynchronous-chat-calls) based on whether you want to authenticate as a user or the Chat app.

<!-- -->

- A [Google Chat space](https://developers.google.com/workspace/chat/set-up-spaces) where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, [add the
  Chat app to the space](https://developers.google.com/workspace/chat/test-interactive-features).

### Java

- A Business or Enterprise [Google Workspace](https://support.google.com/a/answer/6043576) account with access to [Google Chat](https://workspace.google.com/products/chat/).

<!-- -->

- Set up your environment:
  - [Create a Google Cloud project](https://developers.google.com/workspace/guides/create-project).
  - [Configure the OAuth consent screen](https://developers.google.com/workspace/guides/configure-oauth-consent).
  - [Enable and configure the Google Chat API](https://developers.google.com/workspace/chat/configure-chat-api) with a name, icon, and description for your Chat app.
  - Install the Java [Cloud Client Library](https://developers.google.com/workspace/chat/libraries?tab=java#cloud-client-libraries).
  - 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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user) 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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app) and save the credentials as a JSON file named `credentials.json`.
- [Choose an authorization scope](https://developers.google.com/workspace/chat/authenticate-authorize#asynchronous-chat-calls) based on whether you want to authenticate as a user or the Chat app.

<!-- -->

- A [Google Chat space](https://developers.google.com/workspace/chat/set-up-spaces) where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, [add the
  Chat app to the space](https://developers.google.com/workspace/chat/test-interactive-features).

### Apps Script

- A Business or Enterprise [Google Workspace](https://support.google.com/a/answer/6043576) account with access to [Google Chat](https://workspace.google.com/products/chat/).

<!-- -->

- Set up your environment:
  - [Create a Google Cloud project](https://developers.google.com/workspace/guides/create-project).
  - [Configure the OAuth consent screen](https://developers.google.com/workspace/guides/configure-oauth-consent).
  - [Enable and configure the Google Chat API](https://developers.google.com/workspace/chat/configure-chat-api) with a name, icon, and description for your Chat app.
  - [Create a standalone Apps Script project](https://developers.google.com/apps-script/guides/projects), and turn on the [Advanced Chat Service](https://developers.google.com/apps-script/advanced/chat).
  - In this guide, you must use either [user
    or app authentication](https://developers.google.com/workspace/chat/authenticate-authorize). To authenticate as the Chat app, create service account credentials. For steps, see [Authenticate and authorize as a
    Google Chat app](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app).
- [Choose an authorization scope](https://developers.google.com/workspace/chat/authenticate-authorize#asynchronous-chat-calls) based on whether you want to authenticate as a user or the Chat app.

<!-- -->

- A [Google Chat space](https://developers.google.com/workspace/chat/set-up-spaces) where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, [add the
  Chat app to the space](https://developers.google.com/workspace/chat/test-interactive-features).


> [!NOTE]
> The code samples in this page use the gRPC API interface with the Google Cloud client libraries. Alternatively, you can use the REST API interface. For more information about the gRPC and REST interfaces, see [Google Chat API overview](https://developers.google.com/workspace/chat/api/reference).

<br />

## Get a space

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

- An authorization scope:
  - With [user authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user), specify the `chat.spaces.readonly` or `chat.spaces` authorization scope.
  - With [app authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app), specify the `chat.bot` authorization scope or the `chat.app.spaces` scope. The `chat.app.spaces` scope is available in [Developer Preview](https://developers.google.com/workspace/preview) and requires one-time [administrator approval](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app#admin-approval).
- Call the [`GetSpace`](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.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](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user):

### Node.js

chat/client-libraries/cloud/get-space-user-cred.js [View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/get-space-user-cred.js)

```javascript
import {createClientWithUserCredentials} from './authentication-utils.js';

const USER_AUTH_OAUTH_SCOPES = [
  'https://www.googleapis.com/auth/chat.spaces.readonly',
];

// This sample shows how to get space with user credential
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(
    USER_AUTH_OAUTH_SCOPES,
  );

  // Initialize request argument(s)
  const request = {
    // Replace SPACE_NAME here
    name: 'spaces/SPACE_NAME',
  };

  // Make the request
  const response = await chatClient.getSpace(request);

  // Handle the response
  console.log(response);
}

await main();
```

### Python

chat/client-libraries/cloud/get_space_user_cred.py [View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/chat/client-libraries/cloud/get_space_user_cred.py)

```python
from authentication_utils import create_client_with_user_credentials
from google.apps import chat_v1 as google_chat

SCOPES = ["https://www.googleapis.com/auth/chat.spaces.readonly"]

# This sample shows how to get space with user credential
def get_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 [View on GitHub](https://github.com/googleworkspace/java-samples/blob/main/chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/GetSpaceUserCred.java)

```java
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.GetSpaceRequest;
import com.google.chat.v1.Space;

// This sample shows how to get space with user credential.
public class GetSpaceUserCred {

  private static final String SCOPE =
    "https://www.googleapis.com/auth/chat.spaces.readonly";

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithUserCredentials(
          ImmutableList.of(SCOPE))) {
      GetSpaceRequest.Builder request = GetSpaceRequest.newBuilder()
        // Replace SPACE_NAME here
        .setName("spaces/SPACE_NAME");
      Space response = chatServiceClient.getSpace(request.build());

      System.out.println(JsonFormat.printer().print(response));
    }
  }
}
```

### Apps Script

chat/advanced-service/Main.gs [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/chat/advanced-service/Main.gs)

```javascript
/**
 * 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).
 */
function getSpaceUserCred() {
  // Initialize request argument(s)
  // TODO(developer): Replace SPACE_NAME here
  const name = "spaces/SPACE_NAME";

  // Make the request
  const response = 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`](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Space.FIELDS.string.google.chat.v1.Space.name)
field. You can obtain the ID by calling the
[`ListSpaces`](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaces)
method or from the space's URL.

The Chat API returns an instance of
[`Space`](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#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:

- Call the method using user authentication, and specify an [authorization scope](https://developers.google.com/workspace/chat/authenticate-authorize#asynchronous-chat-calls) that supports calling the method using [administrator privileges](https://developers.google.com/workspace/chat/authenticate-authorize-chat-user#admin-privileges).
- In your request, specify the query parameter `useAdminAccess` to `true`.

For more information and examples, see
[Manage Google Chat spaces as a Google Workspace administrator](https://developers.google.com/workspace/chat/admin-overview).

### Get space details as a Chat app

Here's how to get space details with
[app authentication](https://developers.google.com/workspace/chat/authenticate-authorize-chat-app):

### Node.js

chat/client-libraries/cloud/get-space-app-cred.js [View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/get-space-app-cred.js)

```javascript
import {createClientWithAppCredentials} from './authentication-utils.js';

// This sample shows how to get space with app credential
async function main() {
  // Create a client
  const chatClient = createClientWithAppCredentials();

  // Initialize request argument(s)
  const request = {
    // Replace SPACE_NAME here
    name: 'spaces/SPACE_NAME',
  };

  // Make the request
  const response = await chatClient.getSpace(request);

  // Handle the response
  console.log(response);
}

await main();
```

### Python

chat/client-libraries/cloud/get_space_app_cred.py [View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/chat/client-libraries/cloud/get_space_app_cred.py)

```python
from authentication_utils import create_client_with_app_credentials
from google.apps import chat_v1 as google_chat

# This sample shows how to get space with app credential
def get_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 [View on GitHub](https://github.com/googleworkspace/java-samples/blob/main/chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/GetSpaceAppCred.java)

```java
import com.google.chat.v1.ChatServiceClient;
import com.google.chat.v1.GetSpaceRequest;
import com.google.chat.v1.Space;

// This sample shows how to get space with app credential.
public class GetSpaceAppCred {

  public static void main(String[] args) throws Exception {
    try (ChatServiceClient chatServiceClient =
        AuthenticationUtils.createClientWithAppCredentials()) {
      GetSpaceRequest.Builder request = GetSpaceRequest.newBuilder()
        // Replace SPACE_NAME here
        .setName("spaces/SPACE_NAME");
      Space response = chatServiceClient.getSpace(request.build());

      System.out.println(JsonFormat.printer().print(response));
    }
  }
}
```

### Apps Script

chat/advanced-service/Main.gs [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/chat/advanced-service/Main.gs)

```javascript
/**
 * 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.
 */
function getSpaceAppCred() {
  // Initialize request argument(s)
  // TODO(developer): Replace SPACE_NAME here
  const name = "spaces/SPACE_NAME";
  const parameters = {};

  // Make the request
  const response = 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`](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Space.FIELDS.string.google.chat.v1.Space.name)
field. You can obtain the ID by calling the
[`ListSpaces`](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaces)
method or from the space's URL.

The Chat API returns an instance of
[`Space`](https://developers.google.com/workspace/chat/api/reference/rpc/google.chat.v1#space)
that details the specified space.

## Limitations and considerations

- The [`accessSettings`](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces#Space.AccessSettings) (including `accessPermissionSettings`), [`predefinedPermissionSettings`](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces#predefinedpermissionsettings), and [`permissionSettings`](https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces#Space.PermissionSettings) fields only populate when you authenticate with the `chat.app.spaces` scope, and permission settings are limited to spaces the Chat app created.

## Related topics

- [Create a space](https://developers.google.com/workspace/chat/create-spaces).
- [Set up a space](https://developers.google.com/workspace/chat/set-up-spaces).
- [List spaces](https://developers.google.com/workspace/chat/list-spaces).
- [Update a space](https://developers.google.com/workspace/chat/update-spaces).
- [Delete a space](https://developers.google.com/workspace/chat/delete-spaces).
- [Find a direct message space](https://developers.google.com/workspace/chat/find-direct-message-in-spaces).