1
votes

Is there is any proper example to use Azure Application Insights REST API using the Azure API and Azure Active Directory ?

1
Not sure want you mean. - Peter Bons
There are two methods are metioned int the api doc 1. API key authentication and 2. Azure Active Directory authentication but there is no example for the second method. i facing api rate limit issue with first method so i want to use second method - Navneet Garg
Can you provide me the link to that doc? - Peter Bons

1 Answers

2
votes

There are examples of using both ways, API keys and Azure AAD at the top level page:

https://dev.applicationinsights.io/documentation/Authorization

Using the Public API format: API key authentication

https://api.applicationinsights.io/{api-version}/{app-id}/{query-path}?[query-parameters]

https://dev.applicationinsights.io/documentation/Authorization/API-key-authentication

Using the Azure API format: user authentication

If you are using the Azure API format, then the authorization is done by Azure Active Directory. You can learn more about specific AAD authentication scenarios if you are using this to do per-user authentication.

A useful resource for how to use AAD authentication is the Developer's Guide to Auth with Azure Resource Manager API, and this site also has a useful set of PowerShell cmdlets to handle the details of authenticating against AAD and sending an API call via ARM. They are a quick way to get a targeted set of Fiddler sessions showing the actual calls to authenticate and call our APIs via ARM (vs API keys direct to the API).

For example, this sequence of PowerShell commands would run an Analytics query and dump out the JSON response:

Connect-ARM
Execute-ARMQuery -SubscriptionId {subscription-id} -HTTPVerb GET -Base "/subscriptions/{subscription-id}/resourcegroups/{resource-group-name}/providers/microsoft.insights/components/{ai-component-name}/api/query" -APIVersion "2014-12-01-preview" -Query "&query=requests|count" | ConvertTo-Json -Depth 99