Forum Discussion
Power BI REST API Update datasource credentials
Hi,
Is it possible to use the Powerbi REST API to update the login credentials to a dataset?
I found something similar for gateway-managed dataset: https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/adddatasourceuser#example but all my dataset are on Azure Cloud (Azure SQL) so I can't use gateway.
Thank you!
- Anonymous6 years ago
HI ivanferr92,
I also check the rest API documents but not found any apis to direct operate the data source credentials. (some of API can update the connection strings but they not mention/contains any parameters to operate on data credentials)
I guess power bi service may not want to share them due to security reasons.Regards,
Xiaoxin Sheng
10 Replies
- AnonymousNot applicable
HI ivanferr92,
I also check the rest API documents but not found any apis to direct operate the data source credentials. (some of API can update the connection strings but they not mention/contains any parameters to operate on data credentials)
I guess power bi service may not want to share them due to security reasons.Regards,
Xiaoxin Sheng
- TedPattisonMicrosoft Employee
Are you looking for Power BI .NET SDK v3 code to update datasource credentials. Here is a code snippet.
public static void PatchSqlDatasourceCredentials(Guid WorkspaceId, string DatasetId, string UserName, string UserPassword) { PowerBIClient pbiClient = TokenManager.GetPowerBiClient(requiredScopes); var datasources = (pbiClient.Datasets.GetDatasourcesInGroup(WorkspaceId, DatasetId)).Value; // find the target SQL datasource foreach (var datasource in datasources) { if (datasource.DatasourceType.ToLower() == "sql") { // get the datasourceId and the gatewayId var datasourceId = datasource.DatasourceId; var gatewayId = datasource.GatewayId; // Create UpdateDatasourceRequest to update Azure SQL datasource credentials UpdateDatasourceRequest req = new UpdateDatasourceRequest { CredentialDetails = new CredentialDetails( new BasicCredentials(UserName, UserPassword), PrivacyLevel.None, EncryptedConnection.NotEncrypted) }; // Execute Patch command to update Azure SQL datasource credentials pbiClient.Gateways.UpdateDatasource((Guid)gatewayId, (Guid)datasourceId, req); } }; }Source code can be found here: https://github.com/TedPattison/DatasetManagement/blob/master/DatasetManagement/Models/PowerBiManager.cs
- paritoshmishraHelper I
above code throw "Operation returned an invalid status code 'Unauthorized' on "client.Gateways.UpdateDatasource" event thou I have given all powerBI API permission include Tenant.ReadWrite. I don't use the gateway, Is this the reason for the error?