<?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: Update Credentials C# in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credentials-C/m-p/271635#M8216</link>
    <description>&lt;P&gt;There is currently some issue with V2&amp;nbsp;client.Gateways.UpdateDatasourceAsync&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The body which is sent using that method:&lt;/P&gt;&lt;PRE&gt;{
  "credentialDetails": {
    "credentials": "{\"credentialType\":\"Basic\",\"basicCredentials\":{\"username\":\"usrnmame\",\"password\":\"password\"}}"
  }
}&lt;/PRE&gt;&lt;P&gt;where the correct one should be:&lt;/P&gt;&lt;PRE&gt;{
"credentialType":"Basic",
"basicCredentials":{"username":"usrname","password":"password"}
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Simple http request as pointed above will work just fine:)&lt;/P&gt;</description>
    <pubDate>Sat, 07 Oct 2017 12:04:23 GMT</pubDate>
    <dc:creator>nicksav</dc:creator>
    <dc:date>2017-10-07T12:04:23Z</dc:date>
    <item>
      <title>Update Credentials C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credentials-C/m-p/258192#M7965</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;following the instructions given in this post:&amp;nbsp;&lt;A href="http://community.powerbi.com/t5/Developer/How-do-I-update-the-Credentials-after-I-upload-a-report-to-POWER/td-p/223243" target="_blank"&gt;http://community.powerbi.com/t5/Developer/How-do-I-update-the-Credentials-after-I-upload-a-report-to-POWER/td-p/223243&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ended up with the following snippet:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;                    var gateway = (await m_powerBIClient.Gateways.GetGatewayByIdWithHttpMessagesAsync (datasource.GatewayId,
                        cancellationToken: cancellationToken)).Body;
                    var credentials = AsymmetricKeyEncryptionHelper.EncodeCredentials (username, password, gateway.PublicKey.Exponent, gateway.PublicKey.Modulus);
                    var response = await m_powerBIClient.Gateways.UpdateDatasourceWithHttpMessagesAsync (
                        gateway.Id,
                        datasource.Id,
                        new UpdateDatasourceRequest (
                            new CredentialDetails (
                                credentials,
                                credentialType: "Basic",
                                encryptedConnection: "Encrypted",
                                encryptionAlgorithm: "RSA-OAEP",
                                privacyLevel: "Public"
                                )
                            ),
                        cancellationToken: cancellationToken);&lt;/PRE&gt;&lt;P&gt;But this leads to an internal server error. Do you know what is the missing part to get it running?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 07:30:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credentials-C/m-p/258192#M7965</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-09-25T07:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credentials C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credentials-C/m-p/258872#M7987</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;following the instructions given in this post:&amp;nbsp;&lt;A href="http://community.powerbi.com/t5/Developer/How-do-I-update-the-Credentials-after-I-upload-a-report-to-POWER/td-p/223243" target="_blank"&gt;http://community.powerbi.com/t5/Developer/How-do-I-update-the-Credentials-after-I-upload-a-report-to-POWER/td-p/223243&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ended up with the following snippet:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;                    var gateway = (await m_powerBIClient.Gateways.GetGatewayByIdWithHttpMessagesAsync (datasource.GatewayId,
                        cancellationToken: cancellationToken)).Body;
                    var credentials = AsymmetricKeyEncryptionHelper.EncodeCredentials (username, password, gateway.PublicKey.Exponent, gateway.PublicKey.Modulus);
                    var response = await m_powerBIClient.Gateways.UpdateDatasourceWithHttpMessagesAsync (
                        gateway.Id,
                        datasource.Id,
                        new UpdateDatasourceRequest (
                            new CredentialDetails (
                                credentials,
                                credentialType: "Basic",
                                encryptedConnection: "Encrypted",
                                encryptionAlgorithm: "RSA-OAEP",
                                privacyLevel: "Public"
                                )
                            ),
                        cancellationToken: cancellationToken);&lt;/PRE&gt;
&lt;P&gt;But this leads to an internal server error. Do you know what is the missing part to get it running?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;@Anonymous&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The code demo in &lt;A href="https://community.powerbi.com/t5/Developer/How-do-I-update-the-Credentials-after-I-upload-a-report-to-POWER/td-p/223243" target="_self"&gt;this thread&lt;/A&gt; indeed works in my test when updating a datasource for a specific gateway. To have better troubleshooting, please add try..catch block to get the detailed error message for your code.&lt;/P&gt;
&lt;PRE&gt;try{

//your code here

}
catch (HttpOperationException ex)
               { 
                    //Bad Request
                    var content = ex.Response.Content; 
                    Console.WriteLine(content);
 }&lt;/PRE&gt;
&lt;P&gt;By the way, have you debugged the code and which code line raised the error?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 02:43:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credentials-C/m-p/258872#M7987</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-09-26T02:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credentials C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credentials-C/m-p/259097#M7992</link>
      <description>&lt;P&gt;I have found out that the BadRequest was already in the GetGatewayByIdWithHttpMessagesAsync call. But nevertheless I found an easier way to handle the problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var request = new HttpRequestMessage (
                        new HttpMethod ("PATCH"),
                        $"https://api.powerbi.com/v1.0/myorg/gateways/{gatewayDatasource.GatewayId}/datasources/{gatewayDatasource.Id}");
                    request.Content = new StringContent (
                    $@" {{
                        'credentialType': 'Basic',
                        'basicCredentials': {{
                            'username': '{username}',
                            'password': '{password}'
                        }}
                    }}");
                    request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse ("application/json");
                    await m_powerBIClient.Credentials.ProcessHttpRequestAsync (request, cancellationToken);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No nasty encryption as it is a secure connection anyway. Wondering why&amp;nbsp;basic credentials are not supported by the C# API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2017 08:12:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credentials-C/m-p/259097#M7992</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-09-26T08:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credentials C#</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credentials-C/m-p/271635#M8216</link>
      <description>&lt;P&gt;There is currently some issue with V2&amp;nbsp;client.Gateways.UpdateDatasourceAsync&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The body which is sent using that method:&lt;/P&gt;&lt;PRE&gt;{
  "credentialDetails": {
    "credentials": "{\"credentialType\":\"Basic\",\"basicCredentials\":{\"username\":\"usrnmame\",\"password\":\"password\"}}"
  }
}&lt;/PRE&gt;&lt;P&gt;where the correct one should be:&lt;/P&gt;&lt;PRE&gt;{
"credentialType":"Basic",
"basicCredentials":{"username":"usrname","password":"password"}
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Simple http request as pointed above will work just fine:)&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2017 12:04:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credentials-C/m-p/271635#M8216</guid>
      <dc:creator>nicksav</dc:creator>
      <dc:date>2017-10-07T12:04:23Z</dc:date>
    </item>
  </channel>
</rss>

