Share via

Automatically delete Teams message

Lwali Hidayat 20 Reputation points
2026-04-15T01:29:56.1033333+00:00

While users can edit or delete their messages manually, there doesn’t seem to be full support for doing this programmatically via APIs in all scenarios.

For example, I have group A containing sensitive daily update, and I want all the message automatically delete after a month from the sent time

Microsoft Teams | Development
Microsoft Teams | Development

Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs

0 comments No comments

Answer accepted by question author

Teddie-D 16,370 Reputation points Microsoft External Staff Moderator
2026-04-15T02:34:44.44+00:00

Hi @Lwali Hidayat 

There is currently no comprehensive API support to programmatically delete Microsoft Teams messages in bulk across all scenarios. This behavior is intentional, as it supports compliance, auditing, and data governance requirements. 

If your group shares sensitive updates and you’d like messages to be automatically removed after a set period such as one month, the recommended approach is to configure retention policies rather than relying on APIs.  

Retention policies in Microsoft Purview give administrators the ability to automatically retain or delete Teams messages based on organizational needs. By setting a policy to delete content after a defined duration, you can ensure that messages are cleaned up in line with your governance requirements. 

These are helpful resources which you can refer to: 


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".    

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. AI answer

    2026-04-15T01:30:08.43+00:00

    Teams does not provide a general-purpose API to auto-delete all messages after a given time, but this scenario is supported with Microsoft Purview retention policies rather than via Teams development APIs.

    To automatically delete messages for a specific group (team/channel or chats) after one month from send time, configure a Teams retention policy with “delete after” settings:

    1. In the Microsoft Purview portal, go to Solutions > Data Lifecycle Management > Policies > Retention policies.
    2. Select New retention policy and name the policy (for example, “Group A – 30‑day delete”).
    3. Choose Static or Adaptive scope depending on how the group is targeted.
    4. For locations, select the appropriate Teams locations for Group A:
      • Teams channel message for standard/shared channel messages in that team.
      • Teams chats if the requirement is for private/group/meeting chats instead.
    5. On Decide if you want to retain content, delete it, or both, configure a delete-only or “retain for X days and then delete” policy with the period set to 30 days.
    6. Complete the wizard and save the policy.

    Behavior and limitations relevant to the scenario:

    • When a retention policy is configured to delete chats and channel messages, messages become eligible for automatic deletion at the end of the configured period. If they are still visible in the Teams client, they disappear and users see a system message that a retention policy deleted them.
    • Messages deleted by a retention policy cannot be recovered.
    • If a policy is configured to retain content, users can still manually edit/delete messages, but copies are preserved in a secured location for eDiscovery until the retention period ends or another policy/hold applies.
    • Multiple retention policies are resolved by the principles of retention: if there is a conflict between retain and delete, content is retained; if there are different durations, the longest retention wins.
    • Deletion is not strictly real-time at the 30‑day mark; background jobs typically act within 1–7 days after the expiration.

    This approach gives automatic, policy-based deletion aligned with compliance requirements, instead of relying on programmatic deletion via Teams APIs.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.