Freigeben über


Office 365 usage report APIs in preview

We'll get to configuring and using the Office 365 Usage Reports based on the beta endpoint of the Microsoft Graph API.   First let's quickly overview why this is important.  On October 1st, 2017 some of the API endpoints for the tried and true Reporting webservice https://msdn.microsoft.com/en-us/library/office/jj984325.aspx will be deprecated.   I've grown to depend on this for data modeling and understanding various tenants usage.     Our, Microsoft, march towards a unified API has tremendous benefits for the developer and in reality all platforms.  Azure AD has truly enabled Microsoft to offer first class development and usability.   Enough about that for a moment.

So what's replacing the Reporting Service endpoints.  Surely if the reporting service is being deprecated it has a replacement.  That's a bigger conversation but the good news is; you can start building today  https://blogs.office.com/en-us/2017/03/31/whats-new-in-office-365-administration-public-preview-of-microsoft-graph-reporting-apis/     I don't want to take screenshots of how to register an application in Azure AD.   For the sake of this demo I'll send you to 2 locations.

  1. Azure AD v1.0 Endpoint - Integrating Applications with Azure AD
  2. Azure AD v2.0 Endpoint - Register your app

For these reports you only need v1.0 "Microsoft Graph > Application Permissions > Read all usage reports"  or v2.0 "Application Permissions > Reports.Read.All"    For the sample code I'm providing I'll demonstrate the v1.0 registration and application permissions.

If you aren't familiar with the PinchPerfect.InfrastructureAsCode.Powershell project its a quick way to gather a few sample cmdlets for processing various SharePoint Online activities.  Go to my Powershell Readme  for a walk through on cloning locally and running.     Once you have the Powershell solution cloned locally you can start to debug and run through the Preview Usage API queries.  I haven't implemented admin consent; the assumption is that you've done this through the links above.  I've taken care of the Authentication Token and Refreshing the token once it's expired.  So the core framework is in place for you to extend it.   Once you've followed my steps in the Powershell Readme you can debug or run in Powershell the following:

Extract from sample-preview-and-adoption.ps1

 $graphparms = @{
appid='';
appsecret='';
aaddomain='.onmicrosoft.com';
ResourceUri='https://graph.microsoft.com';
}

Report-IaCUsageAnalytics @graphparms -ReportType OneDriveActivity -ViewType Users -Period D30 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType OneDriveActivity -ViewType Files -Period D30 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType OneDriveActivity -ViewType Detail -Date ([System.DateTime]::Parse("2017-09-06")) -Verbose

Report-IaCUsageAnalytics @graphparms -ReportType OneDriveUsage -ViewType Account -Period D30 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType OneDriveUsage -ViewType Files -Period D30 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType OneDriveUsage -ViewType Storage -Period D30 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType OneDriveUsage -ViewType Detail -Date ([System.DateTime]::Parse("2017-09-06")) -Verbose

Report-IaCUsageAnalytics @graphparms -ReportType SharePointActivity -ViewType Users -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType SharePointActivity -ViewType Pages -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType SharePointActivity -ViewType Files -Period D7 -Verbose

Report-IaCUsageAnalytics @graphparms -ReportType SharePointSiteUsage -ViewType Sites -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType SharePointSiteUsage -ViewType Pages -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType SharePointSiteUsage -ViewType Storage -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType SharePointSiteUsage -ViewType Files -Period D7 -Verbose

Report-IaCUsageAnalytics @graphparms -ReportType EmailActivity -ViewType Activity -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType EmailActivity -ViewType Users -Period D7 -Verbose

Report-IaCUsageAnalytics @graphparms -ReportType Office365GroupsActivity -ViewType Activity -Period D7 -Verbose

Report-IaCUsageAnalytics @graphparms -ReportType Office365ActiveUsers -ViewType Services -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType Office365ActiveUsers -ViewType Users -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType Office365ActiveUsers -ViewType Detail -Date ([System.DateTime]::Parse("2017-09-06")) -Verbose

Report-IaCUsageAnalytics @graphparms -ReportType MailboxUsage -ViewType Mailbox -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType MailboxUsage -ViewType Storage -Period D7 -Verbose
Report-IaCUsageAnalytics @graphparms -ReportType MailboxUsage -ViewType Quota -Period D7 -Verbose

This is just the start of this project.  My intent is to build the companion Web project with Web API to enable a UI visualization of this data.  As of today I extended the ReportVisitor to pump this data into a database.    If you are interested in the database and seeing a holistic overview leave a comment.   This isn't complete and as the title indicates very much a preview effort.