<?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 Unable to update data source credentials using PowerBI API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/298585#M8840</link>
    <description>&lt;P&gt;I have created a PBIX that used direct query to SQL Azure DB. I initially created this report in development environment that points to my development DB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For production purpose, I programatically upload this report to a group in Power BI. Likewise for other reports. Then I try to programatically update the data source along with credentials using PowerBI API. But it fails. It updates the data source (DB server and catalog), but not the credentials.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my sample code that updates the data source connection string:&lt;BR /&gt;foreach( var ds in client.Datasets.GetDatasetsInGroup(grp.Id).Value)&lt;BR /&gt;client.Datasets.SetAllDatasetConnectionsInGroup(grp.Id,ds.Id , new ConnectionDetails(ConnectionString));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I doing it the right way. Kindly advice.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Nov 2017 03:38:14 GMT</pubDate>
    <dc:creator>shiva</dc:creator>
    <dc:date>2017-11-08T03:38:14Z</dc:date>
    <item>
      <title>Unable to update data source credentials using PowerBI API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/298585#M8840</link>
      <description>&lt;P&gt;I have created a PBIX that used direct query to SQL Azure DB. I initially created this report in development environment that points to my development DB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For production purpose, I programatically upload this report to a group in Power BI. Likewise for other reports. Then I try to programatically update the data source along with credentials using PowerBI API. But it fails. It updates the data source (DB server and catalog), but not the credentials.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my sample code that updates the data source connection string:&lt;BR /&gt;foreach( var ds in client.Datasets.GetDatasetsInGroup(grp.Id).Value)&lt;BR /&gt;client.Datasets.SetAllDatasetConnectionsInGroup(grp.Id,ds.Id , new ConnectionDetails(ConnectionString));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I doing it the right way. Kindly advice.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2017 03:38:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/298585#M8840</guid>
      <dc:creator>shiva</dc:creator>
      <dc:date>2017-11-08T03:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update data source credentials using PowerBI API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/300763#M8845</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/46378"&gt;@shiva&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have created a PBIX that used direct query to SQL Azure DB. I initially created this report in development environment that points to my development DB.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For production purpose, I programatically upload this report to a group in Power BI. Likewise for other reports. Then I try to programatically update the data source along with credentials using PowerBI API. But it fails. It updates the data source (DB server and catalog), but not the credentials.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is my sample code that updates the data source connection string:&lt;BR /&gt;foreach( var ds in client.Datasets.GetDatasetsInGroup(grp.Id).Value)&lt;BR /&gt;client.Datasets.SetAllDatasetConnectionsInGroup(grp.Id,ds.Id , new ConnectionDetails(ConnectionString));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Am I doing it the right way. Kindly advice.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/46378"&gt;@shiva&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You'll have to set credentials after updating the connection string, see&amp;nbsp;&lt;A href="https://msdn.microsoft.com/en-US/library/mt732879.aspx" target="_self"&gt;Set Credentials&lt;/A&gt;, you'll get the gatewayid from&amp;nbsp;&lt;A href="https://msdn.microsoft.com/en-us/library/mt732874.aspx" target="_self"&gt;Get BoundGatewayDatasources&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 09:37:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/300763#M8845</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-11-10T09:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update data source credentials using PowerBI API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/301780#M8879</link>
      <description>&lt;P&gt;Thanks for the reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not using any gateway. I am using PowerBI with SQL Azure. Why should I create a gateway ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 07:48:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/301780#M8879</guid>
      <dc:creator>shiva</dc:creator>
      <dc:date>2017-11-13T07:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update data source credentials using PowerBI API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/301847#M8881</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/46378"&gt;@shiva&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the reply.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not using any gateway. I am using PowerBI with SQL Azure. Why should I create a gateway ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/46378"&gt;@shiva&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Azure SQL in Power BI internally actually uses gateway, however there's nothing for you to configure. If you call&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A title="" href="https://msdn.microsoft.com/en-us/library/mt732874.aspx" target="_self" rel="nofollow noopener noreferrer"&gt;Get BoundGatewayDatasources&lt;/A&gt;&amp;nbsp;by passing the Azure SQL datasetid, you'll get the gatewayid.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 08:56:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/301847#M8881</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-11-13T08:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update data source credentials using PowerBI API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/302764#M8926</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Status.png" style="width: 600px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/69389i168246AD5A858814/image-size/large?v=v2&amp;amp;px=999" role="button" title="Status.png" alt="Status.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Eric, kindly refer to the above pic,&amp;nbsp; I am getting forbidden access error. What could be the reason? Below is the code I used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;string uri = string.Format("&lt;A href="https://api.powerbi.com/v1.0/myorg/gateways/{0}/datasources/{1" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/gateways/{0}/datasources/{1&lt;/A&gt;}", result[0].GatewayId, item.Id);&lt;/P&gt;&lt;P&gt;var Uri = new Uri(uri);&lt;/P&gt;&lt;P&gt;var content = new StringContent("{ \"credentialType\": \"Basic\", \"basicCredentials\": { \"username\": \"userName\", \"password\": \"password\" }}", System.Text.Encoding.Default, "application/json");&lt;/P&gt;&lt;P&gt;using (var request = new HttpRequestMessage { Method = new HttpMethod("PATCH"), RequestUri = Uri, Content = content })&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;var rep = client.HttpClient.SendAsync(request).Result;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 09:59:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/302764#M8926</guid>
      <dc:creator>shiva</dc:creator>
      <dc:date>2017-11-14T09:59:20Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to update data source credentials using PowerBI API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/307564#M9060</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/46378"&gt;@shiva&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Status.png" style="width: 600px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/69389i168246AD5A858814/image-size/large?v=v2&amp;amp;px=999" role="button" title="Status.png" alt="Status.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi Eric, kindly refer to the above pic,&amp;nbsp; I am getting forbidden access error. What could be the reason? Below is the code I used:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;string uri = string.Format("&lt;A href="https://api.powerbi.com/v1.0/myorg/gateways/{0}/datasources/{1" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/gateways/{0}/datasources/{1&lt;/A&gt;}", result[0].GatewayId, item.Id);&lt;/P&gt;
&lt;P&gt;var Uri = new Uri(uri);&lt;/P&gt;
&lt;P&gt;var content = new StringContent("{ \"credentialType\": \"Basic\", \"basicCredentials\": { \"username\": \"userName\", \"password\": \"password\" }}", System.Text.Encoding.Default, "application/json");&lt;/P&gt;
&lt;P&gt;using (var request = new HttpRequestMessage { Method = new HttpMethod("PATCH"), RequestUri = Uri, Content = content })&lt;BR /&gt;{&lt;/P&gt;
&lt;P&gt;var rep = client.HttpClient.SendAsync(request).Result;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/46378"&gt;@shiva&lt;/a&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The registered app &lt;STRONG&gt;requirs scope&lt;/STRONG&gt;&lt;SPAN&gt;: Dataset.ReadWrite.All or Dataset.Read.All, check the &lt;A href="https://community.powerbi.com/t5/Developer/ERROR-Authorization-RequestDenied-Insufficient-privileges-to/m-p/277683#M8325" target="_self"&gt;registered app in Azure portal&lt;/A&gt;.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;SPAN&gt;Add try catch block to get the very specific error message.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&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;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 08:27:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Unable-to-update-data-source-credentials-using-PowerBI-API/m-p/307564#M9060</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-11-21T08:27:19Z</dc:date>
    </item>
  </channel>
</rss>

