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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

PowerBi dataset refresh via API

Hi,

 

I am trying to write Python code to trigger PowerBi dataset refresh. I have followed the online resources and written the below code. But I am getting a "Resource 403" error when I run this script.

 

 

 

import requests, json
import urllib

token_url = "https://login.microsoftonline.com/<tenant id>/oauth2/token"

test_api_url = "https://api.powerbi.com/v1.0/myorg/datasets/<dataset id>/refreshes"

client_id = 'client id'
client_secret = 'client secret'

data = {'grant_type': 'client_credentials'}

access_token_response = requests.post(token_url, data=data, verify=False, allow_redirects=False, auth=(client_id, client_secret))

print(access_token_response.text)

tokens = json.loads(access_token_response.text)

api_call_headers = {'Authorization': 'Bearer ' + tokens['access_token'], 'Content-Length': '1025'}
api_call_response = requests.post(test_api_url, headers=api_call_headers)

print (api_call_response)

 

 

 

Could you please help me with this?

 

Thanks in advance.

1 REPLY 1
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

Please reference the similar threads:

https://community.powerbi.com/t5/Developer/Can-t-use-any-Power-BI-APIs-get-403-even-with-token/td-p/639548

https://community.powerbi.com/t5/Developer/403-Error-when-trying-to-access-REST-API/td-p/296324

https://community.powerbi.com/t5/Developer/403-Forbidden-error-occured-when-using-REST-API/td-p/71005

https://community.powerbi.com/t5/Developer/Power-BI-REST-API-gives-403-error-User-does-not-have-access-to/td-p/607049

https://community.powerbi.com/t5/Developer/Access-Power-BI-API-with-Python/td-p/189165

 

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.