Delete a space

  • This guide explains how to delete a Google Chat space and its contents (messages, attachments) using the delete() method.

  • Google Workspace administrators can delete any named space within their organization.

  • Prerequisites include a Google Workspace account, a Google Cloud project, and necessary API configurations.

  • Two deletion methods are outlined: one using user authentication for personal spaces and another using app authentication (developer preview) for app-created spaces.

  • Google Workspace administrators have the additional capability to delete any named space using admin privileges.

This guide explains how use the delete() method on the Space resource of the Google Chat API to delete a named space when it's no longer needed. Deleting a space also deletes everything that it contains, including messages and attachments.

If you're a Google Workspace administrator, you can call the delete() method to delete any named 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.

Prerequisites

Node.js

Delete a named space as a user

To delete an existing space in Google Chat with user authentication, pass the following in your request:

  • Specify the chat.delete authorization scope.
  • Call the DeleteSpace() method.
  • Pass the name of the space to delete.

Here's how to delete a space:

Node.js

chat/client-libraries/cloud/delete-space-user-cred.js
import{createClientWithUserCredentials}from'./authentication-utils.js';
constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.delete'];
// This sample shows how to delete a 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.deleteSpace(request);
// Handle the response
console.log(response);
}
awaitmain();

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.

Delete a named space as a Chat app

App authentication requires one-time administrator approval.

With app authentication, you can only delete spaces created by Chat apps.

To delete an existing space in Google Chat with app authentication, pass the following in your request:

Write a script that calls Chat API

Here's how to delete a space:

Python

  1. In your working directory, create a file named chat_space_delete_app.py.
  2. Include the following code in chat_space_delete_app.py:

    fromgoogle.oauth2import service_account
    fromapiclient.discoveryimport build
    # Define your app's authorization scopes.
    # When modifying these scopes, delete the file token.json, if it exists.
    SCOPES = ["https://www.googleapis.com/auth/chat.app.delete"]
    defmain():
    '''
     Authenticates with Chat API using app authentication,
     then deletes the specified space.
     '''
     # Specify service account details.
     creds = (
     service_account.Credentials.from_service_account_file('credentials.json')
     .with_scopes(SCOPES)
     )
     # Build a service endpoint for Chat API.
     chat = build('chat', 'v1', credentials=creds)
     # Use the service endpoint to call Chat API.
     result = chat.spaces().delete(
     # The space to delete.
     #
     # Replace SPACE with a space name.
     # Obtain the space name from the spaces resource of Chat API,
     # or from a space's URL.
     name='spaces/SPACE'
     ).execute()
     # Print Chat API's response in your command line interface.
     # When deleting a space, the response body is empty.
     print(result)
    if __name__ == '__main__':
     main()
    
  3. In the code, replace the following:

    • SPACE with the space name, which you can obtain from the spaces.list method in the Chat API, or from a space's URL.
  4. In your working directory, build and run the sample:

    python3chat_space_delete_app.py

If successful, the response body is empty, which indicates that the space is deleted.

Delete a named space as a Google Workspace administrator

If you're a Google Workspace administrator, you can call the DeleteSpace() method to delete any named 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.

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.