Warning
The steps and screenshots in this article reflect the environment at the time of writing. The Azure portal no longer offers the option to set a client secret to never expire. For current expiration limits and recommendations, see Add and manage app credentials in Microsoft Entra ID.
Reports available in the Microsoft 365 admin center can also be retrieved through the Microsoft Graph reports API. This makes it possible to automate report retrieval with Microsoft Graph. This article shows how to create a Power Automate flow that uses the Microsoft Graph reports API. The flow sends the retrieved report as an email attachment.
For the basics of trying the Microsoft Graph reports API, see Getting started with the Microsoft Graph reports API.
Strictly speaking, the reports in the Microsoft 365 admin center can be retrieved using the beta version of the Microsoft Graph reports API. However, using the beta version of Microsoft Graph in production is not supported. There is also no consolidated information about which reports in the Microsoft 365 admin center correspond to which reports in the Microsoft Graph reports API. You need to check the reference documentation or retrieve the reports to find out.
The Microsoft Graph reports API returns a 302 redirect. When you send a request using the Power Automate HTTP connector, the action fails because it does not handle the 302 redirect. To address this, add another HTTP connector and configure it to run when the first HTTP connector fails. The second connector retrieves the Location header value and sends another request.
Prerequisites
This flow uses the Power Automate HTTP connector, so a paid Power Automate license is required instead of the free version.
An Office 365 administrator account is required because the flow uses Microsoft Graph application permissions to obtain an access token.
Steps
Sign in to the Azure portal as an Office 365 administrator.
Select [Active Directory] - [App registrations] - [New registration].
Enter an application name in [Name] (for example,
App01).Under [Supported account types], select [Accounts in this organizational directory only].
Under [Redirect URI], select [Web] and enter a URI of your choice (for example,
https://localhost/App01).Select [Register].
Make a note of the displayed [Application (client) ID].
Select [Manage] - [Certificates & secrets].
Select [New client secret].
Enter a description in [Description] (for example,
Key1).Select an expiration period under [Expires] (for example, never).
Select [Add].
Make a note of the displayed client secret value.
Select [Manage] - [API permissions].
Select [Add a permission].
Select [Microsoft Graph].
Select [Application permissions].
Select [Reports] - [Reports.Read.All].
Select [Add permissions].
Select [Grant admin consent for <tenant name>].
Select [Yes].
Sign in to Power Automate.
Select [Create].
Under [Start from blank], select [Instant cloud flow].
Enter a [Flow name], select [Manually trigger a flow] under [Choose how to trigger this flow], and select [Create].
Select [New step].
On the [Premium] tab, enter
HTTPin [Search connectors and actions], then select [HTTP] under [Actions].Select [Show advanced options] and configure the action as follows:
- Method: GET
- URI: The URL of the Microsoft Graph reports API to request
- Authentication: Active Directory OAuth
- Tenant: The
onmicrosoft.comdomain name of the tenant where you registered the app - Audience:
https://graph.microsoft.com - Client ID: The value noted in step 7
- Credential Type: Secret
- Secret: The value noted in step 13
Select [New step] and add another HTTP connector.
Select […] on the new HTTP connector, then select [Configure run after].
Select only [has failed], then select [Done].
Select [Show advanced options] on the new HTTP connector and configure it as follows:
- Method: GET
- URI: Enter
outputs('HTTP').headers.Locationunder [Expression], then select [OK] - Authentication: None
Select [New step].
On the [Standard] tab, select [Office 365 Outlook], then select [Send an email (V2)] under [Actions].
Select [Show advanced options] and configure the action as follows:
- To: The email recipient
- Subject: The email subject
- Body: The email body
- Attachments Name - 1: A file name of your choice with the
csvextension - Attachments Content - 1: Select [Body] from [HTTP 2] under [Dynamic content]
Select [Save].
Select the left arrow icon at the upper left to return to the previous page.
If [Your flow is ready to go] appears, select [OK].
Select [Run].
If you have not signed in to Office 365 Outlook, sign in.
Select [Continue].
Select [Run flow].
Select [Done].
Confirm that the run completes and an email with the report attached is sent.