<?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 OAuth2 Dataset Credentails Update after take over fails in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/OAuth2-Dataset-Credentails-Update-after-take-over-fails/m-p/2165970#M32694</link>
    <description>&lt;P&gt;I am trying to take over a dataset that has data in ADX and although the take over is successful, the dataset credentials need to be updated.&lt;/P&gt;&lt;P&gt;*SPN and user have full admin rights on workspace and Adx cluster&lt;/P&gt;&lt;P&gt;I have the following script:&lt;BR /&gt;&lt;BR /&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$PWord = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $clientId, $PWord


Connect-PowerBIServiceAccount -Tenant $Tenant -ServicePrincipal -Credential $Credential



################ Taking over dataset as SPN  ####################

Invoke-PowerBIRestMethod -Url "groups/$($Workspace)/datasets/$($Dataset)/Default.TakeOver" -Method POST -Body "" 

####################  "Resetting" Credentials towards datasource of dataset ####################


# Apparently we need the id of the "Gateway" that the datasets resides within. If it doesn't have a gateway (if it's a cloud data source for instance) it uses Microsofts "Default" gateway. We need its ID.
$BounGateway=Invoke-PowerBIRestMethod -Url "groups/$($Workspace)/datasets/$($Dataset)/Default.GetBoundGatewayDataSources" -Method GET | ConvertFrom-Json 

$Accesstoken = Get-PowerBiAccessToken

$Body =
@{
credentialDetails = @{
credentialType = "OAuth2";
credentials = "{`"credentialData`":[{`"name`":`"accessToken`", `"value`":`"$($Accesstoken.Authorization)`"}]}";
encryptedConnection = "Encrypted";
encryptionAlgorithm = "None";
privacyLevel = "None"
}
} | ConvertTo-Json

Write-Output $Body

Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayId)/datasources/$($BounGateway.value.id)" -Method PATCH -Body $Body | ConvertFrom-Json &lt;/LI-CODE&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;The body of the request I have created it using the example from here: &lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#oauth2-credentials-example.." target="_blank" rel="noopener"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#oauth2-credentials-example&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Finally, as you can see in the script I use an SPN and an access token for it and the last PATCH request returns:&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Invoke-PowerBIRestMethod:
Line |
  44 |  Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayI …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | One or more errors occurred. (Response status code does not indicate success: 400 (Bad Request).)&lt;/LI-CODE&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I tried to use an actual user to do this operation, but the PATCH request with the user access token returns 401:&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Invoke-PowerBIRestMethod:
Line |
  14 |  Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayI …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | One or more errors occurred. (Response status code does not indicate success: 401 (Unauthorized).)&lt;/LI-CODE&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This story seems to be related to&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/td-p/1056352" target="_self"&gt;this&lt;/A&gt;&amp;nbsp;,&amp;nbsp; but it is unanswered for OAuth2.&lt;/P&gt;&lt;P&gt;I was wondering is somebody has figured what the issue is, as far as I have searched the only working credential types are "key" and "basic".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/226550"&gt;@NandanHegde&lt;/a&gt;&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;</description>
    <pubDate>Mon, 01 Nov 2021 11:33:53 GMT</pubDate>
    <dc:creator>alexandruMP</dc:creator>
    <dc:date>2021-11-01T11:33:53Z</dc:date>
    <item>
      <title>OAuth2 Dataset Credentails Update after take over fails</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/OAuth2-Dataset-Credentails-Update-after-take-over-fails/m-p/2165970#M32694</link>
      <description>&lt;P&gt;I am trying to take over a dataset that has data in ADX and although the take over is successful, the dataset credentials need to be updated.&lt;/P&gt;&lt;P&gt;*SPN and user have full admin rights on workspace and Adx cluster&lt;/P&gt;&lt;P&gt;I have the following script:&lt;BR /&gt;&lt;BR /&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$PWord = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $clientId, $PWord


Connect-PowerBIServiceAccount -Tenant $Tenant -ServicePrincipal -Credential $Credential



################ Taking over dataset as SPN  ####################

Invoke-PowerBIRestMethod -Url "groups/$($Workspace)/datasets/$($Dataset)/Default.TakeOver" -Method POST -Body "" 

####################  "Resetting" Credentials towards datasource of dataset ####################


# Apparently we need the id of the "Gateway" that the datasets resides within. If it doesn't have a gateway (if it's a cloud data source for instance) it uses Microsofts "Default" gateway. We need its ID.
$BounGateway=Invoke-PowerBIRestMethod -Url "groups/$($Workspace)/datasets/$($Dataset)/Default.GetBoundGatewayDataSources" -Method GET | ConvertFrom-Json 

$Accesstoken = Get-PowerBiAccessToken

$Body =
@{
credentialDetails = @{
credentialType = "OAuth2";
credentials = "{`"credentialData`":[{`"name`":`"accessToken`", `"value`":`"$($Accesstoken.Authorization)`"}]}";
encryptedConnection = "Encrypted";
encryptionAlgorithm = "None";
privacyLevel = "None"
}
} | ConvertTo-Json

Write-Output $Body

Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayId)/datasources/$($BounGateway.value.id)" -Method PATCH -Body $Body | ConvertFrom-Json &lt;/LI-CODE&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;The body of the request I have created it using the example from here: &lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#oauth2-credentials-example.." target="_blank" rel="noopener"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#oauth2-credentials-example&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Finally, as you can see in the script I use an SPN and an access token for it and the last PATCH request returns:&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Invoke-PowerBIRestMethod:
Line |
  44 |  Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayI …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | One or more errors occurred. (Response status code does not indicate success: 400 (Bad Request).)&lt;/LI-CODE&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I tried to use an actual user to do this operation, but the PATCH request with the user access token returns 401:&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Invoke-PowerBIRestMethod:
Line |
  14 |  Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayI …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | One or more errors occurred. (Response status code does not indicate success: 401 (Unauthorized).)&lt;/LI-CODE&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This story seems to be related to&amp;nbsp;&lt;A href="https://community.powerbi.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/td-p/1056352" target="_self"&gt;this&lt;/A&gt;&amp;nbsp;,&amp;nbsp; but it is unanswered for OAuth2.&lt;/P&gt;&lt;P&gt;I was wondering is somebody has figured what the issue is, as far as I have searched the only working credential types are "key" and "basic".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/226550"&gt;@NandanHegde&lt;/a&gt;&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;</description>
      <pubDate>Mon, 01 Nov 2021 11:33:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/OAuth2-Dataset-Credentails-Update-after-take-over-fails/m-p/2165970#M32694</guid>
      <dc:creator>alexandruMP</dc:creator>
      <dc:date>2021-11-01T11:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: OAuth2 Dataset Credentails Update after take over fails</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/OAuth2-Dataset-Credentails-Update-after-take-over-fails/m-p/2171923#M32738</link>
      <description>&lt;P&gt;You can refer to this thread:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/Programmatically-enter-missing-dataset-credentials-using-API/m-p/877900" target="_self"&gt;https://community.powerbi.com/t5/Developer/Programmatically-enter-missing-dataset-credentials-using-API/m-p/877900&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Nov 2021 06:11:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/OAuth2-Dataset-Credentails-Update-after-take-over-fails/m-p/2171923#M32738</guid>
      <dc:creator>V-lianl-msft</dc:creator>
      <dc:date>2021-11-04T06:11:59Z</dc:date>
    </item>
  </channel>
</rss>

