<?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: Update Credential to OAUTH2 type via REST API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1165190#M24213</link>
    <description>&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;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the reply. I used the code as you suggested. The pipeline deploys succesful, however the credentials aren't properly updated. On the powerBI website, I still get the message that the credentials of one of my datasources are missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I miss something else? Do I need to change some policies of access control settings?&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jun 2020 07:38:23 GMT</pubDate>
    <dc:creator>MGroeneveld</dc:creator>
    <dc:date>2020-06-17T07:38:23Z</dc:date>
    <item>
      <title>Update Credential to OAUTH2 type via REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1056352#M23384</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am trying to update the credentials of an Azure SQL database and Azure Analysis services via REST API through powershell.&lt;BR /&gt;I was able to successfully update the cred of Azure SQL database using basic auth.&lt;BR /&gt;But I am not able to update the cred to OAUTh type for either Azure DB or AAS .&lt;BR /&gt;So can some one please help me the same .&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Below is my code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$datasetname="xyz"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;$workspacename="ABC"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;$clientsec = "$(ClientSecret)" | ConvertTo-SecureString -AsPlainText -Force&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "&amp;lt;&amp;lt;ClientID&amp;gt;&amp;gt;", $clientsec &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "&amp;lt;&amp;lt;TenantID&amp;gt;&amp;gt;"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$workspace =Get-PowerBIWorkspace -Name $workspacename&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$token = Get-PowerBIAccessToken&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$accessToken = $token.Values -replace "Bearer ", ""&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;$DatasetResponse=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets" -Method Get | ConvertFrom-Json&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$datasets = $DatasetResponse.value&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;foreach($dataset in $datasets){&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;if($dataset.name -eq $datasetname){&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;$datasetid= $dataset.id;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;break;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;$BounGateway=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.GetBoundGatewayDataSources" -Method GET | ConvertFrom-Json&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;$UpdateUserCredential = @{&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;credentialType ="OAUTH2"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;CredentialData = @{ &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;name= "accessToken"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;value= $accessToken&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;} | ConvertTo-Json&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayId)/datasources/$($BounGateway.value.id)" -Method PATCH -Body $UpdateUserCredential | ConvertFrom-Json&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 11:50:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1056352#M23384</guid>
      <dc:creator>NandanHegde</dc:creator>
      <dc:date>2020-04-29T11:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credential to OAUTH2 type via REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1071840#M23469</link>
      <description>&lt;P&gt;I also tried the below scenarios wherein :&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Initially generated the access token for the user :&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;$password = "” | ConvertTo-SecureString -asPlainText -Force&lt;/P&gt;&lt;P&gt;$username = ""&lt;/P&gt;&lt;P&gt;$credentialSelf = New-Object System.Management.Automation.PSCredential($username, $password)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Login-PowerBI -Credential $credentialSelf&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$headers = Get-PowerBIAccessToken&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$accessToken = $headers.Values -replace "Bearer ", ""&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then implemented the below code to update the cred:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;BR /&gt;$datasetname="&amp;lt;&amp;lt;name&amp;gt;&amp;gt;"&lt;BR /&gt;$workspacename="PowerAutomation"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;$clientsec = "$(ClientSecret)" | ConvertTo-SecureString -AsPlainText -Force&lt;/P&gt;&lt;P&gt;$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "&amp;lt;&amp;lt;Client ID&amp;gt;&amp;gt;", $clientsec&lt;BR /&gt;Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId "&amp;lt;&amp;lt;tenantID&amp;gt;&amp;gt;"&lt;/P&gt;&lt;P&gt;$workspace =Get-PowerBIWorkspace -Name $workspacename&lt;/P&gt;&lt;P&gt;$workspace&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# GetDataSets&lt;BR /&gt;$DatasetResponse=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets" -Method Get | ConvertFrom-Json&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Get DataSet&lt;BR /&gt;$datasets = $DatasetResponse.value&lt;/P&gt;&lt;P&gt;foreach($dataset in $datasets){&lt;BR /&gt;if($dataset.name -eq $datasetname){&lt;BR /&gt;$datasetid= $dataset.id;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;$BounGateway=Invoke-PowerBIRestMethod -Url "groups/$($workspace.id)/datasets/$($datasetid)/Default.GetBoundGatewayDataSources" -Method GET | ConvertFrom-Json&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;$Body =&lt;BR /&gt;@{&lt;BR /&gt;credentialDetails = @{&lt;BR /&gt;credentialType = "OAuth2";&lt;BR /&gt;credentials = "{`"credentialData`":[{`"name`":`"accessToken`", `"value`":`"$(Accesstoken)`"}]}";&lt;BR /&gt;encryptedConnection = "Encrypted";&lt;BR /&gt;encryptionAlgorithm = "None";&lt;BR /&gt;privacyLevel = "None"&lt;BR /&gt;}&lt;BR /&gt;} | ConvertTo-Json&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Invoke-PowerBIRestMethod -Url "gateways/$($BounGateway.value.gatewayId)/datasources/$($BounGateway.value.id)" -Method PATCH -Body $Body | ConvertFrom-Json&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I referred the below link for the logic:&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/updatedatasource#basic-credentials-example" target="_blank" rel="noopener"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/updatedatasource#basic-credentials-example&lt;/A&gt;&lt;/P&gt;&lt;P&gt;which was succesful for key and basic auth but unable to update for OAuth.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So can someone help me with that?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/100012"&gt;@Jayendran&lt;/a&gt;&amp;nbsp; : I referred to your code for Power BI automation but it had only cred update via basic auth.&lt;BR /&gt;So can you please help me with this &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 06:12:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1071840#M23469</guid>
      <dc:creator>NandanHegde</dc:creator>
      <dc:date>2020-05-05T06:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credential to OAUTH2 type via REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1072053#M23474</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/226550"&gt;@NandanHegde&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please explain what do you mean by unable to work / not working ? Are you seeing any error ? Pls share that also&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is your data source ? Is that a sharepoint where you are trying to modify the OAuth2 token ?&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 07:42:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1072053#M23474</guid>
      <dc:creator>Jayendran</dc:creator>
      <dc:date>2020-05-05T07:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credential to OAUTH2 type via REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1072107#M23475</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;My datasources are Azure SQL database and Azure Analysis services for which I need to update the credentials via OAUTH2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically after updating the datasource details , I am trying to update the credentials of Azure SQL database which was successful via basic Auth but not via OAUTh.&lt;/P&gt;&lt;P&gt;As a part of security measure we are moving away from basic auth to OAuth in our organization for databases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I am unable to update the creds via OAUTH.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I tried executing the below powershell query, I am getting the error:&lt;/P&gt;&lt;P&gt;HTTPS: bad request.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I am not sure what I am doing wrong there?&lt;BR /&gt;And no where there is any example or documentation for updating of creds via OAUTh.&lt;/P&gt;&lt;P&gt;So wanted your help for the same.&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 07:54:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1072107#M23475</guid>
      <dc:creator>NandanHegde</dc:creator>
      <dc:date>2020-05-05T07:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credential to OAUTH2 type via REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1078842#M23546</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/226550"&gt;@NandanHegde&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure the powerbi access token is correct token for sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you try the below link for the sql token and pass it to the API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://techcommunity.microsoft.com/t5/azure-sql-database/azure-ad-service-principal-authentication-to-sql-db-code-sample/ba-p/481467" target="_blank"&gt;https://techcommunity.microsoft.com/t5/azure-sql-database/azure-ad-service-principal-authentication-to-sql-db-code-sample/ba-p/481467&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 09:35:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1078842#M23546</guid>
      <dc:creator>Jayendran</dc:creator>
      <dc:date>2020-05-07T09:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credential to OAUTH2 type via REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1155735#M24133</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/226550"&gt;@NandanHegde&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You wrote it was succesful for key and basic. Can you share your code for key? I got it working for basic, but it won't work for key.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used this code for 'basic':&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$UpdateUserCredentialBasic = @{&lt;BR /&gt;credentialType ="Basic"&lt;BR /&gt;basicCredentials = @{&lt;BR /&gt;username= '$(username)'&lt;BR /&gt;password= '$(password)'&lt;BR /&gt;}} | ConvertTo-Json;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance. Unfortunately I cannot help you with your problem.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 13:04:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1155735#M24133</guid>
      <dc:creator>MGroeneveld</dc:creator>
      <dc:date>2020-06-12T13:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credential to OAUTH2 type via REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1158372#M24162</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/237778"&gt;@MGroeneveld&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;&lt;P&gt;Please refer to the below code for key pair:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;$UpdateUserCredential =&lt;BR /&gt;@{&lt;BR /&gt;credentialDetails = @{&lt;BR /&gt;credentialType = "Key";&lt;BR /&gt;credentials = "{`"credentialData`":[{`"name`":`"key`", `"value`":`"$(key)`"}]}";&lt;BR /&gt;encryptedConnection = "Encrypted";&lt;BR /&gt;encryptionAlgorithm = "None";&lt;BR /&gt;privacyLevel = "None"&lt;BR /&gt;}&lt;BR /&gt;} | ConvertTo-Json&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;where $(key) is the access key passed as a parameter in Azure devops&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this provides you a clarity&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jun 2020 03:07:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1158372#M24162</guid>
      <dc:creator>NandanHegde</dc:creator>
      <dc:date>2020-06-15T03:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Update Credential to OAUTH2 type via REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1165190#M24213</link>
      <description>&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;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the reply. I used the code as you suggested. The pipeline deploys succesful, however the credentials aren't properly updated. On the powerBI website, I still get the message that the credentials of one of my datasources are missing.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I miss something else? Do I need to change some policies of access control settings?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 07:38:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Update-Credential-to-OAUTH2-type-via-REST-API/m-p/1165190#M24213</guid>
      <dc:creator>MGroeneveld</dc:creator>
      <dc:date>2020-06-17T07:38:23Z</dc:date>
    </item>
  </channel>
</rss>

