Quantcast
Channel: All Developer posts
Viewing all articles
Browse latest Browse all 49126

Re: Possible to update credentials via REST API?

$
0
0

Yes, I had to fight the code a bit but I got it working. This code allows me to update creds for connection to Azure SQL as required when doing DirectQuery.

 

static void UpdateAzureSqlDataSource(string workspaceCollectionName, string workspaceId, string datasetId) {
  using (var client = CreatePowerBIClient()) {
    IList<Dataset> datasets = client.Datasets.GetDatasetsAsync(workspaceCollectionName, workspaceId).Result.Value;
    foreach (Dataset dataset in datasets) {
      if (dataset.Name == datasetId) {
        var datasources = client.Datasets.GetGatewayDatasourcesAsync(workspaceCollectionName, workspaceId, dataset.Id).Result;
        // Reset your connection credentials
        var delta = new GatewayDatasource {
          CredentialType = "Basic",
          BasicCredentials = new BasicCredentials {
            Username = azureSqlUser,
            Password = azureSqlPassword
          }
        };
        // Update the datasource with the specified credentials
        client.Gateways.PatchDatasourceAsync(workspaceCollectionName, 
                                              workspaceId, 
                                              datasources.Value[0].GatewayId, 
                                              datasources.Value[0].Id,
                                              delta).Wait();
      }
    }
  }
}

The complete sample program is up in a GitHub report at this URL:

https://github.com/CriticalPathTraining/PowerBiEmbedded/blob/master/PBIEmbeddedDemo_Provisioning/PBIEmbeddedDemo_Provisioning/Program.cs

 


Viewing all articles
Browse latest Browse all 49126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>