Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not 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 by passing it in headers any advice or help is appreciated and thank you in advance.

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

 

 

This is the error in Bi

 

 

DataSource.Error: Web.Contents failed to get contents from 'http://localhost:8080/costanalysis?profile=str109348123&region=london' (405😞 Details: DataSourceKind=Web DataSourcePath=http://localhost:8080/costanalysis Url=http://localhost:8080/costanalysis?profile=str109348123&region=london

 

 

This is the stack error in JAVA end

 

 

c.d.o.exception.GlobalExceptionHandler : Something went wrong.Error Message : Request method 'GET' not supported 2020-12-29 11:27:53.260 WARN 20696 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Failure in @ExceptionHandler com.dsp.oracle.exception.GlobalExceptionHandler#defaultErrorHandler(HttpServletRequest, Exception) 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super 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&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



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Thank you it worked

PhilipTreacy
Super User
Super 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&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



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not 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

amitchandak
Super User
Super User

@ImkeF , can you help on this.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
amitchandak
Super User
Super User

@Anonymous , For post method refer these two, if they can help, if not explored previously

https://community.powerbi.com/t5/Desktop/Pull-data-from-API-using-POST-method-in-Power-BI/td-p/574727

https://www.thebiccountant.com/2018/06/05/easy-post-requests-with-power-bi-and-power-query-using-json-fromvalue/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

I tried those but it didn't work. PowerBi still throws an error for basic auth or anonymous call either way the post gets converted to get by powerBi and authorization fails

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors