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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
jjgray-sl
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 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 

 

thumbnail_image001.png

 

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 ");
                    continue;
                }

                var req = new UpdateDatasourceRequest
                {
                    CredentialDetails = new CredentialDetails(
                        new BasicCredentials(_snowflakeConfig.Username, _snowflakeConfig.Password),
                        PrivacyLevel.None,
                        EncryptedConnection.NotEncrypted
                    )
                };

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

 

{
    "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!

2 REPLIES 2
v-rzhou-msft
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

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.