How to query with a GET request? RRS feed

  • Question

  • I used to use Public API format in order to authenticate with AppId and ApiKey.

    Quite recently I had to authenticate with Azure Active Directory in order to query Application Insights.

    As I understood reading this when I use Azure Active Directory I have to use From what I've learned from this I need to compose a link:{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{componentName}/query/query?api-version={apiVersion}&query={newQuery}

    If I understand correctly the weird /query/query part is how I should interpret /{area}/[path].

    My query looks something like this:

    | where name =~ '{itemName}'
    | where timestamp > datetime('{referenceDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff")}')
    | project timestamp, id, name, success, customDimensions
    | order by timestamp desc
    | take 5

    I do remove the line breaks :-)

    I call the API this way:

    using (var client = new HttpClient())
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
        var response = client.GetAsync(url).Result;

    But I get Bad Request.

    I need to GET query Application Insights with AAD authentication (which I already solved, as without the line with Auth or with bad value I get Unauthorized). When registering the application in Azure Active Directory I was not given any options to add permissions than Data.Read - when using Post (different code than presented) I did get "Method Not Allowed".

    Please advise.


    I tried running the same query in Postman.

      "error": {
        "message": "The request had some invalid properties",
        "code": "BadArgumentError",
        "innererror": {
            "code": "SemanticError",
            "message": "A semantic error occurred.",
            "innererror": {
                "code": "SEM0100",
                "message": "'' operator: Failed to resolve table or column or scalar expression named 'requests'"

    Even when I shortened the query parameter to requests. So I guess I don't know how to pass a query in a GET API call.

    Thursday, October 10, 2019 9:27 PM


  • OK, know what is wrong.

    /query/query should be /api/query

    Api-Version should be 2014-12-01-preview

    That solved my problem.

    • Marked as answer by Klimcio Friday, October 11, 2019 10:28 AM
    Friday, October 11, 2019 10:28 AM