Forum Discussion
Anonymous
5 years agoNot applicable
Invoking rest api post call in PowerBi
I am trying to invoke a post-call in PowerBi using a custom query but I'm facing an error The post-call gets converted to a get call and it throws an error. I tried using basic auth directly and also...
- 5 years ago
Hi Anonymous
You have the Content outside the Web.Contents call. It should be like this
let StartDate = Date.ToText(TimeStart,"yyyy-MM-ddTHH:ss:SSZ"), EndDate = Date.ToText(TimeEnd,"yyyy-MM-ddTHH:ss:SSZ"), auth_key ="Basic ZHNwX3JldGluZ191c2VyOk9DSXJlcG9ydHNAMjAyMA==", body = "{""tenantId"": "&tenancyName&",""granularity"": "&Duration&",""timeUsageStarted"": "&StartDate&",""timeUsageEnded"": "&EndDate&",""queryType"":"&CostType&",""groupBy"": ""[service]""}", Data = Web.Contents( "http://localhost:8080/costanalysis?profile=str109348123®ion=london", [ Headers = [#"Content-Type"="application/json", Authorization=auth_key], Content = Text.ToBinary(body) ] ), DataRecord = Json.Document(Data), Source = DataRecord in SourceBecause the Content was in the wrong place, Web.Contents was making GET requests rather than POST.
Regards
Phil
PhilipTreacy
5 years agoSuper User
Hi Anonymous
You have the Content outside the Web.Contents call. It should be like this
let
StartDate = Date.ToText(TimeStart,"yyyy-MM-ddTHH:ss:SSZ"),
EndDate = Date.ToText(TimeEnd,"yyyy-MM-ddTHH:ss:SSZ"),
auth_key ="Basic ZHNwX3JldGluZ191c2VyOk9DSXJlcG9ydHNAMjAyMA==",
body = "{""tenantId"": "&tenancyName&",""granularity"": "&Duration&",""timeUsageStarted"": "&StartDate&",""timeUsageEnded"": "&EndDate&",""queryType"":"&CostType&",""groupBy"": ""[service]""}",
Data = Web.Contents(
"http://localhost:8080/costanalysis?profile=str109348123®ion=london",
[
Headers = [#"Content-Type"="application/json", Authorization=auth_key],
Content = Text.ToBinary(body)
]
),
DataRecord = Json.Document(Data),
Source = DataRecord
in
Source
Because the Content was in the wrong place, Web.Contents was making GET requests rather than POST.
Regards
Phil
- Anonymous5 years agoNot applicable
When I publish this it throws an error saying anonymous call error but other calls work fine as they have data source by default as basic auth