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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello,
I am trying to retrieve the existing workspaces within my PBI Tenant. For this I have created a function like this:
() =>
let
body = "grant_type=Password&resource=https://analysis.windows.net/powerbi/api&client_id=98xxxxxxxx&client_secret=lBxxxxx&username=xxxxx@x...",
Data=Json.Document(Web.Contents("https://login.microsoftonline.com/common/oauth2/token/", [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
access_token = Data[access_token]
in
access_token.
Then I use this query to retrieve the data:
let
Source = Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/groups?$top=100", [Headers=[Authorization="Bearer "&GetAccessToken()]])),
value = Source[value],
#"Converted to Table" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "isReadOnly", "isOnDedicatedCapacity", "name"}, {"id", "isReadOnly", "isOnDedicatedCapacity", "name"})
in
#"Expanded Column1"
but I am receiving this error. Do you know which might be the cause? Thank you very much!!
An error occurred in the ‘’ query. 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/
Hi, @andra2
Can you test if you can get access token in postman?
You can check the doc:
Reference:Solved: Re: REST API Get Access Token - Microsoft Power BI Community
Handling authentication for Power Query connectors | Microsoft Docs
Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.
Best Regards,
Community Support Team _ Janey
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 39 | |
| 35 | |
| 33 | |
| 32 | |
| 27 |
| User | Count |
|---|---|
| 136 | |
| 96 | |
| 77 | |
| 67 | |
| 65 |