Run query¶
POST/
Live Discover API · Query Run
Run a saved EDR query or an ad hoc query on remote endpoints.
Parameters¶
| Name | In | Type | Required | Description |
|---|---|---|---|---|
X-Tenant-ID | header | string (uuid) | Yes | Tenant ID. |
Request body¶
Content type: application/json
Request body fields
savedQueryobjectSaved query to run. Required if an ad hoc query isn't supplied.
Show child attributesHide child attributes
categoryIdstring (uuid)(Optional) Query category ID.
queryIdstring (uuid)requiredSaved query ID.
adHocQueryobjectAd hoc query to run. Required if a saved query isn't supplied.
Show child attributesHide child attributes
namestring(Optional) Name for the ad hoc query.
Must be 1–300 characters long.
Must be 1–300 characters long.
templatestringrequiredSQL statement for the query. This can contain replacement variables wrapped in
Must be 15–50000 characters long.
$$ (double dollar sign) delimiters.Must be 15–50000 characters long.
variablesarray of objectValues of variables to be replaced in the template SQL.
Query variable.
Show child attributesHide child attributes
namestringrequiredVariable name.
Must be 1–100 characters long.
Must be 1–100 characters long.
dataTypestringrequiredData types supported for Live Discover queries.
Must be one of:
Must be one of:
double, integer, text, dateTime, boolean.valuestringString value of the variable.
Must be 1–5000 characters long.
Must be 1–5000 characters long.
pivotTypestringMeaning of an input parameter of a query.
Must be one of:
Must be one of:
deviceId, deviceName, sophosPid, ipAddress, username, sha256, filePath, registryKey, url.matchEndpointsobjectrequiredCriteria to select endpoints.
Show child attributesHide child attributes
allbooleanWhether to include all endpoints.
filtersarray of objectFilters to select specific endpoints. If present, must contain between one and five filter objects.
Must contain 1–5 items.
Must contain 1–5 items.
Find endpoints matching criteria.
Show child attributesHide child attributes
healthStatusarray of stringFind endpoints by health status.
Each item must be one of:
Each item must be one of:
good, suspicious, bad, unknown.typearray of stringFind endpoints by type.
Each item must be one of:
Each item must be one of:
computer, server, securityVm.tamperProtectionEnabledbooleanFind endpoints by whether Tamper Protection is turned on.
lockdownStatusarray of stringFind endpoints by lockdown status.
Each item must be one of:
Each item must be one of:
creatingWhitelist, installing, locked, notInstalled, registering, starting, stopping, unavailable, uninstalled, unlocked, locking.idsarray of string (uuid)Find endpoints with the specified IDs.
Must contain 1–1000 items.
Must contain 1–1000 items.
lastSeenBeforestringFind endpoints that were last seen before the given date and time (UTC) or a duration relative to the current date and time (exclusive).
lastSeenAfterstringFind endpoints that were last seen after the given date and time (UTC) or a duration relative to the current date and time (inclusive).
hostnameContainsstringFind endpoints where the hostname contains the given string.
associatedPersonContainsstringFind endpoints where the name of the person associated with the endpoint contains the specified string.
groupNameContainsstringFind endpoints where the name of the group the endpoint is in contains the given string. We are temporarily stopping support for
groupNameContains until further notice.osarray of objectMatches endpoints with any of the supplied operating system versions.
Matches where operating system platform, type, and version match.
Show child attributesHide child attributes
platformstringOS platform type.
Must be one of:
Must be one of:
windows, linux, macOS.typestringEndpoint type. Please note
Must be one of:
securityVm is deprecated and will be removed soon.Must be one of:
computer, server, securityVm.versionobjectSpecifies the criteria for a version match.
Show child attributesHide child attributes
matchstringExact version match. Takes precedence over 'from' and 'to' range options.
fromstringMatch versions greater than or equal to this value.
tostringMatch versions less or equal to this value.
ipAddressesarray of stringFind endpoints by IP addresses.
searchstringTerm to search for in the specified search fields.
searchFieldsarray of stringList of search fields for finding the given search term. Defaults to all applicable fields.
Each item must be one of:
Each item must be one of:
hostname, groupName, associatedPersonName, ipAddresses, osName.Request samples¶
curl -X POST "https://api-<data-region>.central.sophos.com/live-discover/v1/queries/runs" -H "Authorization: Bearer <access-token>" -H "X-Tenant-ID: <tenant-id>" -H "Content-Type: application/json" -d "{
\"savedQuery\": {
\"categoryId\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\",
\"queryId\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\"
},
\"variables\": [
{
\"name\": \"ExecutionName\",
\"dataType\": \"integer\",
\"value\": \"123\",
\"pivotType\": \"deviceId\"
}
],
\"matchEndpoints\": {
\"all\": false,
\"filters\": [
{
\"healthStatus\": [
\"good\"
],
\"type\": [
\"computer\"
],
\"tamperProtectionEnabled\": true,
\"lockdownStatus\": [
\"creatingWhitelist\"
],
\"ids\": [
\"3fa85f64-5717-4562-b3fc-2c963f66afa6\"
],
\"lastSeenBefore\": \"2020-05-13T21:00:01.000\",
\"hostnameContains\": \"example\",
\"associatedPersonContains\": \"person\",
\"groupNameContains\": \"group\",
\"os\": [
{
\"platform\": \"windows\",
\"type\": \"computer\",
\"version\": {
\"match\": \"10\"
}
}
],
\"ipAddresses\": [
\"10.50.100.100\"
],
\"search\": \"example\",
\"searchFields\": [
\"hostname\"
]
}
]
}
}"
import requests
response = requests.post(
"https://api-<data-region>.central.sophos.com/live-discover/v1/queries/runs",
headers={
"Authorization": "Bearer <access-token>",
"X-Tenant-ID": "<tenant-id>",
"Content-Type": "application/json",
},
json={ 'savedQuery': { 'categoryId': '3fa85f64-5717-4562-b3fc-2c963f66afa6',
'queryId': '3fa85f64-5717-4562-b3fc-2c963f66afa6'},
'variables': [ { 'name': 'ExecutionName',
'dataType': 'integer',
'value': '123',
'pivotType': 'deviceId'}],
'matchEndpoints': { 'all': False,
'filters': [ { 'healthStatus': ['good'],
'type': ['computer'],
'tamperProtectionEnabled': True,
'lockdownStatus': [ 'creatingWhitelist'],
'ids': [ '3fa85f64-5717-4562-b3fc-2c963f66afa6'],
'lastSeenBefore': '2020-05-13T21:00:01.000',
'hostnameContains': 'example',
'associatedPersonContains': 'person',
'groupNameContains': 'group',
'os': [ { 'platform': 'windows',
'type': 'computer',
'version': { 'match': '10'}}],
'ipAddresses': ['10.50.100.100'],
'search': 'example',
'searchFields': ['hostname']}]}},
)
print(response.json())
$headers = @{
"Authorization" = "Bearer <access-token>"
"X-Tenant-ID" = "<tenant-id>"
"Content-Type" = "application/json"
}
$body = '{
"savedQuery": {
"categoryId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"queryId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
},
"variables": [
{
"name": "ExecutionName",
"dataType": "integer",
"value": "123",
"pivotType": "deviceId"
}
],
"matchEndpoints": {
"all": false,
"filters": [
{
"healthStatus": [
"good"
],
"type": [
"computer"
],
"tamperProtectionEnabled": true,
"lockdownStatus": [
"creatingWhitelist"
],
"ids": [
"3fa85f64-5717-4562-b3fc-2c963f66afa6"
],
"lastSeenBefore": "2020-05-13T21:00:01.000",
"hostnameContains": "example",
"associatedPersonContains": "person",
"groupNameContains": "group",
"os": [
{
"platform": "windows",
"type": "computer",
"version": {
"match": "10"
}
}
],
"ipAddresses": [
"10.50.100.100"
],
"search": "example",
"searchFields": [
"hostname"
]
}
]
}
}'
Invoke-RestMethod -Method POST -Uri "https://api-<data-region>.central.sophos.com/live-discover/v1/queries/runs" -Headers $headers -Body $body -ContentType "application/json"
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
req, err := http.NewRequest("POST", "https://api-<data-region>.central.sophos.com/live-discover/v1/queries/runs", strings.NewReader(`{
"savedQuery": {
"categoryId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"queryId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
},
"variables": [
{
"name": "ExecutionName",
"dataType": "integer",
"value": "123",
"pivotType": "deviceId"
}
],
"matchEndpoints": {
"all": false,
"filters": [
{
"healthStatus": [
"good"
],
"type": [
"computer"
],
"tamperProtectionEnabled": true,
"lockdownStatus": [
"creatingWhitelist"
],
"ids": [
"3fa85f64-5717-4562-b3fc-2c963f66afa6"
],
"lastSeenBefore": "2020-05-13T21:00:01.000",
"hostnameContains": "example",
"associatedPersonContains": "person",
"groupNameContains": "group",
"os": [
{
"platform": "windows",
"type": "computer",
"version": {
"match": "10"
}
}
],
"ipAddresses": [
"10.50.100.100"
],
"search": "example",
"searchFields": [
"hostname"
]
}
]
}
}`))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer <access-token>")
req.Header.Set("X-Tenant-ID", "<tenant-id>")
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
const response = await fetch("https://api-<data-region>.central.sophos.com/live-discover/v1/queries/runs", {
method: "POST",
headers: {
"Authorization": "Bearer <access-token>",
"X-Tenant-ID": "<tenant-id>",
"Content-Type": "application/json",
},
body: JSON.stringify({
"savedQuery": {
"categoryId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"queryId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
},
"variables": [
{
"name": "ExecutionName",
"dataType": "integer",
"value": "123",
"pivotType": "deviceId"
}
],
"matchEndpoints": {
"all": false,
"filters": [
{
"healthStatus": [
"good"
],
"type": [
"computer"
],
"tamperProtectionEnabled": true,
"lockdownStatus": [
"creatingWhitelist"
],
"ids": [
"3fa85f64-5717-4562-b3fc-2c963f66afa6"
],
"lastSeenBefore": "2020-05-13T21:00:01.000",
"hostnameContains": "example",
"associatedPersonContains": "person",
"groupNameContains": "group",
"os": [
{
"platform": "windows",
"type": "computer",
"version": {
"match": "10"
}
}
],
"ipAddresses": [
"10.50.100.100"
],
"search": "example",
"searchFields": [
"hostname"
]
}
]
}
}),
});
const data = await response.json();
console.log(data);
Responses¶
201 — Query run created.¶
Response fields
idstring (uuid)requiredQuery run ID.
categoryobjectReference to a query category.
Show child attributesHide child attributes
idstring (uuid)requiredCategory ID.
namestringCategory name.
codestringIdentifier for category name. This is available only for pre-defined categories.
queryobjectShow child attributesHide child attributes
idstring (uuid)requiredQuery ID.
namestringQuery name.
codestringLocalization code of the query.
namestringrequiredQuery name.
templatestringrequiredQuery SQL template.
variablesarray of objectQuery template replacement variables.
Query variable.
Show child attributesHide child attributes
namestringrequiredVariable name.
Must be 1–100 characters long.
Must be 1–100 characters long.
dataTypestringrequiredData types supported for Live Discover queries.
Must be one of:
Must be one of:
double, integer, text, dateTime, boolean.valuestringString value of the variable.
Must be 1–5000 characters long.
Must be 1–5000 characters long.
pivotTypestringMeaning of an input parameter of a query.
Must be one of:
Must be one of:
deviceId, deviceName, sophosPid, ipAddress, username, sha256, filePath, registryKey, url.statusstringrequiredStatus of a query run.
Must be one of:
Must be one of:
pending, started, finished.resultstringrequiredOverall result of a query run.
Must be one of:
Must be one of:
notAvailable, succeeded, failed, timedOut.createdAtstring (datetime)When the query run was started.
createdByobjectPrincipal reference.
Show child attributesHide child attributes
idstring (uuid)requiredPrincipal ID. This is the client ID for service principals.
typestring (enum)requiredPrincipal type.
Must be one of:
Must be one of:
user, service.namestringPrincipal name. This doesn't apply to service principals.
accountTypestringAccount type.
Must be one of:
Must be one of:
partner, tenant, organization.finishedAtstring (datetime)When the query run completed.
maxDurationInSecondsintegerrequiredMaximum query duration allowed (in seconds) after which the query is terminated.
timeRemainingInSecondsintegerrequiredRemaining time in seconds.
performanceobjectOverall query performance metrics.
Show child attributesHide child attributes
scorestringLive Discover query performance score.
Must be one of:
Must be one of:
excellent, good, fair, poor, notEvaluated.dataTransferredInBytesobjectStatistics.
Show child attributesHide child attributes
totalintegerTotal value.
minintegerMin value.
maxintegerMax value.
medianintegerMedian value.
averageintegerAverage value.
executionTimeInMillisobjectStatistics.
Show child attributesHide child attributes
totalintegerTotal value.
minintegerMin value.
maxintegerMax value.
medianintegerMedian value.
averageintegerAverage value.
resultCountintegerCount of query run results collected.
matchEndpointsobjectrequiredCriteria to select endpoints.
Show child attributesHide child attributes
allbooleanWhether to include all endpoints.
filtersarray of objectFilters to select specific endpoints. If present, must contain between one and five filter objects.
Must contain 1–5 items.
Must contain 1–5 items.
Find endpoints matching criteria.
Show child attributesHide child attributes
healthStatusarray of stringFind endpoints by health status.
Each item must be one of:
Each item must be one of:
good, suspicious, bad, unknown.typearray of stringFind endpoints by type.
Each item must be one of:
Each item must be one of:
computer, server, securityVm.tamperProtectionEnabledbooleanFind endpoints by whether Tamper Protection is turned on.
lockdownStatusarray of stringFind endpoints by lockdown status.
Each item must be one of:
Each item must be one of:
creatingWhitelist, installing, locked, notInstalled, registering, starting, stopping, unavailable, uninstalled, unlocked, locking.idsarray of string (uuid)Find endpoints with the specified IDs.
Must contain 1–1000 items.
Must contain 1–1000 items.
lastSeenBeforestringFind endpoints that were last seen before the given date and time (UTC) or a duration relative to the current date and time (exclusive).
lastSeenAfterstringFind endpoints that were last seen after the given date and time (UTC) or a duration relative to the current date and time (inclusive).
hostnameContainsstringFind endpoints where the hostname contains the given string.
associatedPersonContainsstringFind endpoints where the name of the person associated with the endpoint contains the specified string.
groupNameContainsstringFind endpoints where the name of the group the endpoint is in contains the given string. We are temporarily stopping support for
groupNameContains until further notice.osarray of objectMatches endpoints with any of the supplied operating system versions.
Matches where operating system platform, type, and version match.
Show child attributesHide child attributes
platformstringOS platform type.
Must be one of:
Must be one of:
windows, linux, macOS.typestringEndpoint type. Please note
Must be one of:
securityVm is deprecated and will be removed soon.Must be one of:
computer, server, securityVm.versionobjectSpecifies the criteria for a version match.
Show child attributesHide child attributes
matchstringExact version match. Takes precedence over 'from' and 'to' range options.
fromstringMatch versions greater than or equal to this value.
tostringMatch versions less or equal to this value.
ipAddressesarray of stringFind endpoints by IP addresses.
searchstringTerm to search for in the specified search fields.
searchFieldsarray of stringList of search fields for finding the given search term. Defaults to all applicable fields.
Each item must be one of:
Each item must be one of:
hostname, groupName, associatedPersonName, ipAddresses, osName.endpointCountsobjectrequiredCount of endpoints grouped by various attributes.
Show child attributesHide child attributes
totalintegerTotal number of endpoints.
typesobjectNumber of endpoints of each type.
platformsobjectNumber of endpoints by platform.
statusesobjectCount of endpoints grouped by the status of the query running on each endpoint.
Show child attributesHide child attributes
pendingobjectCount of endpoints grouped by whether they are online or not.
Show child attributesHide child attributes
totalintegerTotal number of endpoints.
offlineintegerNumber of endpoints that are offline.
onlineintegerNumber of endpoints that are online.
startedobjectCount of endpoints by whether they have returned any data.
Show child attributesHide child attributes
totalintegerTotal number of endpoints.
withDataintegerNumber of endpoints that have returned some data.
withoutDataintegerNumber of endpoints that have returned no data.
finishedobjectCount of endpoints grouped by the result of the query run on each endpoint.
Show child attributesHide child attributes
succeededobjectCount of endpoints by whether they have returned any data.
Show child attributesHide child attributes
totalintegerTotal number of endpoints.
withDataintegerNumber of endpoints that have returned some data.
withoutDataintegerNumber of endpoints that have returned no data.
failedobjectCount of endpoints by whether they have returned any data.
Show child attributesHide child attributes
totalintegerTotal number of endpoints.
withDataintegerNumber of endpoints that have returned some data.
withoutDataintegerNumber of endpoints that have returned no data.
timedOutobjectCount of endpoints by whether they have returned any data.
Show child attributesHide child attributes
totalintegerTotal number of endpoints.
withDataintegerNumber of endpoints that have returned some data.
withoutDataintegerNumber of endpoints that have returned no data.
Errors¶
| Status | Meaning |
|---|---|
403 | Forbidden. |
404 | No resolved endpoints found. |
500 | Unexpected error. |
All error responses share the same shape — see the error response object.
Response examples¶
201¶
{
"id": "00000000-0000-0000-0000-000000000000",
"category": {
"id": "00000000-0000-0000-0000-000000000000",
"name": "string",
"code": "string"
},
"query": {
"id": "00000000-0000-0000-0000-000000000000",
"name": "string",
"code": "string"
},
"name": "string",
"template": "string",
"variables": [
{
"name": "string",
"dataType": "double",
"value": "string",
"pivotType": "deviceId"
}
],
"status": "pending",
"result": "notAvailable",
"createdAt": "string",
"createdBy": {
"id": "00000000-0000-0000-0000-000000000000",
"type": "user",
"name": "string",
"accountType": "partner"
},
"finishedAt": "string",
"maxDurationInSeconds": 0,
"timeRemainingInSeconds": 0,
"performance": {
"score": "excellent",
"dataTransferredInBytes": {
"total": 0,
"min": 0,
"max": 0,
"median": 0,
"average": 0
},
"executionTimeInMillis": {
"total": 0,
"min": 0,
"max": 0,
"median": 0,
"average": 0
}
},
"resultCount": 0,
"matchEndpoints": {
"all": false,
"filters": [
{
"healthStatus": [
"good"
],
"type": [
"computer"
],
"tamperProtectionEnabled": true,
"lockdownStatus": [
"creatingWhitelist"
],
"ids": [
"00000000-0000-0000-0000-000000000000"
],
"lastSeenBefore": "string",
"lastSeenAfter": "string",
"hostnameContains": "string",
"associatedPersonContains": "string",
"groupNameContains": "string",
"os": [
{
"platform": "windows",
"type": "computer",
"version": {
"match": "string",
"from": "string",
"to": "string"
}
}
],
"ipAddresses": [
"string"
],
"search": "string",
"searchFields": [
"hostname"
]
}
]
},
"endpointCounts": {
"total": 0,
"types": {},
"platforms": {},
"statuses": {
"pending": {
"total": 0,
"offline": 0,
"online": 0
},
"started": {
"total": 0,
"withData": 0,
"withoutData": 0
},
"finished": {
"succeeded": {
"total": 0,
"withData": 0,
"withoutData": 0
},
"failed": {
"total": 0,
"withData": 0,
"withoutData": 0
},
"timedOut": {
"total": 0,
"withData": 0,
"withoutData": 0
}
}
}
}
}
See the guide for a narrative walkthrough of this API.