Warning
The Message Trace reports in the Office 365 Reporting Web Service described in this article were retired on April 8, 2026. Do not use this API for new implementations. For current message tracing, use Get-MessageTraceV2 and Get-MessageTraceDetailV2 in Exchange Online PowerShell, or the Microsoft Graph Message Trace API. For details, see the Graph-based message trace API onboarding guide.
See Microsoft’s announcement about the new Message Trace in Exchange Online, Get-MessageTraceV2, Get-MessageTraceDetailV2, and Deprecation of Basic authentication in Exchange Online.
The following is historical content published in 2019 and updated in 2022. These steps do not describe a procedure for the current service.
There is no simple way to try the Office 365 Reporting Web Service, but PowerShell makes it relatively easy to check how it works. This article shows how to retrieve message trace data.
The official documentation available at the time was not maintained very well. Use it with care:
Use the delegated permissions or application permissions procedure, depending on how you obtain an access token. After you have a token, continue to Send a request to the Office 365 Reporting Web Service with PowerShell. The Basic authentication procedure is included as historical reference under Try Basic authentication.
Try delegated permissions with PowerShell
Sign in to the Azure portal.
Select [Active Directory] - [App registrations] - [New registration].
Enter an app name, such as
App01.Under [Supported account types], select [Accounts in this organizational directory only].
Under [Redirect URI], select [Web] and enter a URI, such as
https://localhost/App01.Select [Register], then record the displayed [Application (client) ID].
Select [Manage] - [Certificates & secrets] - [Client secrets], then select [New client secret].
Enter a description and expiration, add the secret, and record its value. Store the secret securely; you cannot view its value again later.
Select [Manage] - [API permissions] - [Add a permission].
Select [APIs my organization uses] - [Office 365 Exchange Online]. Under [Delegated permissions], select
ReportingWebService.Read, then add the permission.Create a URL in the following format and open it in a browser. Replace each placeholder with the actual value. The redirect URI and scope must be URL-encoded.
1
https://login.microsoftonline.com/<tenant-name>/oauth2/v2.0/authorize?response_type=code&client_id=<client-id>&redirect_uri=<url-encoded-redirect-uri>&scope=<url-encoded-https://outlook.office.com/.default>&response_mode=query&prompt=login
Sign in as an Exchange Online administrator. You are redirected to a URL that starts with the registered redirect URI. The page itself does not have to load. Record the value of the
codeparameter in the URL.In PowerShell, use the authorization code to get an access token.
1
2
3
4
5
6
7
8
9$Params = @{
"grant_type" = "authorization_code"
"redirect_uri" = "<registered-redirect-uri>"
"client_id" = "<registered-client-id>"
"client_secret" = "<client-secret>"
"code" = "<authorization-code>"
"scope" = "https://outlook.office.com/.default"
}
Invoke-RestMethod -Uri "https://login.microsoftonline.com/<tenant-name>/oauth2/v2.0/token" -Method "POST" -Body $Params
This completes the access-token procedure for delegated permissions. Steps 11 and later use the Authorization Code Flow. You do not have to use a browser and PowerShell exactly as shown; if you are familiar with the process, you can obtain the token another way, such as with MSAL.
The procedure above registers a confidential client app, but a public client app can also be used when operating an API from PowerShell. In general, a public client app is appropriate for this scenario. This example follows the confidential-client approach described in the documentation at the time.
Try application permissions with PowerShell
Sign in to the Azure portal.
Select [Active Directory] - [App registrations] - [New registration].
Enter an app name, such as
App02.Under [Supported account types], select [Accounts in this organizational directory only].
Under [Redirect URI], select [Web] and enter a URI, such as
https://localhost/App02.Select [Register], then record the displayed [Application (client) ID].
Select [Manage] - [Certificates & secrets] - [Client secrets], then select [New client secret].
Enter a description and expiration, add the secret, and record its value. Store the secret securely; you cannot view its value again later.
Select [Manage] - [API permissions] - [Add a permission].
Select [APIs my organization uses] - [Office 365 Exchange Online]. Under [Application permissions], select
ReportingWebService.Read.All, then add the permission.Select [Grant admin consent for your tenant], then select [Yes].
In the Azure portal, select [Active Directory] - [Manage] - [Roles and administrators] - [Exchange administrator] - [Add assignment], then add the registered app. If you use Privileged Identity Management (PIM), select the app as a member and set the assignment type to [Active].
Wait for the settings to synchronize to Exchange Online.
In PowerShell, get an access token using application permissions.
1
2
3
4
5
6
7$Params = @{
"client_id" = "<registered-client-id>"
"scope" = "https://outlook.office.com/.default"
"client_secret" = "<client-secret>"
"grant_type" = "client_credentials"
}
Invoke-RestMethod -Uri "https://login.microsoftonline.com/<tenant-name>/oauth2/v2.0/token" -Method "POST" -Body $Params
Instead of steps 11 and 12, you can create a URL in the following format, open it in a browser, sign in as a global administrator, and grant consent to the app. The redirect URI and scope must be URL-encoded.
1 | https://login.microsoftonline.com/organizations/v2.0/adminconsent?client_id=<client-id>&redirect_uri=<url-encoded-redirect-uri>&scope=<url-encoded-https://outlook.office.com/.default> |
The token procedure above uses the Client Credentials Flow. If you are familiar with the process, you can get a token another way, such as with MSAL.
Send a request to the Office 365 Reporting Web Service with PowerShell
Use the access token to retrieve data equivalent to the Get-MessageTrace cmdlet. This example filters by sender email address.
1 | $Headers = @{ "Authorization" = "Bearer <access-token>" } |
To specify a date range, run a request like this:
1 | (Invoke-RestMethod -Uri "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace/?`$filter=StartDate eq datetime'2022-09-01T00:00:00Z' and EndDate eq datetime'2022-09-02T00:00:00Z'" -Headers $Headers).Content.Properties | |
To get data equivalent to Get-MessageTraceDetail, you need to create a separate request. The following function creates a URL for retrieving the details from a message trace entry.
1 | function Get-MessageTraceDetailUrl { |
First, store the message trace results in a variable.
1 | $MessageTrace = Invoke-RestMethod -Uri "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace/" -Headers $Headers |
Then pass the first message to the function to create a URL for its details.
1 | $MessageTrace.Content.Properties[0] | Get-MessageTraceDetailUrl -Escape |
Use the generated URL to get data equivalent to Get-MessageTraceDetail.
1 | (Invoke-RestMethod "<generated-url>" -Headers $Headers).Content.Properties | |
Try Basic authentication
Warning
The following steps are included only as a historical record. Basic authentication is disabled in all Exchange Online tenants and cannot be used. The Message Trace reports in the Reporting Web Service described in this article have also been retired.
At the time, you could run the following command in Windows PowerShell and enter Office 365 administrator credentials in the authentication dialog. This example filters by sender email address.
1 | $Credential = Get-Credential |
Check that the result contains data equivalent to the Get-MessageTrace cmdlet. To specify a date range, run a request like this:
1 | (Invoke-RestMethod -Uri "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace/?`$filter=StartDate eq datetime'2019-07-18T00:00:00Z' and EndDate eq datetime'2019-07-19T00:00:00Z'" -Credential $Credential).Content.Properties | |
To get data equivalent to Get-MessageTraceDetail, define the Get-MessageTraceDetailUrl function shown earlier. First retrieve the message trace results, then create a URL from the first message.
1 | $MessageTrace = Invoke-RestMethod -Uri "https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MessageTrace/" -Credential $Credential |
Use the generated URL to get the details.
1 | (Invoke-RestMethod "<generated-url>" -Credential $Credential).Content.Properties | |