<?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: Creating datasource using Power BI RestAPI in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Creating-datasource-using-Power-BI-RestAPI/m-p/2173689#M32753</link>
    <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;It seems like you send the wrong request content to the rest API so that the power bi server return the bad request error.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;If you are not so sure how to configuration Datasource connections settings, you can try to publish a sample report to the power bi service side with a similar type of data source and use rest API to get the detailed configuration. After these steps, you can refer to this template to config your own data source settings.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/get-datasource" target="_blank"&gt;Gateways - Get Datasource - REST API (Power BI Power BI REST APIs) | Microsoft Docs&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Nov 2021 01:23:30 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-11-05T01:23:30Z</dc:date>
    <item>
      <title>Creating datasource using Power BI RestAPI</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Creating-datasource-using-Power-BI-RestAPI/m-p/2168408#M32712</link>
      <description>&lt;P&gt;I tried creating "Excel" datasource using PowerBI Rest API. When am calling the&amp;nbsp;CreateDatasource rest api call with parameters am getting error as "Bad request".&lt;/P&gt;&lt;P&gt;Below is the code:&lt;/P&gt;&lt;P&gt;private void btn_createdatasource(object sender, RoutedEventArgs e)&lt;BR /&gt;{&lt;BR /&gt;PowerBIClient pbiClient = TokenManager.GetPowerBiClient(requiredScopes);&lt;BR /&gt;var gateways = pbiClient.Gateways.GetGateways().Value;&lt;BR /&gt;var gateway = gateways.First();&lt;BR /&gt;var gatewaydatasources = pbiClient.Gateways.GetDatasources(gateway.Id).Value;&lt;BR /&gt;&lt;BR /&gt;// string userName= ConfigurationManager.AppSettings.Get("username");&lt;BR /&gt;string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;var datatype = "Excel";&lt;BR /&gt;var name = "excelsource";&lt;BR /&gt;var password = ConfigurationManager.AppSettings.Get("Password");&lt;BR /&gt;var credentials = new WindowsCredentials(userName, password);&lt;BR /&gt;var credentialsEncryptor = new AsymmetricKeyEncryptor(gateway.PublicKey);&lt;BR /&gt;var credentialDetails = new CredentialDetails(credentials, PrivacyLevel.Private, EncryptedConnection.Encrypted, credentialsEncryptor);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;var path =&lt;BR /&gt;@"C:\Users\sowmyas\Documents\ReportserverExcelfiles\SuperstoreSales.xlsx";&lt;BR /&gt;try {&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;var request = new PublishDatasourceToGatewayRequest(&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;dataSourceType: datatype,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;connectionDetails: "{ \"path\":\"" + path + "\"}",&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;credentialDetails: credentialDetails,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;dataSourceName: name);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;pbiClient.Gateways.CreateDatasource(gateway.Id, request);&lt;/FONT&gt;&lt;BR /&gt;MessageBox.Show("Gateway Datasource successfully : " + name);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;MessageBox.Show("Datasource not created in Gateway. Error: " + ex.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error Message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sowmyas_1-1635855443402.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/623993i79CA5C0297B4B393/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sowmyas_1-1635855443402.png" alt="sowmyas_1-1635855443402.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Name Value Type&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;▶&lt;/TD&gt;&lt;TD&gt;$exception&lt;/TD&gt;&lt;TD&gt;{"Operation returned an invalid status code 'BadRequest'"}&lt;/TD&gt;&lt;TD&gt;Microsoft.Rest.HttpOperationException&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 12:20:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Creating-datasource-using-Power-BI-RestAPI/m-p/2168408#M32712</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-11-02T12:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating datasource using Power BI RestAPI</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Creating-datasource-using-Power-BI-RestAPI/m-p/2173689#M32753</link>
      <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;It seems like you send the wrong request content to the rest API so that the power bi server return the bad request error.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;If you are not so sure how to configuration Datasource connections settings, you can try to publish a sample report to the power bi service side with a similar type of data source and use rest API to get the detailed configuration. After these steps, you can refer to this template to config your own data source settings.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/get-datasource" target="_blank"&gt;Gateways - Get Datasource - REST API (Power BI Power BI REST APIs) | Microsoft Docs&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Nov 2021 01:23:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Creating-datasource-using-Power-BI-RestAPI/m-p/2173689#M32753</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-11-05T01:23:30Z</dc:date>
    </item>
  </channel>
</rss>

