Execute an Analytics query

Executes an Analytics query for data

HTTP request

GET /v1/workspaces/{workspaceId}/query

Security

Type Description
API key

Pass the API key 'DEMO_KEY' via an X-Api-Key custom header or an api_key query parameter. [More info about authorization]

Basic Auth

Use the API key 'DEMO_KEY' as either username or password with normal HTTP basic auth [More info about authorization]

Azure AAD Auth

Pass the AAD auth token in the 'Authorization' header. [More info about authorization]

URL parameters

Name Value Description
workspaceId string (uuid)

ID of the workspace. This is Workspace ID from the Properties blade in the Azure portal.

Query parameters

Name Value Description
query string

The Analytics query. Learn more about the Analytics query syntax

timespan string (interval)

Optional. The timespan over which to query data. This is an ISO8601 time period value. This timespan is applied in addition to any that are specified in the query expression.

prefer string

Optional. HTTP preferences that should be applied to the query

workspaces string (csv)

Comma separated workspace IDs to include in cross-workspace queries.

Responses

Status Code Description
200 OK. The API call succeeded and the Analytics query result is in the response payload
204 No Content. The {workspaceId} being queried has not yet been enabled for Analytics queries and populated with data
400 Bad Request. The request was invalid; can be caused by a bad API request body, or errors in the Analytics query in the request
401 Unauthorized. No authentication was provided; authenticate and re-issue the API call
403 Forbidden. Authentication was provided, but the caller did not have the necessary permissions
404 Not Found. The caller supplied an invalid {workspaceId}
429 Too Many Requests. The caller has exceeded the rate limits for the user/workspace
500 Internal Server Error. The service experienced an unexpected error while processing the request
502 Bad Gateway. A downstream service dependency experienced an internal service error while processing the request
503 Service Unavailable. A downstream service dependency was temporarily unavailable due to load or maintenance
504 Gateway Timeout. A downstream service dependency timed out while processing the request

Examples


A simple query that returns query results.

Parameters:

{
  "workspaceId": "63613592-b6f7-4c3d-a390-22ba13102111",
  "query": "Usage | take 10",
  "timespan": "PT12H",
  "prefer": "include-statistics=true,include-render=true"
}

Response:

{
  "headers": {
    "x-ms-request-id": "58a37988-2c05-427a-891f-5e0e1266fcc5",
    "x-ms-correlation-request-id": "58a37988-2c05-427a-891f-5e0e1266fcc5"
  },
  "body": {
    "tables": [
      {
        "name": "PrimaryResult",
        "columns": [
          {
            "name": "TenantId",
            "type": "string"
          },
          {
            "name": "Computer",
            "type": "string"
          },
          {
            "name": "TimeGenerated",
            "type": "datetime"
          },
          {
            "name": "SourceSystem",
            "type": "string"
          },
          {
            "name": "StartTime",
            "type": "datetime"
          },
          {
            "name": "EndTime",
            "type": "datetime"
          },
          {
            "name": "ResourceUri",
            "type": "string"
          },
          {
            "name": "LinkedResourceUri",
            "type": "string"
          },
          {
            "name": "DataType",
            "type": "string"
          },
          {
            "name": "Solution",
            "type": "string"
          },
          {
            "name": "BatchesWithinSla",
            "type": "long"
          },
          {
            "name": "BatchesOutsideSla",
            "type": "long"
          },
          {
            "name": "BatchesCapped",
            "type": "long"
          },
          {
            "name": "TotalBatches",
            "type": "long"
          },
          {
            "name": "AvgLatencyInSeconds",
            "type": "real"
          },
          {
            "name": "Quantity",
            "type": "real"
          },
          {
            "name": "QuantityUnit",
            "type": "string"
          },
          {
            "name": "IsBillable",
            "type": "bool"
          },
          {
            "name": "MeterId",
            "type": "string"
          },
          {
            "name": "LinkedMeterId",
            "type": "string"
          },
          {
            "name": "Type",
            "type": "string"
          }
        ],
        "rows": [
          [
            "b438b4f6-912a-46d5-9cb1-b44069212abc",
            "ContosoSQLSrv1",
            "2017-08-24T06:59:59Z",
            "OMS",
            "2017-08-24T06:00:00Z",
            "2017-08-24T06:59:59Z",
            "/subscriptions/e4272367-5645-4c4e-9c67-3b74b59a6982/resourcegroups/contosoazurehq/providers/microsoft.operationalinsights/workspaces/contosoretail-it",
            null,
            "Perf",
            "LogManagement",
            "1",
            "0",
            "0",
            "1",
            "1.286",
            "0.076408",
            "MBytes",
            "true",
            "a4e29a95-5b4c-408b-80e3-113f9410566e",
            "00000000-0000-0000-0000-000000000000",
            "Usage"
          ],
          [
            "b438b4f6-912a-46d5-9cb1-b44069212abc",
            "Store010Web3",
            "2017-08-24T06:59:59Z",
            "OMS",
            "2017-08-24T06:00:00Z",
            "2017-08-24T06:59:59Z",
            "/subscriptions/e4272367-5645-4c4e-9c67-3b74b59a6982/resourcegroups/contosoazurehq/providers/microsoft.operationalinsights/workspaces/contosoretail-it",
            null,
            "Perf",
            "LogManagement",
            "1",
            "0",
            "0",
            "1",
            "1.7",
            "0.106767",
            "MBytes",
            "true",
            "a4e29a95-5b4c-408b-80e3-113f9410566e",
            "00000000-0000-0000-0000-000000000000",
            "Usage"
          ]
        ]
      }
    ],
    "render": {
      "visualization": "table",
      "title": "",
      "accumulate": false,
      "isQuerySorted": false,
      "kind": "",
      "annotation": "",
      "by": null
    },
    "statistics": {
      "query": {
        "executionTime": 0.0156255,
        "resourceUsage": {
          "cache": {
            "memory": {
              "hits": 1061,
              "misses": 0,
              "total": 1061
            },
            "disk": {
              "hits": 0,
              "misses": 0,
              "total": 0
            }
          },
          "cpu": {
            "user": "00:00:00.0625000",
            "kernel": "00:00:00.0937500",
            "totalCpu": "00:00:00.1562500"
          },
          "memory": {
            "peakPerNode": 0
          }
        }
      }
    }
  }
}

A cross workspace query that the type and count of each row per workspace.

Parameters:

{
  "workspaceId": "63613592-b6f7-4c3d-a390-22ba13102111",
  "query": "union * | where TimeGenerated > ago(1h) | summarize count() by Type, TenantId",
  "workspaces": "draft-test,draft-test-2"
}

Response:

{
  "body": {
    "tables": [
      {
        "name": "PrimaryResult",
        "columns": [
          {
            "name": "Type",
            "type": "string"
          },
          {
            "name": "TenantId",
            "type": "string"
          },
          {
            "name": "count_",
            "type": "long"
          }
        ],
        "rows": [
          [
            "Usage",
            "63613592-b6f7-4c3d-a390-22ba13102111",
            "1"
          ],
          [
            "Usage",
            "d436f322-a9f4-4aad-9a7d-271fbf66001c",
            "1"
          ],
          [
            "BillingFact",
            "63613592-b6f7-4c3d-a390-22ba13102111",
            "1"
          ],
          [
            "BillingFact",
            "d436f322-a9f4-4aad-9a7d-271fbf66001c",
            "1"
          ],
          [
            "Operation",
            "63613592-b6f7-4c3d-a390-22ba13102111",
            "7"
          ],
          [
            "Operation",
            "d436f322-a9f4-4aad-9a7d-271fbf66001c",
            "5"
          ]
        ]
      }
    ]
  }
}