In Microsoft 365 there are many usage reports that are available to be retrieved in CSV file format via Microsoft Graph. This blog post will show you how to authenticate to Microsoft Graph using Power Automate then download many different M365 usage reports from your tenant to a SharePoint site on a scheduled basis. This could be handy as most of the usage information in M365 is only retained for 30-120 days before being overwritten.

A template Flow is provided which could be adapted to target other workloads for M365 reports i.e. SharePoint, Teams, Yammer etc

Template flow which downloads the reports and reports written to a SharePoint document library
A report downloaded – showing SharePoint site usage.

Microsoft 365 Usage Reports

Using Microsoft Graph, you can access Microsoft 365 usage reports resources to get information about how people in your business are using Microsoft 365 services. A list of all the current reports usage reports available can be found on the Microsoft Graph – M365 Usage Reports section.

There are many different workloads that can be reported on and you can see the bullet point list below of the available reporting sections.

  • Microsoft Teams device usage
  • Microsoft Teams user activity
  • Outlook activity
  • Outlook app usage
  • Outlook mailbox usage
  • Microsoft 365 activations
  • Microsoft 365 active users
  • Microsoft 365 groups activity
  • OneDrive activity
  • OneDrive usage
  • SharePoint activity
  • SharePoint site usage
  • Skype for Business activity
  • Skype for Business device usage
  • Skype for Business organizer activity
  • Skype for Business participant activity
  • Skype for Business peer-to-peer activity
  • Yammer activity
  • Yammer device usage
  • Yammer groups activity

All of these reporting sections have sub sections for the report type i.e. getSharePointSiteUsageDetail and all have a unique HTTP request URL i.e.’D7′). This url can then be used to make a HTTP request using Power Automate, PowerShell, Python etc. The url must also have a date parameter to specify the date (i.e. YYY-MM-DD) on which to obtain the report from or a period parameter (D7) to specify the length off time in days the report is to be aggregated for.

If the HTTP Request is successful then a 302 Found Response is given that redirects to a preauthenticated download URL for the report – the URL is then found in the response Location header.

This Preauthenticated download URL is only valid for a short period of time (a few minutes) and does not require an Authorisation header so could even be downloaded from putting the url in a web browser.

Create App Registration in your Azure AD

In order to download the reports the following Microsoft Graph permission Reports.Read.All is required to call the API.

This is done by creating an App Registration in your Azure AD – link here.

Ensure the API permissions for the App Registration have at least Reports.Read.All for application permissions and an admin has granted consent for this. You may also want add Reports.Read.All for delegated (user) permissions but this solution does not require these permissions.

Create a new Client Secret for the app and make a note of the created value which you will use in Power Automate.

Finally make a note of the Application (client) ID and Directory (tenant) ID as you will use these in Power Automate to Authenticate to Microsoft Graph.

Finally in my experience these permissions took a couple of hours to apply so if you Power Automate flow doesn’t work immediately – wait a couple of hours for the permissions to propagate.

Create Flow in Power Automate to download M365 reports

You can either use the steps below as guidance or download a Power Automate template Flow of the solution which can then be added to your environment – download link here.

I will then use Power Automate to perform the following:

  1. Trigger once a week to download the past 7 days reports.
  2. Modify the variables for the tenantId, clientid and client secret to reflect the values from YOUR tenant.
  3. Store a JSON array which holds all of the M365 usage report request urls we want to download reports for. Currently configured to download all SharePoint and OneDrive reports but this should be changed to add/remove further reports from Working with Microsoft 365 usage reports in Microsoft Graph on the Microsoft Graph site i.e. add Teams usage reports.

Sample JSON Array – modify to suit your workload/reporting requirements.

  1. Connect to Microsoft Graph using a HTTP action using the POST method using application permissions and generate an Access Token. This access token will then be used in the Headers of subsequent Microsoft Graph calls to download M365 usage reports. Ensure the variables are used for tenantId, clientId and clientSecret.
  1. Add an Apply to each to loop through the JSON array of M365 usage report request urls – add the following expression to the Apply to each input section

The loop will the loop through the JSON array and do the following for each url:

  • Request an M365 Usage report from Microsoft Graph with a HTTP GET action using the access token in the header generated in step four.

Add an Autorization header and then add the following concatenate expression in the expression builder for the Authorization value.

Ensure your HTTP Login Action is name is named the same as mine or change the expression slightly.

  • The step above will provide on success a pre-authenticated url in the location header which is used to download the CSV file for the report.

In URI enter the following in the expression builder.

NOTE this action must also be configured to run after the previous step has failed to allow for the HTTP redirection which Power Automate treats as failing.

  1. Uploads the CSV file to a SharePoint document library and the name format will be in the format yyyyMMddHHmmss-reportname.csv

Ensure that the SharePoint web part connects to a valid site and library.

File Name uses the following string manipulation in Power Automate to generate a logical file name.

Completed Power Automate Flow:


This blog post focused on using Power Automate to download M365 usage reports and provides a flow that can be modified to retrieve any of the numerous M365 usage reports another many workloads i.e. Teams, SharePoint, Onedrive, Yammer, Outlook, Microsoft 365 Groups etc.

You could install this flow in your environment and keep a historical record of M365 usage reports which could be handy as most of the usage reports are reset after 30-120 days. You could also manipulate this information in Power Automate further and perhaps extend the workflow to email reports to certain users or even read the reports using Power Automate.

If you are also interested in reporting further on the M365 Audit logs then see my blogs using Power Automate and the the Office 365 Management API here.

This Post Has 16 Comments

  1. Luca Willms

    Hi, thank you for sharing your amazing work, I didn’t have any idea how I can access the data, thanks!
    But unforgettably I got every time an error after I submit the flow:

    Unable to process template language expressions in action ‘HTTP__-_Download_CSV_File_of_Report’ inputs at line ‘1’ and column ‘8569’: ‘The template language expression ‘outputs(‘HTTP_-_Request_M365_Usage_Report’)[‘headers’][‘location’]’ cannot be evaluated because property ‘location’ doesn’t exist, available properties are ‘Transfer-Encoding, Vary, Strict-Transport-Security, request-id, client-request-id, x-ms-ags-diagnostic, Cache-Control, Date, Content-Type, Content-Length’. Please see for usage details.’

    *Link images from Power Automate*

      1. Luca

        Hi, yes that was the Problem, i already fix this issue, but Is it possible to split the data to add it to an existing Sharepoint List? For example I want to use the column “User Principal Name” from my recent Report (Sharepoint or Onedrive) to add this column to my SharePoint list every time.

  2. Casey


    Is there any way to edit the report urls to give data to specific SharePoint sites?

  3. Haze

    I’m getting a “CompactToken parsing failed with error code: 80049217” for request m365 usage report part. 🙁

  4. haze

    Actually I fixed the compacttoken parsing error.. However, now I’m getting error 302 for request m365 usage report part. 🙁 How do I fix that? thanks It seems in the output tho I was able to get the report url for download but it still fails the flow.

  5. Hakeem

    Hello Leon,
    Greetings !

    This Post is really amazing. Thanks for sharing it,
    I have exported 0365 usage report. But it’s displaying all the mailboxes.
    I want to filter only 15 mailboxes details from the report.
    Is there any possibility for that.
    Your reply will be highly appreciated.

  6. Jason

    Great article!!! Easy to follow and works perfectly!!!


  7. Fred

    Can something similar be done to get the Site Usage Analytics?

    Site Usage Analytics on a SharePoint site goes back up to 90 days. We want to be able to extract the data regularly so we can report on usage for the past year.

  8. Sam

    What’s the point in creating a guide like this if you are giving people code with errors. The following expression is invalid:

    concat(formatDateTime(utcNow(), ‘yyyyMMddHHmmss’),’-‘,replace(first(split(item(),'(‘)),’’,”),’.csv’)

    Also, where are you getting the green location from in the HTTP – Downlaod CSV File of Report card? You provide the code as an expression and it becomes purple, so clearly different than the screenshot. Why is this?

    Pretty useless guide as it stands at the moment.

    1. Matt

      Hi Sam, just remove the

      1. Matt


  9. Syed

    Hello Lean Armston,

    I am getting blank values in “Site URL” Column sometimes.
    Could you please help me why this is happening.


    1. Pieter Veenstra

      Hi Syed,

      Did you manage to get this resolved? I’m having the same issue. Both Site Url and SiteID remain blank.

      I’m also finding that item analytics allTime and lastSevenDays return null values.

      The Usage screens in SharePoint however do display the correct data.

Leave a Reply