Forum Discussion

eyelikedata2's avatar
eyelikedata2
Helper I
3 years ago
Solved

Can connect to API from PBI Desktop but cannot complete CURL example for data binary element - Help!

Hello,

 

I have an API that I am able to connect to and are authorized, but I cannot seem to get the data binary part of the cURL example working. How do I enter something like this in PBI as my understanding is in the body, not header.

 

curl 'https://hostname:443/incidents/search' -H 'content-type: application/json' -H 'accept: application/json' -H 'Authorization: <API Key goes here>' --data-binary '{"filter":{"query":"-status:closed -category:job","period":{"by":"day","fromValue":7}}}' --compressed
  • lbendlin's avatar
    lbendlin
    3 years ago
    I thought I was to use Example 2

    That's my mistake, apologies.  Indeed I wanted you to look primarily at example 1 which shows both RelativePath and Query. But your sample curl script indicates that all filter parameters are in the POST body, so the Query part is not relevant (the RelativePath part is).

     

    You can convert the curl -d value into a Power Query Content value like this

    CURL:

    {"filter":{"query":"-status:closed -category:job","period":{"by":"day","fromValue":7}}}

    Power Query:

    Text.ToBinary("{""filter"":{""query"":""-status:closed -category:job"",""period"":{""by"":""day"",""fromValue"":7}}}")

     

9 Replies

  • Could I do something like this?

     

    Here is the new code:

    let
    body= [GrantType="**",Username="**",Password="***",ClientId="***",ClientSecret=""],
    Source = Json.Document(Web.Contents("https://****/token",
        [ 
         Headers=[#"Content-Type"="application/json"],
         Content= Json.FromValue(body)
        ]))
    in
        #"Source"
    • eyelikedata2's avatar
      eyelikedata2
      Helper I

      Here's what I came up with to connect Palo Alto Networks XSOAR formerly Demisto with Power BI based upon your example and the documentation at https://github.com/demisto/demisto-py/blob/master/docs/DefaultApi.md#search_incidents:

       

      let
      base_url = "https://hostname:443",
      api_key = "<Your API Key>",
      url = base_url & "/incidents/search",
      headers = [
      #"Content-Type" = "application/json",
      #"Accept" = "application/json",
      #"Authorization" = api_key
      ],
      filter = [
      "filter" = [
      "query" = "-status:closed -category:job",
      "period" = [
      "by" = "day",
      "fromValue" = 7
      ]
      ]
      ],
      body = Json.FromValue(filter),

      // Make the API request
      response = Web.Contents(
      url,
      [
      Headers = headers,
      Content = body,
      ManualStatusHandling = {404} // Handle 404 errors if needed
      ]
      ),

      // Handle response
      jsonResponse = Json.Document(response)
      in
      jsonResponse

       

      • eyelikedata2's avatar
        eyelikedata2
        Helper I

        I also found that I got an Invalid identifier error with "filter" highlighted. Hmm, maybe this will work?

         

        let
        base_url = "https://hostname:443",
        api_key = "<Your API Key>",
        url = base_url & "/incidents/search",
        headers = [
        #"Content-Type" = "application/json",
        #"Accept" = "application/json",
        #"Authorization" = api_key
        ],
        filterPayload = [
        "filter" = [
        "query" = "-status:closed -category:job",
        "period" = [
        "by" = "day",
        "fromValue" = 7
        ]
        ]
        ],
        body = Json.FromValue(filterPayload),

        // Make the API request
        response = Web.Contents(
        url,
        [
        Headers = headers,
        Content = body,
        ManualStatusHandling = {404} // Handle 404 errors if needed
        ]
        ),

        // Handle response
        jsonResponse = Json.Document(response)
        in
        jsonResponse