https://api.applicationinsights.io/v1/query I am using above endpoint to send a post request in powershell script and getting errors in below script.
# Set the ID of the Application Insights resource you want to query
$appId = "app id"
# Set the access token for the Application Insights resource
$accessToken = "access token"
# Encode the access token as a URL-safe string
$accessToken = [System.Uri]::EscapeDataString($accessToken)
# Set the query you want to execute
$query = "customEvents"
# Construct the request body for the Application Insights query endpoint
$requestBody = @{
appId = $appId
query = $query
} | ConvertTo-Json
# Execute the query and retrieve the results
$queryResponse = Invoke-WebRequest -Method POST -Uri "https://api.applicationinsights.io/v1/query" -Headers @{
"Authorization" = "Bearer $accessToken"
"Content-Type" = "application/json"
} -Body $requestBody
# Extract the results from the response
$results = $queryResponse.Content | ConvertFrom-Json
# Print the results
$results
ERROR :
Invoke-WebRequest : {"error":{"message":"The requested path does not exist","code":"PathNotFoundError","correlationId":"1e33e5cd-43a4-4108-b28d-0b0ef4c3942c"}}
At line:26 char:18
+ ... yResponse = Invoke-WebRequest -Method POST -Uri "https://api.applicat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
The access token i am generating through postman for testing purpose and it is correct. Query is just customevents, not sure what is the issue here.
Edit: 9 Jan 2023
Granted read permission like this api permission but getting below error
Invoke-WebRequest : {"error":{"message":"The provided credentials have insufficient access to perform the requested operation","code":"InsufficientAccessError","correlationId":