Forum Discussion

akarkal's avatar
akarkal
Frequent Visitor
4 years ago
Solved

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?

 

 

2 Replies