Problems Retrieving SharePoint Online Usage Data with Graph APIs

Longstanding Service Issue Retrieving SharePoint Usage Data

The Microsoft 365 ecosystem is so large that it’s hard to keep track of everything that changes that show up in different workloads. We’ve always known about the difficulties of tracking new features, deprecations, and other issues, but sometimes it takes a user to report something to focus on a specific problem.

An example is when a reader noted that the Graph-based script to report the storage quota used by SharePoint sites no longer included site URLs in the output (Figure 1). The original script (from 2020) used a registered Entra ID app to authenticate and use the Graph getSharePointSiteUsageDetail API to fetch site detail data.

No SharePoint Site URL available in usage data.

SharePoint Usage Data
Figure 1: No SharePoint Site URL available in usage data

Problems in the Graph APIs Accessing SharePoint Usage Data

When I investigated the problem, I decided to update the script code to use the Microsoft Graph PowerShell SDK instead. The update did nothing to retrieve the missing data. This isn’t surprising because the problem lies in the Graph API rather than the way the API is called.

The Microsoft 365 admin center uses the same Graph API for its SharePoint site usage report and the same problem of no site URL data is seen there (Figure 2).

No SharePoint Site URL in the Microsoft 365 admin center usage reports
Figure 1: No SharePoint Site URL in the Microsoft 365 admin center usage reports

Even worse, the SharePoint site activity report in the Microsoft 365 admin center displays no data (Figure 3).

No SharePoint user activity available in the Microsoft 365 admin center.
Figure 3: No SharePoint usage data for user activity is available in the Microsoft 365 admin center

This problem is because the getSharePointActivityUserDetail API returns no data whatsoever. Here’s an example of using the API in PowerShell in an attempt to retrieve SharePoint Online user activity for the last 180 days. The retrieved data should end up in the SPOUserDetail.CSV file.

$Uri = "https://graph.microsoft.com/v1.0/reports/getSharePointActivityUserDetail(period='D180')"
Invoke-MgGraphRequest -Uri $Uri -Method GET -OutputFilePath SPOUserDatail.CSV

However, the output file is perfectly empty apart from the column headers (Figure 4).

Blank user activity data downloaded from the Graph
Figure 4: Blank user activity data downloaded from the Graph

The same approach works perfectly with other usage data. For instance, this query works nicely to fetch Exchange Online usage data:

$Uri = "https://graph.microsoft.com/v1.0/reports/getEmailActivityUserDetail(period='D180')"
Invoke-MgGraphRequest -Uri $Uri -Method GET -OutputFilePath $EmailUsage.CSV

A Known Service Issue with SharePoint Usage Data

It’s not surprising that an API should have a problem. The APIs haven’t changed recently, so the root cause is more likely due to a change in the SharePoint Online back end. This feeling is reinforced by service health report SP676147 filed on 21 September 2023 (last updated 9 February 2024) that blithely says that “SharePoint and OneDrive URLs may not be displayed in some usage reports.”

Microsoft goes on to note that:

We’re continuing our work through the validation of multiple potential mitigation strategies to display the URLs of the affected site usage reports. Due to the complexity of the scenarios involved we anticipate this may take additional time.”

The next update for the service health announcement is due on 1 March 2024. What I’m struggling with is that the usage reports included site URLs without any difficulty for years. Why it should suddenly become an issue is inexplicable. And taking over six months to find a solution is even more so.

Microsoft suggests that developers use the Graph Sites API to retrieve the site URL. For example:

$Uri = ("https://graph.microsoft.com/v1.0/sites/{0}" -f $Site.'Site Id')
$SiteData = Invoke-MgGraphRequest -Uri $Uri -Method GET

This works, but only when using an application permission. Using delegated permissions restricts access to sites that the signed-in user is a member of.

SharePoint PowerShell Still Works

Fortunately, it’s possible to get the site storage quota information using the SharePoint Online management PowerShell module. The Graph APIs read from a usage data warehouse that’s populated using background processes. The data is always at least two days old, but it’s much faster to access than using PowerShell to check the storage for each site. But needs must, and at least the old method still works.

I admit forgetting about the service health announcement, perhaps because it’s been ongoing for so long. I’m genuinely surprised that Microsoft is still working on something that seems so innocuous. And I’m even more surprised that customers aren’t making more of a fuss because the URL is the fundamental way to identify a SharePoint site.


Learn how to exploit the data available to Microsoft 365 tenant administrators through the Office 365 for IT Pros eBook. We love figuring out how things work.

2 Replies to “Problems Retrieving SharePoint Online Usage Data with Graph APIs”

  1. Thanks Tony article on this. Microsoft did not resolve the issue but provided an alternative workaround by suspending the invistigation.

    Admins may see incomplete usage reports for SharePoint Online and OneDrive for Business
    ID: SP676147
    Issue type: Advisory

    Status
    Investigation Suspended

    Impacted services
    SharePoint Online

    Details
    Title: Admins may see incomplete usage reports for SharePoint Online and OneDrive for Business

    User impact: Admins may see incomplete usage reports for SharePoint Online and OneDrive for Business.

    More info: SharePoint and OneDrive URLs may not be displayed in some usage reports. The following report types may be impacted:

    – SharePoint site usage reports

    – OneDrive for Business site usage reports

    – Data Access Governance (DAG) impact was remediated on Saturday, October 21, 2023, reports created during the impact timeframe can be re-generated to include URLs.

    As a workaround, admins with appropriate access can use the SharePoint REST API or Microsoft Graph API to retrieve information about site IDs referenced in the affected reports.

    Here is an example SharePoint REST API request that retrieves information about the Contoso site with site ID 15d43f38-ce4e-4f6b-bac6-766ece1fbcb4: https://contoso.sharepoint.com/_api/v2.1/sites/contoso.sharepoint.com,15d43f38-ce4e-4f6b-bac6-766ece1fbcb4

    The Microsoft Graph API can be used to list SharePoint sites or retrieve information about a specific site ID: https://learn.microsoft.com/en-us/graph/api/resources/site?view=graph-rest-1.0

    Examples:

    https://graph.microsoft.com/v1.0/sites?search=*&$select=sharepointIds

    https://graph.microsoft.com/v1.0/sites/{siteId}

    The Microsoft Graph API can be used to retrieve information about a given user’s OneDrive for Business site: https://learn.microsoft.com/en-us/graph/api/resources/drive?view=graph-rest-1.0

    Example:

    https://graph.microsoft.com/v1.0/users/{userId}/drives?$select=sharepointIds

    Final status: Additional resources and guidance are being provided for admins to perform a robust set of optional workaround actions here: https://learn.microsoft.com/en-US/microsoft-365/admin/activity-reports/resolve-site-urls?view=o365-worldwide.

    We’re continuing an investigation focused on the restoration of the URLs into the affected Site Usage reports. We expect that this process will continue for an extended period of time. We’ll provide additional notifications through standard update channels as our work on the necessary changes progresses.

    More general information about site usage reports is provided here: https://learn.microsoft.com/en-US/microsoft-365/admin/activity-reports/sharepoint-site-usage-ww?view=o365-worldwide and here https://learn.microsoft.com/en-us/microsoft-365/admin/activity-reports/onedrive-for-business-usage-ww?view=o365-worldwide.

    Scope of impact: Your organization is affected by this event, and admins attempting to access affected usage reports may be unable to view URLs within the reports.

    Start time: Thursday, September 21, 2023, at 4:15 AM UTC.

    End time: Friday, March 8, 2024, at 11:30 PM UTC.

    Root cause: A previous change made to mitigate an unrelated service side issue removed the flow of URLs for the affected usage reports, resulting in impact.

    Next steps:

    – We’re continuing to work on the necessary changes required to restore this aspect of the service, and we’ll provide additional notifications through standard update channels as they become available.

    This is the final update for this event.

    Is this message helpful?

Leave a Reply

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