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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Kaveesha_Silva
Frequent Visitor

Unable to send a POST Request in Power Query

Hi,

 

I need to send a POST request to generate an access token in Power Query. In Power BI Desktop, a POST request is sent, and it works as expected. However, when I try to refresh after publishing the report to Power BI Service, a GET request is sent instead, resulting in a "Method Not Allowed" error, and a response code of 405.

This is the error I have encountered.

Kaveesha_Silva_0-1678436980064.png

This is the Power Query code I’m using

 

 

let
    base_url = [base_url],
    client_secret = [client_secret],
    Source  = Json.Document(Web.Contents(base_url&"/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],

 

 

I'm uncertain if the problem lies with the headers and content we are using. However, I was able to send the request successfully via Postman by setting the "Content-Type" to "application/json". What’s the issue here? Any issue with my script?

 

 

2 REPLIES 2
Poohkrd
Advocate I
Advocate I

Hi! Try this code:

let
    base_url = [base_url],
    client_secret = [client_secret],
    Source  = Json.Document(Web.Contents(base_url,
        [ 
          RelativePath = "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],

 

Thanks for the reply, seems it doesn't resolve the existing issue

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors