REST APIがあり、フォームデータを含むPOSTリクエストのみを受け入れます。
PowerQueryではJSONリクエストは次のようになっています。
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
フォームデータを送信するにはどうすればよいですか?
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
ところで、body
をrecord
に直接構築し、テキスト文字列と二重引用符の二重引用符を避けた方がよいでしょう)
私はそれが機能するようにこのように使用しました、認証タイプは基本であり、エンコードされたユーザー名とパスワードです。
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"