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

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

Reply
capradeep1984
New Member

Power BI Dataset refresh through REST Api using Python

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)

12 REPLIES 12
capradeep84
Regular Visitor

I am getting option to enable read write datasets in delegated power bi service under tenant

capradeep84
Regular Visitor

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


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

Happy to help!

LaDataWeb Blog

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,


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

Happy to help!

LaDataWeb Blog

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


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

Happy to help!

LaDataWeb Blog

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

 

API_Permissions.png

Let me try this and get back to you ASAP

 

ibarrau
Super User
Super User

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,


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

Happy to help!

LaDataWeb Blog

Helpful resources

Announcements
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.