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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
mamatha5195
Microsoft Employee
Microsoft Employee

Need help to update the default connection of semantic model automatically

I have deployed a semantic model in fabric workspace in import mode and when I try to refresh, it is giving an error "We cannot refresh this semantic model because this semantic model uses a default data connection without explicit connection credentials. Please replace the default data connection in the semantic model settings with an explicit cloud or gateway data connection.". I am able to refresh the model only if I update the cloud connection manually in settings. Is there any way we can automate this process of updating the connection using API's, if the required connection is already available in the workspace?

2 ACCEPTED SOLUTIONS
Akash_Varuna
Super User
Super User

Hi @mamatha5195 You will have to use the Power BI REST API endpoints with a Python script to handle updating the data source credentials. For automation, I think Power Automate or Azure Functions would be suitable to trigger the script periodically or based on events. 

View solution in original post

Hi @mamatha5195 ,
Thank you for the follow-up.I would be be happy to assist you!
At the moment, sempy.fabric does not support updating data source credentials or changing connections. It is mainly for querying and working with the semantic model itself , not managing its connections. So as mentioned earlier, the Power BI REST APIs are the only APIs currently available for that purpose.

I hope this helps.If so,consider accepting it as solution.

View solution in original post

5 REPLIES 5
v-pagayam-msft
Community Support
Community Support

Hi @mamatha5195 ,
Thank you @Akash_Varuna for the helpful response!
The error occurs because the semantic model uses a default connection without explicit credentials, which requires manual updating. To automate this, you have to use Power BI REST APIs as suggested by Akash. Then, use the PATCH /groups/{groupId}/datasets/{datasetId}/datasources API to update the data source.This process can be Python scripted . Make sure the caller has Contributor access.
Here is the API reference for more details. https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/update-datasources-in-group 

Thank you.

Regards,
Pallavi.

Can we achive this using sempy.fabric API's?

Hi @mamatha5195 ,
Thank you for the follow-up.I would be be happy to assist you!
At the moment, sempy.fabric does not support updating data source credentials or changing connections. It is mainly for querying and working with the semantic model itself , not managing its connections. So as mentioned earlier, the Power BI REST APIs are the only APIs currently available for that purpose.

I hope this helps.If so,consider accepting it as solution.

I am using below API to map the connection ID and recieving errors that the resource is not available in the URL. But for requests.get() I am able to get the existing datasource details. Please let me know if the API works for patch.

update_payload = {
"datasources": [
{
"datasourceId": datasource_id 
}
]
}

url = f"https://api.powerbi.com/v1.0/myorg/groups/{target_workspace_id}/datasets/{target_model_id}/datasourc..."
response = requests.patch(url, json=update_payload, headers=headers)

if response.status_code == 200:
print("Dataset successfully mapped to the specific connection.")
else:
print(f"Error: {response.status_code}")
print(response.json())

Akash_Varuna
Super User
Super User

Hi @mamatha5195 You will have to use the Power BI REST API endpoints with a Python script to handle updating the data source credentials. For automation, I think Power Automate or Azure Functions would be suitable to trigger the script periodically or based on events. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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