Update a section

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

Update a section

To update a section with user authentication, pass the following in your request:

  • Specify the chat.users.sections authorization scope.
  • Call the UpdateSection method.
  • In the request body, provide a Section resource and a field mask:
    • Set the name of the section to update.
    • Set displayName to the new name for the section.
    • Set updateMask to displayName.

The following example updates a section:

Python

from google.cloud import chat_v1
from google.protobuf import field_mask_pb2

def update_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 the ListSections method.
  • NEW_SECTION_DISPLAY_NAME: The new name for the section.

The Chat API returns the updated instance of Section.