Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
Hello Folks,
I am completely new to the API calls and M code, please help me to resolve the access token refresh issue.
I am trying to create a function in Power BI query editor to refresh the access token for an API call and I get error saying
"DataSource.Error: Web.Contents failed to get contents from 'https://login.microsoftonline.com/common/oauth2/token/' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=https://login.microsoftonline.com/common/oauth2/token
Url=https://login.microsoftonline.com/common/oauth2/token/ "
below is the M code
let
body = "grant_type=password&resource=https://analysis.windows.net/powerbi/api&client_id=******&username=**@**.com&password=*****",
Data=Web.Contents("https://login.microsoftonline.com/common/oauth2/token/",
[
Headers=[#"Content-Type"="application/x-www-form-urlencoded"],
Content=Text.ToBinary(body)
])
in
Data
Can you please shed some light or help me out in fixing the above error.
Thank you
Hi @sqlguru448 ,
You could refer the topics which have the same issue.
https://community.powerbi.com/t5/Desktop/Bad-Request-in-Power-Query/m-p/20471
Best Regards,
Jay
Anybody, please help?
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 53 | |
| 52 | |
| 39 | |
| 15 | |
| 14 |
| User | Count |
|---|---|
| 94 | |
| 81 | |
| 34 | |
| 29 | |
| 25 |