Forum Discussion
To get Power BI API Access Token dynamically, make sure to do this
- Anonymous2 years ago
Hi uahmed114pbi
Thank you for your sharing. I think we can try code as below to get access token in Power Query Editor. Then use this token as parameter when you get data by REST API. Access token will refresh new each time you refresh your report.
- Get Access token in Power BI Desktop:
() => let body = "client_id=" & #"App ID" & "&scope=https://analysis.windows.net/powerbi/api/.default&client_secret=" & #"App Secret" & "&grant_type=client_credentials", Data= Json.Document(Web.Contents("https://login.microsoftonline.com/"& TenantID & "/oauth2/v2.0/token/", [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])), access_token = Data[access_token] in access_token
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi uahmed114pbi
Thank you for your sharing. I think we can try code as below to get access token in Power Query Editor. Then use this token as parameter when you get data by REST API. Access token will refresh new each time you refresh your report.
- Get Access token in Power BI Desktop:
() =>
let
body = "client_id=" & #"App ID"
& "&scope=https://analysis.windows.net/powerbi/api/.default&client_secret=" & #"App Secret"
& "&grant_type=client_credentials",
Data= Json.Document(Web.Contents("https://login.microsoftonline.com/"& TenantID & "/oauth2/v2.0/token/",
[Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),
access_token = Data[access_token]
in
access_token
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- MargaritaGG1 year agoNew Member
Hi,
In my case App registration was done not by me, but Tenant.ReadAll is enabled (so as I understand would need to request to disable that) -- what access should be left?
I tried using this in Power Query (I have MFA enabled account) and I get this (does not let me to proceed with anonymous)Can you please advise?