Forum Discussion
Generating Access Token for Power BI REST API in Power BI Desktop
Hi DaniloSantosBRS,
Yes, it is possible to access Power BI REST APIs from Power BI Desktop and automate the generation of tokens to fetch data into the reports.
Getting an auth token from the "Try It" section in Microsoft Learn Documentation is a great way to fetch data and experiment with things in Power BI, but the generation of an auth token needs to be automated to refresh reports continuously.
In our organization, we are using PowerShell scripts that use App Registrations to connect to Power BI read-only admin APIs and fetch the necessary data in the form of JSON files, which are then imported into Power BI.
If you want to automate the generation of auth token in Power BI, I suggest that you could go through a few of the following links and see if you can implement the solution they suggest -
- https://pbi-guy.com/2023/03/25/connect-with-power-bi-to-the-power-bi-rest-api-with-a-service-principal/
- https://www.youtube.com/watch?v=2RZkc_qrV1g&t=603s&ab_channel=BIElite
- https://www.youtube.com/watch?v=N8qYRSqRz84&ab_channel=DhruvinShah
- https://community.fabric.microsoft.com/t5/Developer/To-get-Power-BI-API-Access-Token-dynamically-make-sure-to-do/m-p/3606448
I believe the above links should help you in implementing your desired solution. Let me know how it goes for you!
- DaniloSantosBRS2 years agoNew Member
Thank you for the assistance Bipin-Lala,
I followed the steps from the first link to generate the token, and it seems to have worked the same way; the function generates a token without errors.
The videos from the second and third links show how to authenticate using a username and password, but they're from 3 years ago. In the tests I conducted using this method, it didn't work; it returned a message related to authorization code. I believe this might be due to two-factor authentication, which prompts the user to access via a browser.In the fourth link, it shows how to obtain the token via client_credentials, which is similar to the first method, and this worked.
Perhaps the issue lies not in the code but in some permission or option that I should enable either in Azure or in Power BI. It's strange because I'm the account administrator; I should have all the privileges.
Implicit Grant and Hybrid Flows
Workspace administrator
My REST API on Azure
Permissions in Azure