Forum Discussion
Can connect to API from PBI Desktop but cannot complete CURL example for data binary element - Help!
- 3 years ago
I thought I was to use Example 2That'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}}}")
I did find the following while playing with the developer tab in firefox. I noticed it used --data-raw instead of --data-binary and more fields as referenced in the API docs I provided. I modified my M query as follows but still needs improvement.
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
],
filterJson = [
"userFilter" = false,
"": [
"page" = 0,
"size" = 50,
"query" = "investigation:id:* -status:Closed -category:job",
"sort" = {[{"field"="modified", "asc"=false}]},
"period" = {"by"="day", "fromValue"=7}
}
],
bodyText = Text.FromBinary(Json.FromValue(filterJson)),
// Create a custom request
request = Http.Request(url, [
Content = Text.ToBinary(bodyText), // Convert payload to binary
Headers = headers,
ManualStatusHandling = {404} // Handle 404 errors if needed
]),
// Make the API request using Web.Contents
response = Web.Contents(request),
// Handle response
jsonResponse = Json.Document(response)
in
jsonResponse
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}}}")