March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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.
Hi @Anonymous ,
Please reference the similar threads:
https://community.powerbi.com/t5/Developer/403-Error-when-trying-to-access-REST-API/td-p/296324
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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
20 | |
12 | |
11 | |
9 |
User | Count |
---|---|
46 | |
36 | |
24 | |
10 | |
10 |