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
akarkal
Frequent Visitor

Update DataSet Credentials using Service Principal

- I have a dataset that is setup to load data from Azure Storage

- I recently switched to using Service Principal.  

       - I am trying the below code after taking ownership of the dataset

       - tenant settings has the toggle enabled for service principal to access admin apis

       - service principal is the admin of the workspace (groupId) used below

- There are no gateways configured as all the data is in azure.

- However when I use access the dataset using C# nuget package, the gatewayId on datasource is populated.

 var datasources = powerbiClient.Datasets
                .GetDatasourcesInGroup(groupId, dataSetId.ToString()).First();
Assert.NotNull(datasource.GatewayId.Value)

 

the only way I found to update a datasource was 

var credentials = new CredentialDetails(
                @"{""credentialData"":[{""name"":""accessToken"", ""value"":""" + accessToken + @"""}]}",
                CredentialType.Anonymous,
                EncryptedConnection.NotEncrypted,
                EncryptionAlgorithm.None,
                PrivacyLevel.None
            );
   powerbiClient.Gateways
.UpdateDatasource(datasource.GatewayId.Value, dataSetId, new UpdateDatasourceRequest(credentials));

However I get error that the action is unauthorized. 

I don't see any gateways in app.powerbi.com (not as admin) and I get empty result when I get all gateways

 

 

How do I update credentials of data set that the Service Principal is the owner of?

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @akarkal ,

First, please review the following links to check if you have missed any necessary step.

Refresh a Power BI Dataset with PowerShell and a Service Principal

The Tenant Management Application for Power BI

Just for example,

  1.  Allow service principals to use Power BI APIs in Admin PortalAllow service principals to use Power BI APIsAllow service principals to use Power BI APIs
  2.  Add the Service Principal as an Admin to the workspaceAdd the Service Principal as an Admin to the workspaceAdd the Service Principal as an Admin to the workspace

Then verify if you are experiencing a problem similar to the one in the posts below. If so, you can refer to the solution to solve your problem.

How to update Azure SQL datasource credentials of PowerBI dataset programmatically?

yingyinr_2-1639642729524.png

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @akarkal ,

Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem with you. Thank you.

Best Regards

Anonymous
Not applicable

Hi @akarkal ,

First, please review the following links to check if you have missed any necessary step.

Refresh a Power BI Dataset with PowerShell and a Service Principal

The Tenant Management Application for Power BI

Just for example,

  1.  Allow service principals to use Power BI APIs in Admin PortalAllow service principals to use Power BI APIsAllow service principals to use Power BI APIs
  2.  Add the Service Principal as an Admin to the workspaceAdd the Service Principal as an Admin to the workspaceAdd the Service Principal as an Admin to the workspace

Then verify if you are experiencing a problem similar to the one in the posts below. If so, you can refer to the solution to solve your problem.

How to update Azure SQL datasource credentials of PowerBI dataset programmatically?

yingyinr_2-1639642729524.png

Best Regards

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.