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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
SumanthSai
New Member

Refresh PowerBI DataSet with RestAPI with msal authentication gives error as datasource cred missing

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")

 

 

2 REPLIES 2
SumanthSai
New Member

Hi @aj1973 

 

Yes the account is added to workspace as member to the workspace 

 

aj1973
Community Champion
Community Champion

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.