Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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...
  • PhilipTreacy's avatar
    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&region=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