Update a user's space notification settings

This guide explains how to use the patch() method on the SpaceNotificationSetting resource of the Google Chat API to update a user's space notification settings.

The SpaceNotificationSetting resource is a singleton resource that represents details about a specified user's space notification settings.

Prerequisites

Node.js

Update the calling user's space notification settings

To update a user's space notification setting, include the following in your request:

  • Specify the chat.users.spacesettings authorization scope.
  • Call the UpdateSpaceNotificationSetting() method, passing UpdateSpaceNotificationSetting request to contain the changes to the notification settings. The request includes:
    • spaceNotificationSetting with the following properties:
      • The name property specifies which space notification settings to update which includes a user ID or alias and a space ID. Updating space notification settings only supports updating the notification settings of the calling user, which can be specified by setting one of the following:
        • The me alias. For example, users/me/spaces/SPACE/spaceNotificationSetting.
        • The calling user's Workspace email address. For example, users/user@example.com/spaces/SPACE/spaceNotificationSetting.
        • The calling user's user ID. For example, users/USER/spaces/SPACE/spaceNotificationSetting.
      • The notificationSetting: sets the notification level, such as ALL, OFF.
      • The muteSetting: sets the mute on or off, values can be MUTED or UNMUTED.
    • updateMask: sets the update fields, it can include notification_setting, mute_setting.

The following example updates the calling user's space notification setting:

Node.js

chat/client-libraries/cloud/update-space-notification-setting-user-cred.js
import{createClientWithUserCredentials}from'./authentication-utils.js';
constUSER_AUTH_OAUTH_SCOPES=[
'https://www.googleapis.com/auth/chat.users.spacesettings',
];
// This sample shows how to update the space notification setting for the
// calling user
asyncfunctionmain(){
// Create a client
constchatClient=awaitcreateClientWithUserCredentials(
USER_AUTH_OAUTH_SCOPES,
);
// Initialize request argument(s), replace the SPACE_NAME with an actual space
// name.
constrequest={
spaceNotificationSetting:{
name:'users/me/spaces/SPACE_NAME/spaceNotificationSetting',
notificationSetting:'ALL',
muteSetting:'UNMUTED',
},
updateMask:{paths:['notification_setting','mute_setting']},
};
// Make the request
constresponse=awaitchatClient.updateSpaceNotificationSetting(request);
// Handle the response
console.log(response);
}
awaitmain();

To run this sample, replace SPACE_NAME with the ID from the space's name. You can obtain the ID by calling the ListSpaces() method or from the space's URL.

The Google Chat API updates the specified space notification settings and returns an instance of SpaceNotificationSetting.

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 2025年10月13日 UTC.