Update a space

  • This guide explains how to update a Google Chat space using the patch() method of the Google Chat API to change attributes like display name, description, and guidelines.

  • Workspace administrators can update any space within their organization, while regular users can update spaces they have access to.

  • The guide provides code samples in Node.js, Python, Java, and Apps Script for updating spaces with user authentication.

  • It also covers updating spaces as a Google Workspace administrator using administrator privileges.

  • Developer Preview: Chat apps can also update spaces they created using app authentication with the chat.app.spaces scope and an API key.

This guide explains how to use the patch method on the Space resource of the Google Chat API to update a space. Update a space to change attributes about a space, like its user-visible display name, description, and guidelines.

If you're a Google Workspace administrator, you can call the patch method to update any existing 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

Python

Java

Apps Script

Update a space as a user

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

  • Specify the chat.spaces authorization scope.
  • Call the UpdateSpace method. In your request, you specify the space name field, the updateMask field with one or more fields to update, and a body with the updated space information.

You can update things like the display name, space type, history state, and more. To see all the fields you can update, see the reference documentation.

Here's how to update the displayName field of an existing space:

Node.js

chat/client-libraries/cloud/update-space-user-cred.js
import{createClientWithUserCredentials}from'./authentication-utils.js';
constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.spaces'];
// This sample shows how to update a space with user credential
asyncfunctionmain(){
// Create a client
constchatClient=awaitcreateClientWithUserCredentials(
USER_AUTH_OAUTH_SCOPES,
);
// Initialize request argument(s)
constrequest={
space:{
// Replace SPACE_NAME here
name:'spaces/SPACE_NAME',
displayName:'New space display name',
},
// The field paths to update. Separate multiple values with commas or use `*`
// to update all field paths.
updateMask:{
// The field paths to update.
paths:['display_name'],
},
};
// Make the request
constresponse=awaitchatClient.updateSpace(request);
// Handle the response
console.log(response);
}
awaitmain();

Python

chat/client-libraries/cloud/update_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"]
# This sample shows how to update a space with user credential
defupdate_space_with_user_cred():
 # Create a client
 client = create_client_with_user_credentials(SCOPES)
 # Initialize request argument(s)
 request = google_chat.UpdateSpaceRequest(
 space = {
 # Replace SPACE_NAME here
 'name': 'spaces/SPACE_NAME',
 'display_name': 'New space display name'
 },
 # The field paths to update. Separate multiple values with commas.
 update_mask = 'displayName'
 )
 # Make the request
 response = client.update_space(request)
 # Handle the response
 print(response)
update_space_with_user_cred()

Java

chat/client-libraries/cloud/src/main/java/com/google/workspace/api/chat/samples/UpdateSpaceUserCred.java
importcom.google.chat.v1.ChatServiceClient;
importcom.google.chat.v1.UpdateSpaceRequest;
importcom.google.chat.v1.Space;
importcom.google.protobuf.FieldMask;
// This sample shows how to update space with user credential.
publicclass UpdateSpaceUserCred{
privatestaticfinalStringSCOPE=
"https://www.googleapis.com/auth/chat.spaces";
publicstaticvoidmain(String[]args)throwsException{
try(ChatServiceClientchatServiceClient=
AuthenticationUtils.createClientWithUserCredentials(
ImmutableList.of(SCOPE))){
UpdateSpaceRequest.Builderrequest=UpdateSpaceRequest.newBuilder()
.setSpace(Space.newBuilder()
// Replace SPACE_NAME here.
.setName("spaces/SPACE_NAME")
.setDisplayName("New space display name"))
.setUpdateMask(FieldMask.newBuilder()
// The field paths to update.
.addPaths("display_name"));
Spaceresponse=chatServiceClient.updateSpace(request.build());
System.out.println(JsonFormat.printer().print(response));
}
}
}

Apps Script

chat/advanced-service/Main.gs
/**
 * This sample shows how to update a space with user credential
 *
 * It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.spaces'
 * referenced in the manifest file (appsscript.json).
 */
functionupdateSpaceUserCred(){
// Initialize request argument(s)
// TODO(developer): Replace SPACE_NAME here
constname="spaces/SPACE_NAME";
constspace={
displayName:"New space display name",
};
// The field paths to update. Separate multiple values with commas or use
// `*` to update all field paths.
constupdateMask="displayName";
// Make the request
constresponse=Chat.Spaces.patch(space,name,{
updateMask:updateMask,
});
// 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 Google Chat API returns an instance of the Space reflecting the updates.

Update a space as a Google Workspace administrator

If you're a Google Workspace administrator, you can call the UpdateSpace method to update 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.

Update a space as a Chat app

App authentication requires one-time administrator approval.

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

  • Specify the chat.app.spaces authorization scope. With app authentication, you can only update spaces created by Chat apps.
  • Call the patch method on the Space resource. In your request, you specify the space name field, the updateMask field with one or more fields to update, and a body with the updated space information.

You can update things like the display name, space type, history state, permission settings, and more. To see all the fields you can update, see the reference documentation.

Write a script that calls Chat API

Here's how to update the spaceDetails field of an existing space:

Python

  1. In your working directory, create a file named chat_space_update_app.py.
  2. Include the following code in chat_space_update_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.spaces"]
    defmain():
    '''
     Authenticates with Chat API using app authentication,
     then updates the specified space description and guidelines.
     '''
     # 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().patch(
     # The space to update, and the updated space details.
     #
     # 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',
     updateMask='spaceDetails',
     body={
     'spaceDetails': {
     'description': 'This description was updated with Chat API!',
     'guidelines': 'These guidelines were updated with Chat API!'
     }
     }
     ).execute()
     # Prints details about the updated space.
     print(result)
    if __name__ == '__main__':
     main()
    
  3. In the code, replace the following:

    • SPACE with a 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_update_app.py

The Google Chat API returns an instance of the Space resource reflecting the updates.

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 2026年07月22日 UTC.