Access the Microsoft 365 Defender APIs
Note
Want to experience Microsoft 365 Defender? Learn more about how you can evaluate and pilot Microsoft 365 Defender.
Applies to:
- Microsoft 365 Defender
Note
Try our new APIs using MS Graph security API. Find out more at: Use the Microsoft Graph security API - Microsoft Graph | Microsoft Learn.
Important
Some information relates to prereleased product which may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Microsoft 365 Defender exposes much of its data and actions through a set of programmatic APIs. These APIs help you automate workflows and make full use of Microsoft 365 Defender's capabilities.
In general, you'll need to take the following steps to use the APIs:
- Create an Azure Active Directory application
- Get an access token using this application
- Use the token to access the Microsoft 365 Defender API
Note
API access requires OAuth2.0 authentication. For more information, see OAuth 2.0 Authorization Code Flow.
Once you've accomplished these steps, you're ready to access the Microsoft 365 Defender API using a particular context.
Application context (Recommended)
Use this context for apps that run without a signed-in user present, such as background services or daemons.
- Create an Azure Active Directory web application.
- Assign the desired permissions to the application.
- Create a key for the application.
- Get a security token using the application and its key.
- Use the token to access the Microsoft 365 Defender API.
For more information, see Create an app to access Microsoft 365 Defender without a user.
User context
Use this context to perform actions on behalf of a single user.
- Create an Azure Active Directory native application.
- Assign the desired permission to the application.
- Get a security token using the user credentials for the application.
- Use the token to access the Microsoft 365 Defender API.
For more information, see Create an app to access Microsoft 365 Defender APIs on behalf of a user.
Partner context
Use this context when you need to provide an app to many users across multiple tenants.
- Create an Azure Active Directory multi-tenant application.
- Assign the desired permission to the application.
- Get admin consent for the app from each tenant.
- Get a security token using user credentials based on a customer's tenant ID.
- Use the token to access the Microsoft 365 Defender API.
For more information, see Create an app with partner access to Microsoft 365 Defender APIs.
Related articles
Use the Microsoft Graph security API - Microsoft Graph | Microsoft Learn
Create a 'Hello world' application that accesses the Microsoft 365 APIs
Tip
Do you want to learn more? Engage with the Microsoft Security community in our Tech Community: Microsoft 365 Defender Tech Community.
Feedback
Submit and view feedback for