Pages Menu

Posted by on Jul 25, 2022 in Development, Microsoft Teams

You can now delete (and un-delete) Microsoft Teams messages via Graph APIs

You can now delete (and un-delete) Microsoft Teams messages via Graph APIs

There are two new API endpoints that developers can now use when working with Microsoft Teams chat messages.

These mirror behavior that has been available in the Teams client for a while: the ability to delete a message, and then un-delete it if required).

A new method has been added to “soft delete” messages. which can now programmatically be done on any of one of:

  • One-to-one or group chats
  • channel chats
  • replies to chat messages

Either type has a slightly different endpoint URL, because the location of the chatMessage is in slightly different places.

Slightly confusingly, Microsoft have chosen not to use the DELETE method, but instead use a POST method to a /softDelete method with an empty body. So, the three different delete calls one could make, for each of the message types above is (in order):

  • POST /users/{userId}/chats/{chatsId}/messages/{chatMessageId}/softDelete
  • POST /teams/{teamsId}/channels/{channelId}/messages/{chatMessageId}/softDelete
  • POST /teams/{teamId}/channels/{channelId}/messages/{messageId}/replies/{replyId}/softDelete

You will need either ChannelMessage.ReadWrite or ChatMessage.ReadWrite (based on where the chat is located).

Important note: this call is only for delegated permissions right now. There are no application permissions for these calls, and no way for an application to delete messages without the user being present.

Un-delete that soft delete

As is made very clear by the name of the API call, this is a soft-deletion, and there is a way to reverse the decision and retrieve any deleted messages.

For each of the /softDelete method calls, there is a corresponding /undoSoftDelete method. Same POST method. Same empty body.

Right now, both of these new methods are only available on the /beta endpoint, and are not yet Generally Available.

Written by Tom Morgan

Tom is a Microsoft Teams Platform developer and Microsoft MVP who has been blogging for over a decade. Find out more.
Buy the book: Building and Developing Apps & Bots for Microsoft Teams. Now available to purchase online with free updates.

Post a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.