Search code examples
azurerestazure-application-insights

Application Insights REST API doesn't return rows


I use this endpoint to query data from my App insight The problem is, it always returns empty rows i.e. "rows": [].

{
  "tables": [
    {
      "name": "PrimaryResult",
      "columns": [
        {
          "name": "timestamp",
          "type": "datetime"
        },
        {
          "name": "message",
          "type": "string"
        },
        {
          "name": "severityLevel",
          "type": "int"
        },
        ...
        {
          "name": "_ResourceId",
          "type": "string"
        }
      ],
      "rows": []
    }
  ]
}

I want to check if I am missing something. I use Nightingale for it, here are my values:

Method - POST
URL - https://api.applicationinsights.io/v1/apps/00000000-0000-0000-0000-000000000000/query
BODY - {
    "query": "traces | where timestamp <= ago(120m) | limit 10"
}
HEADERS - {"X-Api-Key": "0000000000000000000000000000000000000000"}

I tried changing my query, adding timespan, using GET, tried adding "Content-Type" or "charset" to headers. I also tried querying using OAuth 2.0 but still get response 200 but empty results. Here are some screenshots on how do it using OAuth enter image description here enter image description here enter image description here


Solution

  • I found out why it works for others but not for me. My Application Insights resource is workspace-based and this fact seeming prevents you from reading data straight from app insights. I tried creating one using "standalone" setup and it works.

    So, in order to query data from workspace-based app insights, I need to send queries to the related workspace and then, inside the query, specify the actual app insights I need, like this:

    METHOD - POST
    URL - https://api.loganalytics.io/v1/workspaces/workspace_id/query
    AUTH - OAuth 2.0
    BODY - {
      "query": "app('app001_test').traces",
      "timespan": "PT24H"
    }