<?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: Powershell API Update datasource in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/847482#M21416</link>
    <description>&lt;P&gt;So apparantly the trailing slash in the resource URL was the problem, removed it and now I get the token back. So "&lt;A href="https://analysis.windows.net/powerbi/api/" target="_blank"&gt;https://analysis.windows.net/powerbi/api/&lt;/A&gt;" didn't work but "&lt;A href="https://analysis.windows.net/powerbi/api" target="_blank"&gt;https://analysis.windows.net/powerbi/api&lt;/A&gt;" works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now that I know that of course I notice the Microsoft guide doesn't have a trailing slash but the URL where you add permissions to the service principal have the trailing slash.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A bit frustrated that I didn't notice/tested this but I simply didn't even notice/think about the slash....&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Nov 2019 13:00:39 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-11-15T13:00:39Z</dc:date>
    <item>
      <title>Powershell API Update datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/831786#M21231</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;we're creating poweshell script for the deployment of our datasets/reports to different environments.&lt;/P&gt;&lt;P&gt;Later will use this scripts in Azure DevOps for automatic deployment.&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&lt;SPAN&gt;ServicePrincipal is created&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;for the deployments (&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embed-service-principal#service-principal-vs-master-account" target="_blank" rel="noopener"&gt;Create service principle&lt;/A&gt;) . Deployment is working fine but we've an issue when we want to update the datasource.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;We're connecting to a Azure SQL database.&lt;/P&gt;&lt;P&gt;Everytime we receive the error below when calling the command: "&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Invoke-PowerBIRestMethod&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt;Url&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;groups/&lt;/SPAN&gt;&lt;SPAN&gt;$($&lt;/SPAN&gt;&lt;SPAN&gt;destinationWorkspace.Id&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;/datasets/&lt;/SPAN&gt;&lt;SPAN&gt;$($&lt;/SPAN&gt;&lt;SPAN&gt;datasetid&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;/Default.UpdateDatasources&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt;Method&amp;nbsp;POST&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt;Body&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;NewConnectionBody&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;|&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;ConvertFrom-Json"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Error.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/204231i433B3DD970724A30/image-size/large?v=v2&amp;amp;px=999" role="button" title="Error.png" alt="Error.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The value of the $NewConnectionBody looks like&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="body.png" style="width: 471px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/204237i67A7AE58AD4E5793/image-size/large?v=v2&amp;amp;px=999" role="button" title="body.png" alt="body.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Is there a solution that we can change the datasource using powershell?&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 29 Oct 2019 21:22:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/831786#M21231</guid>
      <dc:creator>KoenVdB</dc:creator>
      <dc:date>2019-10-29T21:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell API Update datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832060#M21233</link>
      <description>&lt;P&gt;Try using "Invoke-RestMethod" with complete URL&lt;BR /&gt;I suppose you are also adding "Content-Type" and header with "Authorization"&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 04:35:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832060#M21233</guid>
      <dc:creator>gauravkh</dc:creator>
      <dc:date>2019-10-30T04:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell API Update datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832232#M21235</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/114239"&gt;@KoenVdB&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here the possible solutions to try&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Did you add the SPN as an admin to the work space ?&lt;/LI&gt;&lt;LI&gt;Try using the fiddler to get the exact error message.&lt;/LI&gt;&lt;LI&gt;Did you Take Over the data set using the SPN ?- This requires if you need to modify the data sources in the dataset&lt;/LI&gt;&lt;LI&gt;You can look into my article which I gave the detailed step by step to achieve this&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/PowerBI-CICD-using-Azure-DevOps/ba-p/769244" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/PowerBI-CICD-using-Azure-DevOps/ba-p/769244&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 07:34:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832232#M21235</guid>
      <dc:creator>Jayendran</dc:creator>
      <dc:date>2019-10-30T07:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell API Update datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832569#M21238</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/100012"&gt;@Jayendran&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The SPN had admin rights to the workspace, the spn has take over the data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i created the body that needs to be provide manually like you see below, and it looks oke. I also placed the result of the json below&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="error1.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/204505i6FC591FBBC9B18EC/image-size/large?v=v2&amp;amp;px=999" role="button" title="error1.png" alt="error1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when doing this fiddler is giving me the following message:&amp;nbsp;&lt;/P&gt;&lt;P&gt;5B&lt;BR /&gt;{"error":{"code":"InvalidRequest","message":"Operation is not supported for selector #28"}}&lt;BR /&gt;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 12:42:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832569#M21238</guid>
      <dc:creator>KoenVdB</dc:creator>
      <dc:date>2019-10-30T12:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell API Update datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832585#M21240</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/114239"&gt;@KoenVdB&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see this similar thread&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/quot-Operation-is-not-supported-for-selector-quot-when-using/td-p/372441" target="_blank"&gt;https://community.powerbi.com/t5/Developer/quot-Operation-is-not-supported-for-selector-quot-when-using/td-p/372441&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 13:05:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832585#M21240</guid>
      <dc:creator>Jayendran</dc:creator>
      <dc:date>2019-10-30T13:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell API Update datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832658#M21242</link>
      <description>&lt;P&gt;Would you mind sharing how you manage to get the Bearer token using Service Principal and Powershell?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a SP, added it as admin to the workspace and also added the requiered delegated permissions in Azure (Power BI Service -&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://analysis.windows.net/powerbi/api/" target="_blank" rel="noopener"&gt;https://analysis.windows.net/powerbi/api/&lt;/A&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I can use the .Net nuget client package to do work on the workspace, updating reports/datasets and so on. But I can't manage to get the authorization token when I use either powershell, Invoke-RestMethod, or Postman.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;function getBearer([string]$TenantID, [string]$ClientID, [string]$ClientSecret)
{
  $TokenEndpoint = {https://login.microsoftonline.com/{0}/oauth2/token} -f $TenantID 
  #$ARMResource = "https://analysis.windows.net/powerbi/api/";
  $ARMResource = "https://api.powerbi.com/";

  $Body = @{
          'resource'= $ARMResource
          'client_id' = $ClientID
          'grant_type' = 'client_credentials'
          'client_secret' = $ClientSecret
  }

  $params = @{
      ContentType = 'application/x-www-form-urlencoded'
      Headers = @{'accept'='application/json'}
      Body = $Body
      Method = 'Post'
      URI = $TokenEndpoint
  }

  $token = Invoke-RestMethod @params

  Return "Bearer " + ($token.access_token).ToString()
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's how I try to acquire the&amp;nbsp; token but I keep getting "AADSTS500011: The resource principal named &lt;A href="https://api.powerbi.com/" target="_blank" rel="noopener"&gt;https://api.powerbi.com/&lt;/A&gt; was not found in the tenant named ... " (It's the same with&amp;nbsp;&lt;A href="https://analysis.windows.net/powerbi/api/" target="_blank" rel="noopener"&gt;https://analysis.windows.net/powerbi/api/&lt;/A&gt;) however&amp;nbsp;&lt;A href="https://management.azure.com/" target="_blank" rel="noopener"&gt;https://management.azure.com/&lt;/A&gt;&amp;nbsp;returns a bearer token.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance !&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2019 14:03:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832658#M21242</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-10-30T14:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell API Update datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832776#M21243</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i'm not using bearer token.&lt;/P&gt;&lt;P&gt;But maybe this can help you, this is how i connect:&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;$PowerBIServiceApplicationKey ="xxx"
$PowerBIServiceApplicationID ="xxx"
$TenantID = "yyy"

#Install Power Bi Modules
foreach ($moduleName in @("MicrosoftPowerBIMgmt.Reports", "MicrosoftPowerBIMgmt.Workspaces", "MicrosoftPowerBIMgmt.Profile","MicrosoftPowerBIMgmt.Data"))
{
  if  ((Get-Module $moduleName) -eq $null)
  {
      Write-Host "Installing $moduleName"
      Install-Module -Name $moduleName -Force
  }
}
securedPassword = $PowerBIServiceApplicationKey  | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($PowerBIServiceApplicationID,$securedPassword)

#Connect to PowerBI
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -Tenant $TenantID&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;Maybe u can use the command&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Get-PowerBIAccessToken &lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;to retrieve what you need after the connect?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 30 Oct 2019 15:27:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/832776#M21243</guid>
      <dc:creator>KoenVdB</dc:creator>
      <dc:date>2019-10-30T15:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell API Update datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/833450#M21249</link>
      <description>&lt;P&gt;Of course , why I didn't try with the actual Power BI packages is beyond me...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/114239"&gt;@KoenVdB&lt;/a&gt;&amp;nbsp; !&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2019 06:24:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/833450#M21249</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-10-31T06:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell API Update datasource</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/847482#M21416</link>
      <description>&lt;P&gt;So apparantly the trailing slash in the resource URL was the problem, removed it and now I get the token back. So "&lt;A href="https://analysis.windows.net/powerbi/api/" target="_blank"&gt;https://analysis.windows.net/powerbi/api/&lt;/A&gt;" didn't work but "&lt;A href="https://analysis.windows.net/powerbi/api" target="_blank"&gt;https://analysis.windows.net/powerbi/api&lt;/A&gt;" works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now that I know that of course I notice the Microsoft guide doesn't have a trailing slash but the URL where you add permissions to the service principal have the trailing slash.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A bit frustrated that I didn't notice/tested this but I simply didn't even notice/think about the slash....&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Nov 2019 13:00:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Powershell-API-Update-datasource/m-p/847482#M21416</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-15T13:00:39Z</dc:date>
    </item>
  </channel>
</rss>

