Create a section

This guide explains how to use the create method on the Section resource of the Google Chat API to create a new custom section in Google Chat.

Sections help users group their conversations and customize the list of spaces displayed in the Google Chat navigation panel. For more information, see Create and organize sections in Google Chat.

Prerequisites

Python

Create a section

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

  • Specify the chat.users.sections authorization scope.
  • Call the CreateSection method.
  • In the request body, provide a Section resource:
    • Set displayName to a name for the section (up to 80 characters).
    • Set type to CUSTOM_SECTION.

The following example creates a section:

Python

from google.cloud import chat_v1

def create_section():
    # Create a client
    client = chat_v1.ChatServiceClient()

    # Initialize request
    request = chat_v1.CreateSectionRequest(
        parent="users/me",
        section=chat_v1.Section(
            display_name="SECTION_DISPLAY_NAME",
            type=chat_v1.Section.SectionType.CUSTOM_SECTION
        )
    )

    # Make the request
    response = client.create_section(request=request)

    print(response)

To run this sample, replace the following:

  • SECTION_DISPLAY_NAME: The name of the new section.

The Chat API returns an instance of Section that details the section that was created.