Delete a space Stay organized with collections Save and categorize content based on your preferences.
Page Summary
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 thedelete()method on theSpace resource of the Google Chat API to delete a named space whenit's no longer needed. Deleting a space also deletes everything that itcontains, including messages and attachments.
If you're a Google Workspace administrator, you can call thedelete()method to delete any named space in your Google Workspace organization.
TheSpace resourcerepresents 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 anda Chat app.
- Group chats are conversations between three or more users andChat apps.
- Named spaces are persistent places where people send messages, share files,and collaborate.
Prerequisites
Node.js
- A Business or EnterpriseGoogle Workspace account with access toGoogle 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 OAuth client ID credentials for a desktop application. To run the sample in this guide, save the credentials as a JSON file named
credentials.jsonto your local directory.
- Choose an authorization scope that supports user authentication.
- A Google Chat space. To create one using the Google Chat API, seeCreate a space. To create one in Chat,visit theHelp Center documentation.
The code samples in this page use the gRPC API interface with the Google Cloud clientlibraries. Alternatively, you can use the REST API interface. For more information about the gRPCand REST interfaces, seeGoogle Chat API overview.
Delete a named space as a user
To delete an existing space in Google Chat withuser authentication, passthe following in your request:
- Specify the
chat.deleteauthorization scope. - Call the
DeleteSpace()method. - Pass the
nameof the space to delete.
Here's how to delete a space:
Node.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 credentialasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES,);// Initialize request argument(s)constrequest={// Replace SPACE_NAME herename:'spaces/SPACE_NAME',};// Make the requestconstresponse=awaitchatClient.deleteSpace(request);// Handle the responseconsole.log(response);}awaitmain();
To run this sample, replaceSPACE_NAME with the ID fromthe space'snamefield. You can obtain the ID by calling theListSpaces()method or from the space's URL.
Delete a named space as a Chat app
App authentication requires one-timeadministrator approval.
With app authentication, you can only delete spaces created byChat apps.
To delete an existing space in Google Chat withapp authentication, passthe following in your request:
- Specify the
chat.app.deleteauthorization scope. - Call the
deletemethodon theSpaceresource. - Pass the
nameof the space to delete.
Write a script that calls Chat API
Here's how to delete a space:
Python
- In your working directory, create a file named
chat_space_delete_app.py. Include the following code in
chat_space_delete_app.py:fromgoogle.oauth2importservice_accountfromapiclient.discoveryimportbuild# 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()In the code, replace the following:
SPACEwith the space name,which you can obtain from thespaces.listmethodin the Chat API, or from a space's URL.
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 isdeleted.
Delete a named space as a Google Workspace administrator
If you're a Google Workspace administrator, you can call theDeleteSpace() method to delete any named space in yourGoogle Workspace organization.
To call this method as a Google Workspace administrator, do the following:
- Call the method using user authentication, and specify anauthorization scopethat supports calling the method usingadministrator privileges.
- In your request, specify the query parameter
useAdminAccesstotrue.
For more information and examples, seeManage Google Chat spaces as a Google Workspace administrator.
Related topics
- Create a space
- Get details about a space.
- List spaces.
- Update a space.
- Delete a space.
- Set up a space.
- Find a direct message space.
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.