Per-Team Activity Data Available via Graph API

Access the Same Information as in the Teams Admin Center

The Microsoft Graph usage reports API gives access to the activity data gathered for many Microsoft 365 workloads, including SharePoint Online, Exchange Online, OneDrive for Business, Yammer, and Teams. Up to now, the Teams data are available at a user level (how many messages someone posted, for instance), but you couldn’t retrieve per-team activity data. This is even though the Teams admin center boasts a team activity report (Figure 1).

Teams activity data viewed through the Teams admin center
Figure 1: Teams activity data viewed through the Teams admin center

Downloading the report from the Teams admin center creates a CSV file. The good news is that Microsoft has upgraded the Graph reports API to allow tenants to create the data shown in the Teams admin center programmatically. Since its inception, the reports API has focused on per-user activity (which is what we use in the Microsoft 365 User Activity Report script). Now, as reported by Vasil Michev, new Graph queries are available to grab per-team activity data.

Caveats About Team Activity Data

Although it’s great to have the ability to download per-team activity data, the information comes with some caveats:

  • The data retrieved from the Graph is for user messaging activities in channels only. It does not reflect other team activity such as document creation, process tasks, Yammer communities, or any other apps.
  • It does not include messages sent to Team channels using email.
  • It does not include messages posted to channels using connectors such as the RSS or incoming webhook connectors.

In addition, if a team hasn’t had any activity over the period of the usage report (up to 90 days), the Graph doesn’t include it in the data. For instance, this means that the team created to manage Teams approval templates will never show up in a usage report. Activity means that some channel-related action happens in a team. It doesn’t necessarily mean that someone posts a new topic or replies to a topic. Editing channel properties or creating a new channel is sufficient. In my tenant, the data included information for 35 of 72 teams (I have many teams created for test purposes).

Accessing the Per-Team Activity Data

You can access the per-team activity data with a registered Azure AD app or the Microsoft Graph PowerShell SDK. In both cases, the Reports.Read.All permission is needed.

The query to retrieve per-team activity data is straightforward:

Write-Host "Finding Teams Activity Data from the Graph..."
$Uri = "https://graph.microsoft.com/beta/reports/getTeamsTeamActivityDetail(period='D90')?`$format=application/json"
[array]$TeamsData =  (Invoke-RestMethod -Uri $Uri -Headers $headers -Method Get)

The $TeamsData array which receives the data includes an array called Value storing the statistics such as number of messages, replies, and mentions. It’s easy to report the information by processing each team and extracting the statistics for each team. Here’s how I do the job, including the calculation of how many days it has been since the team was last active (for channel activity):

$Report = [System.Collections.Generic.List[Object]]::new() 
ForEach ($Team in $TeamsData.Value) {
   $DaysSinceActive = (New-Timespan -Start ($Team.LastActivityDate -as [datetime]) -End ($Team.Reportrefreshdate -as [datetime])).Days
   $ReportLine  = [PSCustomObject] @{   
      Team            = $Team.teamName
      Privacy         = $Team.teamType
      TeamId          = $Team.teamId
      LastActivity    = Get-Date ($Team.lastActivityDate) -format dd-MMM-yyyy
      ReportPeriod    = $Team.Details.reportPeriod
      DaysSinceActive = $DaysSinceActive
      ActiveUsers     = $Team.Details.activeUsers
      Posts           = $Team.Details.postMessages
      Replies         = $Team.Details.replyMessages
      Urgent          = $Team.Details.urgentMessages
      Mentions        = $Team.Details.mentions
      Guests          = $Team.Details.guests
      ActiveChannels  = $Team.Details.activeChannels
      Reactions       = $Team.Details.reactions }
 $Report.Add($ReportLine)
} #end ForEach

You can download the script from the Office365itpros.com GitHub repository. Figure 2 shows what the output looks like:

Figure 2: Reporting Teams activity data

The data is usually two days behind the actual date. The time needed to process activity data and make it available in a repository accessible via the Graph accounts for the lag. Currently, the data appears to include activity for regular and private channels, but not for shared channels. No doubt Microsoft will include shared channel activity after the feature is generally available.

If you don’t want to use a registered Azure AD app, you can connect to the Microsoft Graph PowerShell SDK and use the Invoke-MgGraphRequest cmdlet to fetch the data. For example:

Connect-MgGraph -Scopes Report.Read.All
Select-MgProfile beta
$Uri = "https://graph.microsoft.com/beta/reports/getTeamsTeamActivityDetail(period='D90')?`$format=application/json"
[array]$TeamsData = Invoke-MgGraphRequest -Method Get -Uri $Uri

After fetching the data, the same kind of loop extracts the data.

Incomplete But Nice to Have

The Microsoft 365 Groups and Teams activity report script can use per-team activity data downloaded from the Teams admin center. We can upgrade the script to use the data fetched from the Graph instead, which should speed things up and avoid the need for administrators to download the data manually. That’s all goodness, but the fact remains that the per-team activity data doesn’t represent a truly accurate picture of what happens in a team. It’s fine if all you’re worried about is channel conversations; it’s not so good for anything else.

One Reply to “Per-Team Activity Data Available via Graph API”

Leave a Reply

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