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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Get MS AAD access token

I am trying to get a Microsoft AAD access token using a Power Query:

 

 

let
     url = "https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token",
    
     body  = "{ ""client_id"": ""<client_id>"",  ""client_secret"": ""<client_secret>"", ""grant_type"": ""client_credentials"", ""scope"":""<scope>""}",
     options = [Headers = [#"Content-Type"="application/x-www-form-urlencoded"], Content = Text.ToBinary(body)],
     tokenResponse = Json.Document(Web.Contents(url,options)),
     AccessToken = tokenResponse[access_token],
     AccessTokenHeader = "Bearer " & AccessToken
 in
     AccessTokenHeader

 

 

 

I get the following error:

DataSource.Error: Fehler beim Abrufen von Inhalten von "https://login.microsoftonline.com/****************/oauth2/v2.0/token" (400) durch "Web.Contents": Bad Request

Need help please, can't find anything on the web.

 

2 REPLIES 2
sebMTW2022
New Member

I've the same issue , it works with another api with oauth2  for another system but not for microsoftlogin whereas it works in postman...

 

lbendlin
Super User
Super User

According to Chris Webb this will only work in custom connectors.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.