I have a REST API, which accepts only POST requests with form data.
I know that in Power Query JSON requests are like this:
let
url = "https://example.com",
body = "{ ""first_param"": ""AAAAA"", ""second_param"": ""BBBBBB""}",
Source = Json.Document(Web.Contents(url,[ Headers = [#"Content-Type"="application/json"], Content = Text.ToBinary(body) ] ))
in
Source
How it is possible to send form data??
let
url = "https://example.com",
body = "{ ""first_param"": ""AAAAA"", ""second_param"": ""BBBBBB""}",
Parsed_JSON = Json.Document(body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
Source = Json.Document(Web.Contents(url,[Headers = [#"Content-Type"="application/json"], Content = Text.ToBinary(BuildQueryString) ] ))
in
Source
btw, you'd better construct body
directly into a record
, avoiding text string and double of double quotes )
I used this way it's working, Authorization type is Basic and encoded username and password.
let
url = "http://localhost:8091/_p/query/query/service?",
body = "{
""statement"": ""SELECT ROUND((SUM(src.DUR) / COUNT(.)), 0) AS 'Mean Screen Time per day' FROM \r\n(SELECT
SUM(TONUMBER(source.DURATION)) AS DUR, source.startDate AS DATE FROM \r\n(SELECT startDate, DATE_DIFF_STR(completionDate,
startDate, 'second') AS DURATION, attributes.screen AS SCREEN \r\nFROM data WHERE type_ = \""Event\"" AND type is NOT MISSING and
startDate IS NOT MISSING and completionDate IS NOT MISSING \r\nand completionDate > startDate and attributes.screen IS NOT
MISSING) source GROUP BY source.startDate) src"",
""pretty"":true,""timeout"":""600s"",""profile"":""timings"",""scan_consistency":"not bounded"",""client_context_id"":""xyz""}",
Source = Json.Document(Web.Contents(
url,[
Timeout=#duration(0,0,120,0),
Headers=[#"Authorization"="Basic YXB",#"Content-Type"="application/json"],
Content=Text.ToBinary(body)
]
)
),
results = Source[results],
#"Converted to Table" = Table.FromList(results, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"MEAN _DURATION", "SCREEN"},{"MEAN DURATION","SCREEN"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1",{{"MEAN_DURATION", type number}})
in
#"Changed Type"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With