We're trying to use the Gateways - Update Datasource endpoint in the REST API (via the dotnet client). We're using this endpoint to add Snowflake credentials to the datasource. The datasource has just been copied from another workspace using TOM via the XMLA endpoint.
Unfortunately, the endpoint does not seem to work. The code runs without error, however when I check back at app.powerbi.com, the changes have not been made to the dataset and no connection can be made to the data in Snowflake.
Using a network inspection tool, we have been able to see that the HTTP PATCH call that the dotnet client makes returns with a 200 OK status. We're also confident that the credentials work, as we can add them manually through app.powerbi.com to the copied data source and it is able to successfully connect. When doing this through code, the website shows that there is an error with the credentials. The linked support article doesn't seem to cover the error we're seeing here
public async Task AddCredentialsToDataSources(string workspaceId, string datasetId)
using (PowerBIClient client = GetPowerBIClient())
// Not always necessary, but calling it guarantees that we will be able to perform all operations on the data source
await client.Datasets.TakeOverAsync(new Guid(workspaceId), datasetId);
var dataSources = (await client.Datasets.GetDatasourcesInGroupAsync(new Guid(workspaceId), datasetId)).Value;
foreach (var dataSource in dataSources)
if (dataSource.DatasourceType.ToLower() == "extension")
var datasourceId = dataSource.DatasourceId;
var gatewayId = dataSource.GatewayId;
if (!datasourceId.HasValue || !gatewayId.HasValue)
_logger.LogWarning("Found a datasource with missing datasource ID or gateway ID ");
var req = new UpdateDatasourceRequest
CredentialDetails = new CredentialDetails(
new BasicCredentials(_snowflakeConfig.Username, _snowflakeConfig.Password),
// The network call this creates returns a 200 OK status message, but fails to load the credentials at app.powerbi.com
await client.Gateways.UpdateDatasourceAsync(gatewayId.Value, datasourceId.Value, req);
The PATCH request body that the dotnet client is sending (recorded with network inspection tool and credentials redacted):
Once all of this has happened, the web UI shows that our service principal has configured the dataset.
Interestingly, after the code has ran, when we click the "Take over" button in the UI, the data source seems to be able to authenticate. We have been able to establish that this is using the same credentials as the original dataset we copied from (this was set up manually in the web UI with my user). We're not really sure why or how this is happening.
Any help or advice would be appreciated - thanks!