<?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 new SQL Datasource for Gateway with Powershell. in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/m-p/1342584#M25526</link>
    <description>&lt;P&gt;Was this issue ever solved? I am getting a 400 bad request.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Sep 2020 23:29:40 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-09-02T23:29:40Z</dc:date>
    <item>
      <title>Creating new SQL Datasource for Gateway with Powershell.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/m-p/695814#M19457</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;Is it possible to automatise creating SQL Datasource in specified Gateway with Powershell?&lt;BR /&gt;Documentation says it's possible to create new Datasource&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/createdatasource" target="_blank" rel="noopener"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/createdatasource&lt;/A&gt;&amp;nbsp;with Rest API by 'Invoke-PowerBiRestMethod' in PS.&lt;BR /&gt;If I'm not wrong as credentials we can use example from here:&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/updatedatasource#examples" target="_blank" rel="noopener"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/updatedatasource#examples&lt;/A&gt;&amp;nbsp;(update credentials).&lt;BR /&gt;&lt;BR /&gt;So we've got body:&lt;/P&gt;&lt;PRE&gt;$body = '{
"datasourceType": "Sql",
"connectionDetails": "{\"server\":\"&lt;STRONG&gt;real_sql_server_address&lt;/STRONG&gt;\",
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;\"database\":\"&lt;STRONG&gt;real_database_name&lt;/STRONG&gt;\"}",
"datasourceName": "&lt;STRONG&gt;new_name_for_datasource&lt;/STRONG&gt;"
"credentialDetails": {"credentialType": "Basic",
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "credentials": "{\"credentialData\":[{\"name\":\"username\",
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;         \"value\":\"&lt;STRONG&gt;real_sql_username&lt;/STRONG&gt;\"},
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{\"name\":\"password\", 
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; \"value\":\"&lt;STRONG&gt;real_password&lt;/STRONG&gt;\"}]
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }",
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"encryptedConnection": "Encrypted",
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"encryptionAlgorithm": "None",
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"privacyLevel": "None"
},
}'&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;Invoke-PowerBiRestMethod -Url https://api.powerbi.com/v1.0/myorg/gateways/Id-of-real-gateway/datasources -Method Post -Body $body -Verbose&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;*with bold are marked real parameters we can use&lt;BR /&gt;&lt;BR /&gt;When we execute above code: we've got response:&lt;/P&gt;&lt;PRE&gt;Status Code: BadRequest (400)&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Above code without slashes and with option to convert to json format doesn't work either:&lt;/P&gt;&lt;PRE&gt;$body = '{"datasourceType": "Sql",
"connectionDetails": "{"server":"&lt;STRONG&gt;real_sql_server_address&lt;/STRONG&gt;",
                       "database":"&lt;STRONG&gt;real_database_name&lt;/STRONG&gt;"}",
  "datasourceName": "&lt;STRONG&gt;new_name_for_datasource&lt;/STRONG&gt;"
  "credentialDetails": {"credentialType": "Basic",
                        "useEndUserOAuth2Credentials":false,
                        "credentials": "{"credentialData\":[{"name":"username",
                                                              "value":"&lt;STRONG&gt;real_sql_username&lt;/STRONG&gt;"},
                                                             {"name":"password", 
                                                              "value":"&lt;STRONG&gt;real_password&lt;/STRONG&gt;"}]}",
                        "encryptedConnection": "Encrypted",
                        "encryptionAlgorithm": "None",
                        "privacyLevel": "None"
  },
}'
$body = $body | ConvertTo-Json&lt;/PRE&gt;&lt;P&gt;After executing command:&lt;/P&gt;&lt;PRE&gt;Resolve-PowerBIError -last&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;we receive:&lt;/P&gt;&lt;PRE&gt;Message        : 400 (Bad Request).
StackTrace     :    w System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
                    w Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod.&amp;lt;InvokeRestMethod&amp;gt;d__31.MoveNext()
Exception      : System.Net.Http.HttpRequestException
InvocationInfo : {Invoke-PowerBIRestMethod}
Line           : Invoke-PowerBiRestMethod -Url https://api.powerbi.com/v1.0/myorg/gateways/Id-of-real-gateway/datasources -Method Post -Body $body
                  -Verbose
Position       : At line:1 char:1
                 + Invoke-PowerBiRestMethod -Url https://api.powerbi.com/v1.0/myorg/gate ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : xxx&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Even simple update datasource doesn't work:&lt;/P&gt;&lt;PRE&gt;$body = '{
  "credentialDetails": {
    "credentialType": "Basic",
    "credentials": "{"credentialData":[{"name":"username", "value":"&lt;STRONG&gt;real_sql_username&lt;/STRONG&gt;"},{"name":"password", "value":"&lt;STRONG&gt;real_sql_password&lt;/STRONG&gt;"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None"
  }
}'

$body = $body | ConvertTo-Json



Invoke-PowerBiRestMethod -Url  https://api.powerbi.com/v1.0/myorg/gateways/&lt;STRONG&gt;Id-gateway&lt;/STRONG&gt;/datasources/&lt;STRONG&gt;Id-datasource&lt;/STRONG&gt; -Method Patch -Body $body -Verbose&lt;/PRE&gt;&lt;P&gt;Response:&lt;/P&gt;&lt;PRE&gt;VERBOSE: Status Code: BadRequest (400)&lt;/PRE&gt;&lt;P&gt;Am I doing something wrong or it's just doesn't work?&lt;BR /&gt;Is it even possible with Powershell?&lt;BR /&gt;&lt;BR /&gt;Greetings&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 12:17:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/m-p/695814#M19457</guid>
      <dc:creator>sm3</dc:creator>
      <dc:date>2019-05-23T12:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new SQL Datasource for Gateway with Powershell.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/m-p/735772#M19930</link>
      <description>&lt;P&gt;I am having the exact same issue.&amp;nbsp; No clue how to resolve.&amp;nbsp; Have you had any luck?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 21:13:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/m-p/735772#M19930</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-07-09T21:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new SQL Datasource for Gateway with Powershell.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/m-p/1342584#M25526</link>
      <description>&lt;P&gt;Was this issue ever solved? I am getting a 400 bad request.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 23:29:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/m-p/1342584#M25526</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-02T23:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating new SQL Datasource for Gateway with Powershell.</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/m-p/1377688#M25760</link>
      <description>&lt;P&gt;Anyone figured out how to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;add a datasource without encryption and without credentials&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;like the checkbox "skip test connection"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using "anonymus" credential type but that did not work yet in my tests.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 12:58:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Creating-new-SQL-Datasource-for-Gateway-with-Powershell/m-p/1377688#M25760</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-17T12:58:25Z</dc:date>
    </item>
  </channel>
</rss>

