Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I deployed Power BI Dataset from Power BI desktop to Service and whenever i am trying to refresh the dataset with rest api using msal(Microsoft Autentication Library) authentication it was giving error as datasource credentials are missing and even i set up the datasource credentials it is throwing same error message. Datasource for the Dataset is Azure blob below is the Code snippet . Kindly provide any solution
Code:
import msal
import requests
# Add your credentials and other variables here
client_id = "YOUR_CLIENT_ID"
tenant_name = "YOUR_TENANT_NAME"
username = "YOUR_USERNAME"
password = "YOUR_PASSWORD"
workspace_id = "YOUR_WORKSPACE_ID"
dataset_id = "YOUR_DATASET_ID"
authority_url = "https://login.microsoftonline.com/" + tenant_name
scope = ["https://analysis.windows.net/powerbi/api/.default"]
# URLs for API endpoints
url = f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/Default.UpdateDataSou..."
url_refresh = f"https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/refreshes"
url_update_refresh = f"https://api.powerbi.com/v1.0/myorg/datasets/{dataset_id}/refreshSchedule"
# Authenticate and get access token
app = msal.PublicClientApplication(client_id, authority=authority_url)
result = app.acquire_token_by_username_password(username, password, scopes=scope)
if 'access_token' in result:
access_token = result['access_token']
header = {'Content-Type': 'application/json', 'Authorization': f'Bearer {access_token}'}
# Example payload for updating data source credentials
datasource_payload = {
"updateDetails": [
{
"datasourceSelector": {
"datasourceType": "Sql",
"connectionDetails": {
"server": "YOUR_SQL_SERVER",
"database": "YOUR_DATABASE_NAME"
}
},
"credentialDetails": {
"credentialType": "Basic",
"basicCredentials": {
"username": "YOUR_DB_USERNAME",
"password": "YOUR_DB_PASSWORD"
}
}
}
]
}
# Update data source credentials
datasource_response = requests.post(url=url, headers=header, json=datasource_payload)
print("Datasource Update API Response:", datasource_response.json())
# Refresh the dataset
refresh_response = requests.post(url=url_refresh, headers=header)
print("Refresh Dataset API Response:", refresh_response.json())
# Set up refresh schedule
refresh_schedule_payload = {
"value": {
"days": ["Monday"],
"times": ["12:00"],
"localTimeZoneId": "UTC",
"enabled": True
}
}
refresh_schedule_response = requests.patch(url=url_update_refresh, headers=header, json=refresh_schedule_payload)
print("Refresh Schedule API Response:", refresh_schedule_response.json())
else:
print("Failed to obtain access token")
Hi @SumanthSai
Is the account added to the workspace where the dataset is located? It needs to be added as a member
Regards
Amine Jerbi
If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook
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 |
---|---|
48 | |
31 | |
27 | |
27 | |
26 |
User | Count |
---|---|
61 | |
56 | |
35 | |
29 | |
28 |