<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unable to update datasource credentials using ProcessHttpRequestAsync in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-datasource-credentials-using/m-p/639069#M18724</link>
    <description>&lt;P&gt;So found another thread where person was using and instance of "UpdateDataSourceRequst" and "UpdateDataSourceAsync" to update credentials, see code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; var updateDataSourceRequest = new UpdateDatasourceRequest();
                    updateDataSourceRequest.CredentialDetails = new CredentialDetails();
                    updateDataSourceRequest.CredentialDetails.CredentialType = "Basic";
                    updateDataSourceRequest.CredentialDetails.Credentials = "{\"credentialData\":[{\"name\":\"username\", \"value\":\"MYUSER\"},{\"name\":\"password\", \"value\":\"MYPASSWORD\"}]}";                    
                    updateDataSourceRequest.CredentialDetails.EncryptedConnection = "Encrypted";
                    updateDataSourceRequest.CredentialDetails.EncryptionAlgorithm = "None";
                    updateDataSourceRequest.CredentialDetails.PrivacyLevel = "None";


                    var result = await client.Gateways.UpdateDatasourceAsync(datasetSource.Value[0].GatewayId, datasetSource.Value[0].DatasourceId, updateDataSourceRequest);&lt;/PRE&gt;&lt;P&gt;This atleast responds with a bad request! assuming its the "credentials" string, i have searched and searched but, found nothing on how i create that string....... Anyone?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Mar 2019 08:57:05 GMT</pubDate>
    <dc:creator>dahund</dc:creator>
    <dc:date>2019-03-07T08:57:05Z</dc:date>
    <item>
      <title>Unable to update datasource credentials using ProcessHttpRequestAsync</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-datasource-credentials-using/m-p/638609#M18716</link>
      <description>&lt;P&gt;Hey Followed another thread in this forum to build a DLL (C#) that will help updating SQL credentials on datasets, code dosnt return any error, but is not processed as PowerBI dashboard will not update, any help would be appricated?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public async Task&amp;lt;bool&amp;gt; UpdateSQLDatasource(string gatewayId, string datasourceID, string sqluser, string sqlPassword)
        {
            var getCredentialsResult = await GetTokenCredentials();
            if (!getCredentialsResult)
            {
                // The error message set in GetTokenCredentials
                return false;
            }
            try
            {
                //Create PowerBI Client
                using (var client = new PowerBIClient(new Uri(_ApiUrl), m_tokenCredentials))
                {    
                    var request = new System.Net.Http.HttpRequestMessage(
                        new HttpMethod("PATCH"),
                        $"https://api.powerbi.com/v1.0/myorg/gateways/{gatewayId}/datasources/{datasourceID}");
                    request.Content = new StringContent(
                    $@" {{
                        'encryptedConnection': 'Encrypted',
                        'encryptionAlgorithm': 'RSA - OAEP',
                        'privacyLevel': 'Public',
                        'credentialType': 'Basic',
                        'basicCredentials': {{
                            'username': '{sqluser}',
                            'password': '{sqlPassword}'
                        }}
                    }}");
                    request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                    await client.Credentials.ProcessHttpRequestAsync(request, new CancellationToken());

                }

            }
            catch (Exception)
            {
            }
            return true;

        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Mar 2019 20:39:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-datasource-credentials-using/m-p/638609#M18716</guid>
      <dc:creator>dahund</dc:creator>
      <dc:date>2019-03-06T20:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update datasource credentials using ProcessHttpRequestAsync</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-datasource-credentials-using/m-p/639069#M18724</link>
      <description>&lt;P&gt;So found another thread where person was using and instance of "UpdateDataSourceRequst" and "UpdateDataSourceAsync" to update credentials, see code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; var updateDataSourceRequest = new UpdateDatasourceRequest();
                    updateDataSourceRequest.CredentialDetails = new CredentialDetails();
                    updateDataSourceRequest.CredentialDetails.CredentialType = "Basic";
                    updateDataSourceRequest.CredentialDetails.Credentials = "{\"credentialData\":[{\"name\":\"username\", \"value\":\"MYUSER\"},{\"name\":\"password\", \"value\":\"MYPASSWORD\"}]}";                    
                    updateDataSourceRequest.CredentialDetails.EncryptedConnection = "Encrypted";
                    updateDataSourceRequest.CredentialDetails.EncryptionAlgorithm = "None";
                    updateDataSourceRequest.CredentialDetails.PrivacyLevel = "None";


                    var result = await client.Gateways.UpdateDatasourceAsync(datasetSource.Value[0].GatewayId, datasetSource.Value[0].DatasourceId, updateDataSourceRequest);&lt;/PRE&gt;&lt;P&gt;This atleast responds with a bad request! assuming its the "credentials" string, i have searched and searched but, found nothing on how i create that string....... Anyone?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2019 08:57:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-datasource-credentials-using/m-p/639069#M18724</guid>
      <dc:creator>dahund</dc:creator>
      <dc:date>2019-03-07T08:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update datasource credentials using ProcessHttpRequestAsync</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-datasource-credentials-using/m-p/639234#M18727</link>
      <description>&lt;P&gt;!!!SOLVED!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So after almost giving in, I decided to test if I could reset password using Postman and a JSON body (&lt;FONT&gt;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/updatedatasource#basic_credentials_example" target="_blank" rel="noopener"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/updatedatasource#basic_credentials_example&lt;/A&gt;&lt;/FONT&gt;)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Postman replied with a msg telling me that the user was unatherized!!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Apparently PowerBI will test credentials against source and if not working will relply with "Bad request" ...........&amp;nbsp; &lt;/STRONG&gt;&lt;STRONG&gt;DAMM&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So tried resetting password on SQL server with new Password, then waited a couple of minutes (PowerBI) apparently need some time to realize its data source is broken. Once PowerBI complained about credential i used following method to update with success &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public async Task&amp;lt;bool&amp;gt; UpdateSQLDatasource(string gatewayId, string datasourceID, string sqluser, string sqlPassword)
        {
            var getCredentialsResult = await GetTokenCredentials();
            if (!getCredentialsResult)
            {
                // The error message set in GetTokenCredentials
                return false;
            }
            try
            {
                //Create PowerBI Client
                using (var client = new PowerBIClient(new Uri(_ApiUrl), m_tokenCredentials))
                {
                    var updateDataSourceRequest = new UpdateDatasourceRequest
                    {
                        CredentialDetails = new CredentialDetails
                        {
                            CredentialType = "Basic",
                            Credentials = "{\"credentialData\":[{\"name\":\"username\", \"value\":\"" + sqluser + "\"},{\"name\":\"password\", \"value\":\"" +sqlPassword+ "\"}]}",
                            EncryptedConnection = "Encrypted",
                            EncryptionAlgorithm = "None",
                            PrivacyLevel = "None"

                        }
                    };
                    var result = await client.Gateways.UpdateDatasourceAsync(gatewayId, datasourceID, updateDataSourceRequest);

                }

            }
            catch (Exception)
            {
            }
            return true;

        }&lt;/PRE&gt;&lt;P&gt;So if anyone else has issues, YOU CANNOT USE a dummy account......&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2019 11:19:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-datasource-credentials-using/m-p/639234#M18727</guid>
      <dc:creator>dahund</dc:creator>
      <dc:date>2019-03-07T11:19:26Z</dc:date>
    </item>
  </channel>
</rss>

