You can now Bulk Export Teams chat data with a dedicated Graph API call
This was announced at Ignite in passing but with little detail until a Microsoft Documentation post yesterday.
There is a new API call, designed for those who want to bulk export 1:1 and group chat messages from Microsoft Teams. It has a high throttling bar (200 RPS per app per tenant) and a single endpoint to expose all messages for a user:
GET https://graph.microsoft.com/beta/users/{id}/chats/allMessages
You can use some basic OData filters as well, such as specifying a date/time period and limiting the number of messages:
GET https://graph.microsoft.com/beta/users/{id}/chats/allMessages?$top=50&$filter=lastModifiedDateTime gt 2020-06-04T18:03:11.591Z and lastModifiedDateTime lt 2020-06-05T21:00:09.413Z
Gotchas
This API call is still in preview, and on the Beta endpoint. Also, it’s classed as a Protected API, so you need to get your application ID validated for that. There’s a specific form to fill out.
You need the following permissions:
- Chat.Read.All: enables access to all 1:1 and Group chat messages
- User.Read.All: enables access to the list of users for a tenant
It’s also worth realising that this API is NOT something which provides all the export data in a single ZIP file or similar. The response from these calls is JSON data representing messages. For all but the very smallest tenant, that data will be too much information for a single response body, and a nextlink will be provided in the response (a property called @odata.nextlink). That provides the URL to the next set of data. To retrieve all the data, you need to keep calling the nextlink URLs until that value is null. A null value or non-existent @odata.nextlink value indicates that there are no more pages of data to retrieve.
Today, use of this API is free. However, there is a sentence in the documentation page which caught my eye:
In the future, Microsoft may require you or your customers to pay additional fees based on the amount of data accessed through the API.
If you include this API call in your solution or process, it’s worth staying up to date on any changes to this position in case it changes.