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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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.

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.