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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Unable to send POST request in Web.Contents

Hi,

I need to retrieve employee data from an API that's only accessible to authorized users. First, I send a POST request using client credentials to obtain a bearer token and then it can access the employee API with this token. This process works smoothly on Power BI Desktop. However, once I publish the report to Power BI Service, the access token request becomes a GET request, resulting in a "Method Not Allowed" error with response code 405. 

 

This is the error I have encountered.

Kaveesha_Silva_0-1678364630307.png

 

 

Failed to update data source credentials: Web.Contents failed to get contents from 'https://a95a-123-231-56-85.in.ngrok.io/oauth/issueToken' (405): Method Not AllowedHide details
Activity ID:	56d0cb6a-3c96-4b10-8ae5-1de4fc1cd8e8
Request ID:	43940e4e-6384-e9ab-7d05-54e2ad842885
Status code:	400
Time:	Thu Mar 09 2023 15:35:33 GMT+0530 (India Standard Time)
Service version:	13.0.20195.63
Client version:	2302.4.12605-train
Cluster URI:	https://wabi-uk-south-c-primary-redirect.analysis.windows.net/

 

 

 

This is the Power Query code

 

 

let
    baseUrl = [base_url],
    client_secret = [client_secret],
    Source  = Json.Document(Web.Contents(baseUrl&"/oauth/issueToken",
        [ 
          Headers = [#"Content-Type"="application/json"],
          Content=Json.FromValue([
            grant_type = "client_credentials",
            client_id = "powerbi_client",
            client_secret = client_secret
          ])
        ]
    )),

    token = Source[access_token],

    data= Json.Document(Web.Contents(baseUrl&"/api/employees",
      [ 
        Headers = [#"Authorization"="Bearer "&token]
      ]
    )),
    data1 = data[data],
    #"Converted to Table" = Table.FromList(data1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"empNumber", "firstName", "lastName", "middleName", "termination_id", "employeeId", "joinedDate", "deletedEmployee"}, {"empNumber", "firstName", "lastName", "middleName", "termination_id", "employeeId", "joinedDate", "deletedEmployee"})
in
    #"Expanded Column1"

 

 

 

According to the documentation, "Content" specifies that the web request should be changed from a GET to a POST, with the value of the option being used as the content of the POST request. As I have mentioned earlier, this is working fine in Power BI Desktop, but not in the Power BI Service as expected.

 

What’s the issue here? Any issue with my script?

 

 

 

 

 

 

3 REPLIES 3
lgtkaushalya
Regular Visitor

Thanks for the quick reply Chirs. Here we are not really trying to get the full OAuth2 flow implemented. The main issue here is why the POST request works properly in PowerBI Desktop but converts into a GET in Power BI Connect(Cloud). We removed all the dynamic parts and tried to hard code the values to see whether the issues are due to dynamic params. Still no luck.

Anonymous
Not applicable

Hi @lgtkaushalya. Were you able to resolve this issue? I have recently run into the same problem. If you have, would you be able to tell me how it was resolved?

cpwebb
Microsoft Employee
Microsoft Employee

For more complex authentication flows (such as OAuth2) you need to build a custom connector, because the necessary functionality is only available there. See https://blog.crossjoin.co.uk/2021/08/29/connecting-to-rest-apis-with-oauth2-authentication-in-power-... for more details.

 

Chris

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors