Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
mrtn
Helper II
Helper II

Generate token for updating refresh schedule of a dataset

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.  

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

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.  

 

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.