Run antivirus scan API

Applies to:

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

Note

If you are a US Government customer, please use the URIs listed in Microsoft Defender for Endpoint for US Government customers.

Tip

For better performance, you can use server closer to your geo location:

  • us.api.security.microsoft.com
  • eu.api.security.microsoft.com
  • uk.api.security.microsoft.com
  • au.api.security.microsoft.com
  • swa.api.security.microsoft.com
  • ina.api.security.microsoft.com

API description

Initiate Microsoft Defender Antivirus scan on a device.

Limitations

  1. Rate limitations for this API are 100 calls per minute and 1500 calls per hour.

Note

This page focuses on performing a machine action via API. See take response actions on a machine for more information about response actions functionality via Microsoft Defender for Endpoint.

Important

  • This action is available for devices on Windows 10, version 1709 or later, and on Windows 11.
  • A Microsoft Defender Antivirus scan can run alongside other antivirus solutions, whether Microsoft Defender Antivirus is the active antivirus solution or not. Microsoft Defender Antivirus can be in Passive mode. For more information, see Microsoft Defender Antivirus compatibility.

Permissions

One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Use Microsoft Defender for Endpoint APIs

Permission type Permission Permission display name
Application Machine.Scan 'Scan machine'
Delegated (work or school account) Machine.Scan 'Scan machine'

Note

When obtaining a token using user credentials:

  • The user needs to have at least the following role permission: 'Active remediation actions' (See Create and manage roles for more information)
  • The user needs to have access to the device, based on device group settings (See Create and manage device groups for more information)

Device group creation is supported in Defender for Endpoint Plan 1 and Plan 2.

HTTP request

POST https://api.security.microsoft.com/api/machines/{id}/runAntiVirusScan

Request headers

Name Type Description
Authorization String Bearer {token}. Required.
Content-Type string application/json

Request body

In the request body, supply a JSON object with the following parameters:

Parameter Type Description
Comment String Comment to associate with the action. Required.
ScanType String Defines the type of the Scan. Required.

ScanType controls the type of scan to perform and can be one of the following:

  • Quick: Perform quick scan on the device
  • Full: Perform full scan on the device

Response

If successful, this method returns 201, Created response code and MachineAction object in the response body.

If you send multiple API calls to run an antivirus scan for the same device, it returns "pending machine action" or HTTP 400 with the message "Action is already in progress".

Example

Request

Here is an example of the request.

POST https://api.security.microsoft.com/api/machines/1e5bc9d7e413ddd7902c2932e418702b84d0cc07/runAntiVirusScan 
{
  "Comment": "Check machine for viruses due to alert 3212",
  "ScanType": "Full"
}

Tip

Do you want to learn more? Engage with the Microsoft Security community in our Tech Community: Microsoft Defender for Endpoint Tech Community.