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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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 @Anonymous
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
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!