Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi Team,
I am unable to use Python to refresh the Power Bi using REST API. Need quick help.
My code snippet is as below:
import requests
import json
import base64
# Set the API endpoint URL
url = "https://api.powerbi.com/v1.0/myorg/datasets/{dataset}/refreshes"
# Set the user ID and password
user_id = "my email ID"
password = "my password"
# Encode the user ID and password as base64
auth = base64.b64encode(f"{user_id}:{password}".encode()).decode()
# Set the request headers with the Content-Type and Authorization
headers = {
"Content-Type": "application/json",
"Authorization": f"Basic {auth}"
}
# Set the request payload
payload = {
"notifyOption": "NoNotification"
}
# Send the POST request with the headers and payload
response = requests.post(url, headers=headers, data=json.dumps(payload))
# Print the response
print(response)
I am getting option to enable read write datasets in delegated power bi service under tenant
SimpleBI not working
Hi. What's not working? I have just tried pip install and it's modules and are working. It's simplePbi with a P there. There is a typo there.
Regards
Happy to help!
Yes. I I was able to install the package. Let me explore now
I have followed all the steps shown in the simplpbi documentation and getting below error
HTTP Error: 401 Client Error: Unauthorized for url: https://api.powerbi.com/v1.0/myorg/admin/datasets
Text:
HTTP Error: 401 Client Error: Unauthorized for url: https://api.powerbi.com/v1.0/myorg/admin/groups/381c81c8-fd15-41bc-a0f0-af83bc716452/datasets
Text:
Are you a Power Bi Admin? You are using admin/groups/{group}/datasets. That will require a PowerBi Admin role for the user logged or the following configuration for service principal:
https://learn.microsoft.com/en-us/power-bi/enterprise/read-only-apis-service-principal-authenticatio...
Your first example was for datasets not for admin. For refreshing you don't need admin. You just need to be added at the workspace storing the dataset (the account or the service principal app). You can try get_datasets_in_group from datasets category to read them before using the refresh.
I hope that helps,
Happy to help!
Is it possible for you to connect on Teams meeting. My email ID is pradeep@smartinfopark.in
You are really very kind. Thank you so much
The idea would be keeping the issues/questions and answers at the forum so we can help others to find solution to similar situations.
You can continue asking our questions in here.
You can try something like:
from simplepbi import token
from simplepbi import admin
from simplepbi import datasets
# for login with user account
t = token.Token(TENANT_ID, power_bi_client_id, power_bi_username, power_bi_password, None, use_service_principal=False)
# for loging with service principal
t = token.Token(TENANT_ID, power_bi_client_id, None, None, power_bi_secret, use_service_principal=True)
# initialize datasets object
d = datasets.Datasets(t.token)
# read datasets in group
d.get_datasets_in_group(workspace_id)
# refresh datasets
d.refresh_dataset_in_group(workspace_id, dataset_id, notifyOption="NoNotification")
I hope that helps
Happy to help!
Now getting below error
HTTP Error: 401 Client Error: Unauthorized for url: https://api.powerbi.com/v1.0/myorg/groups/381c81c8-fd15-41bc-a0f0-af83bc716452/datasets
Text:
HTTP Error: 401 Client Error: Unauthorized for url: https://api.powerbi.com/v1.0/myorg/groups/381c81c8-fd15-41bc-a0f0-af83bc716452/datasets/70c35f2a-43f...
Text:
This is is API permissions screenshot
Let me try this and get back to you ASAP
Hi. The way to connect to PowerBi Rest API is using an App Registered at Azure Active Directory. You won't be able to get a valid token without an app id. You will be able to use a user account or service principal as login with the app registered. Once the app is created it will require permission for read and write dataset in order to use the refresh action. The first part of the following post shows how to do it with Service Principal ( generating a key to login with that instead of a user ). Read more: https://blog.ladataweb.com.ar/post/642023841877671936/azuredatafactory-actualizar-powerbi-con
You can use libraries for this. Like: https://pypi.org/project/SimplePBI/
That might guide you a little on how to write the code or register the app on azure to start working.
I hope that helps,
Happy to help!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
58 | |
30 | |
24 | |
23 | |
20 |
User | Count |
---|---|
51 | |
24 | |
20 | |
20 | |
17 |