Web.Contents(url as text, optional options as nullable record) as binary引数 "options" を使ってリクエスト時に Content などを渡すとよい。そこで、Zabbix を使うことがあったので、Power Query + Zabbix API を試してみた。なお、Zabbix API は JSON-RPC というプロトコルなので、JSON 形式のパラメータを送信 / JSON 形式で結果を受信する。Content-Type は application/json-rpc。
例えば、Zabbix API のバージョンを得るためのリクエストは、
{
"jsonrpc": "2.0",
"method": "apiinfo.version",
"params": [],
"id": 1
}
こんな感じなので、Power Query ではlet
ZabbixServer = "http://Server/zabbix/api_jsonrpc.php",
RequerstJSON = Text.Format(
"{""jsonrpc"":""2.0"",""method"":""apiinfo.version"",""id"":#{0}}",
{Number.Round(Number.RandomBetween(1,9999))}
),
Options = [Headers = [#"Content-Type" = "application/json-rpc"],
Content = Text.ToBinary(RequerstJSON)],
Response = Web.Contents(ZabbixServer, Options),
ImportedJSON = try Json.Document(Response),
Result = if ImportedJSON[HasError]
then ImportedJSON[Error]
else if ImportedJSON[Value][id] = null
then ImportedJSON[Value][error]
else ImportedJSON[Value]
in
Result