Delete a message

  • This guide demonstrates how to delete text or card messages in Google Chat using the delete() method of the Google Chat API.

  • You can delete messages sent by the Chat app or the authenticated user, and potentially messages sent by other space members if you are a space manager.

  • Before using this method, you need a Google Workspace account, a Google Cloud project, and appropriate authorization credentials (user or app).

  • Code samples are provided for Node.js, Python, Java, and Apps Script, showing how to delete messages with both user and app authentication.

  • To successfully delete a message, you need the name of the space and the name of the message you want to delete.

This guide explains how to use the delete() method on the Message resource of the Google Chat API to delete a text or card message.

In the Chat API, a Chat message is represented by the Message resource. While Chat users can only send messages that contain text, Chat apps can use many other messaging features, including displaying static or interactive user interfaces, collecting information from users, and delivering messages privately. To learn more about messaging features available for the Chat API, see the Google Chat messages overview.

With app authentication, you can use this method to delete a message that the Chat app sent. With user authentication, you can use this method to delete a message that the authenticated user sent. If the user is a space manager for the space, you might also be able to delete a message that other space members sent. For more information, see Learn about your role as a Space Manager.

Prerequisites

Node.js

Python

Java

Apps Script

Delete a message with user authentication

To delete a message with user authentication, pass the following in your request:

  • Specify the chat.messages authorization scope.
  • Call the DeleteMessage() method.
  • Set name to the resource name of the message to delete.

The following example deletes a message with user authentication:

Node.js

Python

Java

Apps Script

To run this sample, replace the following:

  • SPACE_NAME: the ID from the space's name. You can obtain the ID by calling the ListSpaces() method or from the space's URL.
  • MESSAGE_NAME: the ID from the message's name. You can obtain the ID from the response body returned after creating a message asynchronously with the Chat API, or with the custom name assigned to the message at creation.

If successful, the response body is empty, which indicates that the message is deleted.

Delete a message with app authentication

To delete a message with app authentication, pass the following in your request:

  • Specify the chat.bot authorization scope.
  • Call the DeleteMessage() method.
  • Set name to the resource name of the message to delete.

The following example deletes a message with app authentication:

Node.js

Python

Java

Apps Script

To run this sample, replace the following:

  • SPACE_NAME: the ID from the space's name. You can obtain the ID by calling the ListSpaces() method or from the space's URL.
  • MESSAGE_NAME: the ID from the message's name. You can obtain the ID from the response body returned after creating a message asynchronously with the Chat API, or with the custom name assigned to the message at creation.

If successful, the response body is empty, which indicates that the message is deleted.

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-12-11 UTC.