Sunday, February 27, 2022

Using Application Insights Rest API

Application Insights itself has great set of features that allows consumers to do many analysis on the application performance and monitoring. But there can be situations where you do need to find them located outside in external web applications. This is simplified by having support for different APIs and libraries to access Application Insights. In this article, we will focus on the REST API. 

Step 1: Aquire an API Access Key

Navigate to Application Insights instance and API Access tab on the left and Create an API Key. Make note of the 'Application ID' as it will be used in query string.

As our purpose is to read telemetry, we will opt just for that and generate the key. 

Step 2: Setup the Key

As this is an example attempt, I will use Postman to demonstrate the POST Request on REST Api. Next step will be to setup the authorization key as a header. You need to set the application ID in the url to construct the url. 


Step 3: Setup Request Body

This is the simplest step if you are familiar with querying Application Insights. You can specify the Kusto Query Language (KQL) syntax in the body and get the response. Also I have setup timespan as P1D, where it defines the duration of data to be queried from. 
In this example I have requested all requests,  but you can look for multiple filters by constructing a WHERE query as per KQL syntax.  








2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Have done the steps and get authenticated to the app service as well. However the rows array comes in empty even though there is data which I can see from the azure portal when I run the same KQL there. How do you resolve that?

    ReplyDelete