Change the position of a section

This guide explains how to use the position method on the Section resource of the Google Chat API to change the sort order of a section in Google Chat.

For more information, see Create and organize sections in Google Chat.

Prerequisites

Python

Change the position of a section

To change the position of a section with user authentication, pass the following in your request:

  • Specify the chat.users.sections authorization scope.
  • Call the PositionSection method.
  • In the request body, specify the name of the section to position and the new position:
    • Set sortOrder to an absolute position (greater than 0).
    • OR set relativePosition to START or END.

The following example moves a section to the start of the list:

Python

fromgoogle.cloudimport chat_v1
defposition_section():
 # Create a client
 client = chat_v1.ChatServiceClient()
 # Initialize request
 request = chat_v1.PositionSectionRequest(
 name="SECTION_NAME",
 relative_position=chat_v1.PositionSectionRequest.Position.START
 )
 # Make the request
 response = client.position_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.

The Chat API returns the updated instance of Section.

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.