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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply

How do I send a POST Query using Power Query and extract the access token?

Hi,

 

I am trying to figure out how to send a POST Query using Power Query but running into some issues. I have some code here which does not work, and did manage to get a 400 error but I have edited it and can't remember what I put now :(.

 

let

// Define the POST Request.
Url = "https://sso.dynatrace.com/sso/oauth2/token",

Body = ([
grant_type = "client_credentials",
client_id = "xxxxxxx",
client_secret = "xxxx",
scope = "account-idm-read",
resource = "xxxxxxxxxx"]),

Source =
Web.Contents(
Url,
[
Headers=[#"Content-Type"="application/x-www-form-urlencoded"],
Content= Text.ToBinary(Body)
]


),
jsonResponse = Json.Document(Source)


in

jsonResponse

I am using this API here: Authentication for the Account Management API - Dynatrace Docs

 

A successful 200 response would give me an access_token variable in JSON representation. Any ideas? 

1 ACCEPTED SOLUTION
cpwebb
Microsoft Employee
Microsoft Employee

If you're trying to implement an OAuth2 authentication flow in Power Query you need to create a custom connector if you want to create something truly robust: https://blog.crossjoin.co.uk/2021/08/29/connecting-to-rest-apis-with-oauth2-authentication-in-power-...

View solution in original post

3 REPLIES 3
cpwebb
Microsoft Employee
Microsoft Employee

If you're trying to implement an OAuth2 authentication flow in Power Query you need to create a custom connector if you want to create something truly robust: https://blog.crossjoin.co.uk/2021/08/29/connecting-to-rest-apis-with-oauth2-authentication-in-power-...

Uzi2019
Community Champion
Community Champion

hi @dinosainsburys 


 GET requests are done by calling Web.Contents without a Content parameter, POST requests are done by calling Web.Contents with the parameter.

 

GET:

let
    URL = "http://xxx/tstat",
    headers = [#"Content-Type"="application/json"],
    web = Web.Contents(URL, [ Headers = headers, ManualStatusHandling = {404, 400}]),
    result = Json.Document(web),
...

 

POST:

let
    URL = "http://xxx/tstat",
    headers = [#"Content-Type"="application/json"],
    data = Json.FromValue([tmode = 2,t_cool = Setpoint,hold = 0]),
    web = Web.Contents(URL, [ Content = data, Headers = headers, ManualStatusHandling = {404, 400}]),
    result = Json.Document(web),
...

@dinosainsburys

Don't forget to give thumbs up and accept this as a solution if it helped you!!!
Uzi2019
Community Champion
Community Champion

Hi @dinosainsburys 

You can also refer below post for reference
https://blog.crossjoin.co.uk/2014/04/19/web-services-and-post-requests-in-power-query/

 

I hope I would resolved your issue!

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.