Change the position of a section
Stay organized with collections
Save and categorize content based on your preferences.
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
- 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.
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.sectionsauthorization scope. - Call the
PositionSectionmethod. - In the request body, specify the
nameof the section to position and the new position:- Set
sortOrderto an absolute position (greater than 0). - OR set
relativePositiontoSTARTorEND.
- Set
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 theListSectionsmethod.
The Chat API returns the updated instance of
Section.
Related topics
- Create a section
- Update a section
- Delete a section
- List sections
- List spaces in a section
- Move a space to a different section