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

from google.cloud import chat_v1

def position_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.