Updating Microsoft Teams Chats and Managing Attachments via Microsoft Graph API in C# .NET6

Amit 671 Reputation points
2024-06-14T14:11:33.4433333+00:00

Hi,

I want to update Microsoft Teams Chats (one-on-one / Channel) programmatically via C# .NET6. Additionally, I want to download and delete attachments.

I see that the Microsoft Graph API has an "Update chatMessage" section, but it is not working for me.

https://learn.microsoft.com/en-us/graph/api/chatmessage-update?view=graph-rest-1.0&tabs=http

Can someone please confirm if we can update/delete chat messages and delete and download attachments via the Graph API?

If yes, could you provide any sample code?

Thank you.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,103 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,967 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Prasad-MSFT 5,891 Reputation points Microsoft Vendor
    2024-06-17T12:53:35.2433333+00:00

    Yes, you can update and delete chat messages as well as delete and download attachments via the Microsoft Graph API.

    Updating a Chat Message: To update a chat message, you can use the PATCH request to the /chats/{chat-id}/messages/{message-id} endpoint.

    https://learn.microsoft.com/en-us/graph/api/chatmessage-update?view=graph-rest-1.0&tabs=http

    Deleting a Chat Message: To delete a chat message, you can send a DELETE request to the /chats/{chat-id}/messages/{message-id} endpoint.

    https://learn.microsoft.com/en-us/graph/api/chatmessage-softdelete?view=graph-rest-1.0&tabs=http

    Downloading an Attachment: To download an attachment, you first need to get the attachment ID using a GET request to the /chats/{chat-id}/messages/{message-id}/attachments endpoint. Then, you can download the attachment using the GET request to the /chats/{chat-id}/messages/{message-id}/attachments/{attachment-id}/$value endpoint.

    Deleting an Attachment: Currently, the Graph API does not support directly deleting an attachment from a chat message. You would need to update the message to remove the attachment reference.

    Thanks, 

    Prasad Das

    ************************************************************************* 

    If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.