Pull Microsoft Defender ATP alerts using SIEM REST API

Applies to:

Want to experience Microsoft Defender ATP? Sign up for a free trial.

Microsoft Defender ATP supports the OAuth 2.0 protocol to pull alerts from the portal.

In general, the OAuth 2.0 protocol supports four types of flows:

  • Authorization grant flow
  • Implicit flow
  • Client credentials flow
  • Resource owner flow

For more information about the OAuth specifications, see the OAuth Website.

Microsoft Defender ATP supports the Authorization grant flow and Client credential flow to obtain access to generate alerts from the portal, with Azure Active Directory (AAD) as the authorization server.

The Authorization grant flow uses user credentials to get an authorization code, which is then used to obtain an access token.

The Client credential flow uses client credentials to authenticate against the Microsoft Defender ATP endpoint URL. This flow is suitable for scenarios when an OAuth client creates requests to an API that doesn't require user credentials.

Use the following method in the Microsoft Defender ATP API to pull alerts in JSON format.


Microsoft Defender Security Center merges similar alert detections into a single alert. This API pulls alert detections in its raw form based on the query parameters you set, enabling you to apply your own grouping and filtering.

Before you begin

  • Before calling the Microsoft Defender ATP endpoint to pull alerts, you'll need to enable the SIEM integration application in Azure Active Directory (AAD). For more information, see Enable SIEM integration in Microsoft Defender ATP.

  • Take note of the following values in your Azure application registration. You need these values to configure the OAuth flow in your service or daemon app:

    • Application ID (unique to your application)
    • App key, or secret (unique to your application)
    • Your app's OAuth 2.0 token endpoint
      • Find this value by clicking View Endpoints at the bottom of the Azure Management Portal in your app's page. The endpoint will look like https://login.microsoftonline.com/{tenantId}/oauth2/token.

Get an access token

Before creating calls to the endpoint, you'll need to get an access token.

You'll use the access token to access the protected resource, which are alerts in Microsoft Defender ATP.

To get an access token, you'll need to do a POST request to the token issuing endpoint. Here is a sample request:

POST /72f988bf-86f1-41af-91ab-2d7cd011db47/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded


The response will include an access token and expiry information.

  "token_type": "Bearer",
  "expires_in": "3599",
  "ext_expires_in": "0",
  "expires_on": "1488720683",
  "not_before": "1488720683",
  "resource": "https://graph.windows.net",

You can now use the value in the access_token field in a request to the Microsoft Defender ATP API.


With an access token, your app can make authenticated requests to the Microsoft Defender ATP API. Your app must append the access token to the Authorization header of each request.

Request syntax

Method Request URI
GET Use the URI applicable for your region.

For EU: https://wdatp-alertexporter-eu.windows.com/api/alerts
For US: https://wdatp-alertexporter-us.windows.com/api/alerts
For UK: https://wdatp-alertexporter-uk.windows.com/api/alerts

Request header

Header Type Description
Authorization string Required. The Azure AD access token in the form Bearer <token>.

Request parameters

Use optional query parameters to specify and control the amount of data returned in a response. If you call this method without parameters, the response contains all the alerts in your organization in the last 2 hours.

Name Value Description
DateTime?sinceTimeUtc string Defines the lower time bound alerts are retrieved from, based on field:
The time range will be: from sinceTimeUtc time to current time.

NOTE: When not specified, all alerts generated in the last two hours are retrieved.
DateTime?untilTimeUtc string Defines the upper time bound alerts are retrieved.
The time range will be: from sinceTimeUtc time to untilTimeUtc time.

NOTE: When not specified, the default value will be the current time.
string ago string Pulls alerts in the following time range: from (current_time - ago) time to current_time time.

Value should be set according to ISO 8601 duration format
E.g. ago=PT10M will pull alerts received in the last 10 minutes.
int?limit int Defines the number of alerts to be retrieved. Most recent alerts will be retrieved based on the number defined.

NOTE: When not specified, all alerts available in the time range will be retrieved.
machinegroups String Specifies machine groups to pull alerts from.

NOTE: When not specified, alerts from all machine groups will be retrieved.


DeviceCreatedMachineTags string Single machine tag from the registry.
CloudCreatedMachineTags string Machine tags that were created in Microsoft Defender Security Center.

Request example

The following example demonstrates how to retrieve all the alerts in your organization.

GET  https://wdatp-alertexporter-eu.windows.com/api/alerts
Authorization: Bearer <your access token>

The following example demonstrates a request to get the last 20 alerts since 2016-09-12 00:00:00.

GET  https://wdatp-alertexporter-eu.windows.com/api/alerts?limit=20&sinceTimeUtc=2016-09-12T00:00:00.000
Authorization: Bearer <your access token>


The return value is an array of alert objects in JSON format.

Here is an example return value:

"AlertTitle":"Suspicious PowerShell commandline",
"Source":"Microsoft Defender ATP",

Code examples

Get access token

The following code example demonstrates how to obtain an access token and call the Microsoft Defender ATP API.

AuthenticationContext context = new AuthenticationContext(string.Format("https://login.windows.net/{0}/oauth2", tenantId));
ClientCredential clientCredentials = new ClientCredential(clientId, clientSecret);
AuthenticationResult authenticationResult  = context.AcquireToken(resource, clientCredentials);

Use token to connect to the alerts endpoint

HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authenticationResult.AccessTokenType, authenticationResult.AccessToken);
HttpResponseMessage response = httpClient.GetAsync("https://wdatp-alertexporter-eu.windows.com/api/alert").GetAwaiter().GetResult();
string alertsJson = response.Content.ReadAsStringAsync().Result;
Console.WriteLine("Got alert list: {0}", alertsJson);

Error codes

The Microsoft Defender ATP REST API returns the following error codes caused by an invalid request.

HTTP error code Description
401 Malformed request or invalid token.
403 Unauthorized exception - any of the domains is not managed by the tenant administrator or tenant state is deleted.
500 Error in the service.