Skip to main content
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Frequent Visitor

Issues updating Snowflake credentials via the API

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, 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 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 




Source code:


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
                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):


    "credentialDetails": {
        "credentials": "{\"credentialData\":[{\"name\":\"username\",\"value\":\"REDACTED\"},{\"name\":\"password\",\"value\":\"REDACTED\"}]}",
        "credentialType": "Basic",
        "encryptedConnection": "NotEncrypted",
        "encryptionAlgorithm": "None",
        "privacyLevel": "None",
        "useCallerAADIdentity": false




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!

Community Support
Community Support

Hi @jjgray-sl ,


This issue should be caused by wrong data source credential.

Please check whether your have add the correct credential parameter into your code.

You can remove the failing data sources in data source setting, then add the correct credential into your gateway manually.

Here is a solved post with same issue like yours, you may refer to it to learn more details.

Solved: Failed to test the connection to your data source.... - Microsoft Power BI Community


Best Regards,
Rico Zhou


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-rzhou-msft,


I've checked the credentials in the code and they are correct. I am able to use them to manually configure the data source in the web UI.


Unfortunately manually adding credentials is not sufficient for my use-case. Ideally we would be using this endpoint to change the credentials.

Helpful resources

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.