Update a section
Stay organized with collections
Save and categorize content based on your preferences.
This guide explains how to use the
patch
method on the Section resource of the Google Chat API to update a custom section in Google Chat.
Only sections of type CUSTOM_SECTION can be updated. For more information, see
Create and organize sections in Google Chat.
Prerequisites
Python
- A Business or Enterprise Google Workspace account with access to Google 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 Python 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.
Update a section
To update a section with user authentication, pass the following in your request:
- Specify the
chat.users.sectionsauthorization scope. - Call the
UpdateSectionmethod. - In the request body, provide a
Sectionresource and a field mask:- Set the
nameof the section to update. - Set
displayNameto the new name for the section. - Set
updateMasktodisplayName.
- Set the
The following example updates a section:
Python
fromgoogle.cloudimport chat_v1
fromgoogle.protobufimport field_mask_pb2
defupdate_section():
# Create a client
client = chat_v1.ChatServiceClient()
# Initialize request
request = chat_v1.UpdateSectionRequest(
section=chat_v1.Section(
name="SECTION_NAME",
display_name="NEW_SECTION_DISPLAY_NAME"
),
update_mask=field_mask_pb2.FieldMask(paths=["display_name"])
)
# Make the request
response = client.update_section(request=request)
print(response)
To run this sample, replace the following:
SECTION_NAME: The resource name of the section. You can obtain the resource name by calling theListSectionsmethod.NEW_SECTION_DISPLAY_NAME: The new name for the section.
The Chat API returns the updated instance of
Section.
Related topics
- Create a section
- Delete a section
- Change the position of a section
- List sections
- List spaces in a section
- Move a space to a different section