Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi,
when using embedded "Try it" functionality on the following webpage, I am able to log in using my organizational account and generate a bearer token that can be used to access the PowerBI API.
Datasets - Update Refresh Schedule (Power BI Power BI REST APIs) | Microsoft Docs
While it is still valid, I am able to use the token obtained from the webpage above to programatically call the API via Python and the request library. I use this function for occasional maintenance, like updating the refresh schedule for a new dataset and similar.
My question is: how can I generate this bearer token programatically? I do not mind logging in via a GUI, as the target is occasional maintenance. I can for instance sign in to Azure using Vscode.
Thanks.
Hi @mrtn ,
See if it will help:
https://docs.microsoft.com/en-us/rest/api/power-bi/embedtoken/generatetoken
https://www.sqlshack.com/how-to-access-power-bi-rest-apis-programmatically/
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
I have in the meantime been able to achive my target by going through the following steps:
1) Create an "App registration" in the Azure portal
a) Within the "API permissions" tab add access to the PowerBI api. Add all necessary permissions
b) On the "Certificates and secrets" tab, create a client secret
2) Generate tokens with the following Python code
import msal
secret="XXXXXXXX"
app_identity="YYYYYYY"
tenant_ID="ZZZZZZZZ"
auth="https://login.microsoftonline.com/"+tenant_ID
client=msal.ConfidentialClientApplication(
app_identity, authority=auth,client_credential=secret)
scopes=['https://analysis.windows.net/powerbi/api/.default']
result = client.acquire_token_silent(scopes, account=None)
But I still wonder how the website linked in the original question is able to generate tokens without creating this intermediate application in Azure. Seems like an uncessary step.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 1 | |
| 1 | |
| 1 |