This guide explains how to use the move
method on the SectionItem
resource of the Google Chat API to move an item (such as a space) from one section to another.
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.
Move a space to a different section
To move a space to a different section with user authentication , pass the following in your request:
- Specify the
chat.users.sectionsauthorization scope. - Call the
MoveSectionItemmethod. - In the request body, specify the
nameof the section item to move and thetargetSection:- Set
nameto the resource name of the section item (for example,users/me/sections/default-spaces/items/spaces/123456). - Set
targetSectionto the resource name of the section you want to move the item to.
- Set
The following example moves a space to a different section:
Python
from
google.cloud
import
chat_v1
def
move_section_item
():
# Create a client
client
=
chat_v1
.
ChatServiceClient
()
# Initialize request
request
=
chat_v1
.
MoveSectionItemRequest
(
name
=
"SECTION_ITEM_NAME"
,
target_section
=
"TARGET_SECTION_NAME"
)
# Make the request
response
=
client
.
move_section_item
(
request
=
request
)
print
(
response
)
To run this sample, replace the following:
-
SECTION_ITEM_NAME: The resource name of the section item. -
TARGET_SECTION_NAME: The resource name of the target section.
The Chat API returns the updated instance of SectionItem
.

