<?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: Changing gateway datasource credentials through API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2291151#M33963</link>
    <description>&lt;P&gt;Your original question stated "gateway datasource credentials".&amp;nbsp; Please clarify.&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jan 2022 13:11:08 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2022-01-19T13:11:08Z</dc:date>
    <item>
      <title>Changing gateway datasource credentials through API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2253820#M33603</link>
      <description>&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;I'm failing on pretty simple task - update datasource credentials with OAuth2 token passed in payload.&lt;/P&gt;&lt;P&gt;Firstly, i'm generating new token to be passed with below request:&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;$getDatasourceTokenRequestParams = @{
        Method = 'POST'
        Uri    = "https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token"
        Body   = @{
            grant_type = 'client_credentials'
            client_id = $ClientId
            client_secret = $ServicePrincipalSecret
            scope = $ClientId+'/.default'
            audience = 'https://s*****-test.database.windows.net/'
        }
    }
    $TokenRequest = Invoke-RestMethod @getDatasourceTokenRequestParams&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then i paste this token into my request using Try It facility on&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#code-try-0" target="_blank" rel="noopener"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#code-try-0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I insert datasourceid and gatewayid and request body with the token:&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;{
  "credentialDetails": {
    "credentialType": "OAuth2",
    "credentials": "{\"credentialData\":[{\"name\":\"accessToken\", \"value\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik1yNS1BVWliZkJpaTdOZDFqQmViYXhib1hXMCJ9.eyJhdWQiOiI1ZjkwMGRhOC03NTUzLTQyYWItOTljYy1hM2QzNjg3ZTM3MzEiLCJpc3M
iOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vM2UyMGVjYjItOWNiMC00ZGYxLWFkN2ItOTE0ZTMxZGNkZGE0L3YyLjAiLCJpYXQiOjE2NDAyNjYyNDMsIm5iZiI6MTY0MDI2NjI0Myw
iZXhwIjoxNjQwMjcwMTQzLCJhaW8iOiJFMlpnWU5DLzhEak45UFBSOVNIOHhoYzRLODY5QWdBPSIsImF6cCI6IjVmOTAwZGE4LTc1NTMtNDJhYi05OWNjLWEzZDM2ODdlMzczMSIsImF6cGFjciI6IjE
iLCJvaWQiOiI3NjMxNmI5Zi0xYzA2LTQzZTItYTNkZi02NzQzMjk5OTUzZmQiLCJyaCI6IjAuQVJzQXN1d2dQckNjOFUydGU1Rk9NZHpkcEtnTmtGOVRkYXRDbWN5ajAyaC1OekViQUFBLiIsInN1YiI
6Ijc2MzE2YjlmLTFjMDYtNDNlMi1hM2RmLTY3NDMyOTk5NTNmZCIsInRpZCI6IjNlMjBlY2IyLTljYjAtNGRmMS1hZDdiLTkxNGUzMWRjZGRhNCIsInV0aSI6IAOI_EnwgM_-1TOcGHiXXPkQqLH5D9STh_KhgC0xgLBZV8W3eO5jMffUxRsuUIGeJigcGbeKlGLCj08k_OgbPeoyAPloGI_Ahl9x3FSE1G0kQH7ehP7wdlI
ppwL09Yi1ScId09NzZnJHtcvUOrOrqgE8oSSx3cn_BwvQnGB8UDTSEufig\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None"
  }
}&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;All looks great but i receiving 401 response code &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&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;{
  "error": {
    "code": "PowerBINotAuthorizedException",
    "pbi.error": {
      "code": "PowerBINotAuthorizedException",
      "parameters": {},
      "details": [],
      "exceptionCulprit": 1
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assume that token i generated is incorrect, but unfortunately i didn't found any documentation on how exactly it should be generated.&lt;/P&gt;&lt;P&gt;Could you please provide me with the steps how to get correct token for this request?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 14:05:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2253820#M33603</guid>
      <dc:creator>SashaSydorenko</dc:creator>
      <dc:date>2021-12-23T14:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gateway datasource credentials through API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2255742#M33619</link>
      <description>&lt;P&gt;Did you grant that app/service principal the required gateway admin permissions and the ReadWrite scope on the tenant?&lt;/P&gt;</description>
      <pubDate>Sat, 25 Dec 2021 17:47:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2255742#M33619</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2021-12-25T17:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gateway datasource credentials through API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2257742#M33633</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/347775"&gt;@SashaSydorenko&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Are you using service principal? If so, did you go through all the proper configuration to enable service principal access to Power BI API in your tenant and add servide principal as gatewway admin?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal" target="_self"&gt;https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/Power-Bi-REST-API-401-Authorization-error-when-using-Service/m-p/627827" target="_self"&gt;https://community.powerbi.com/t5/Developer/Power-Bi-REST-API-401-Authorization-error-when-using-Service/m-p/627827&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Liang&lt;BR /&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Dec 2021 05:32:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2257742#M33633</guid>
      <dc:creator>V-lianl-msft</dc:creator>
      <dc:date>2021-12-28T05:32:32Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gateway datasource credentials through API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2291132#M33961</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="UserName lia-user-name lia-user-rank-Super-User"&gt;&lt;SPAN class="lia-link-navigation lia-page-link lia-link-disabled lia-user-name-link"&gt;&lt;SPAN class=""&gt;lbendlin&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Service Principal have ReadWrite scope API permissions. Not sure about gateway admin? It's some kind of role in Power BI tenant? I'm actually not using gateways because datasource is in Azure.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 13:01:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2291132#M33961</guid>
      <dc:creator>SashaSydorenko</dc:creator>
      <dc:date>2022-01-19T13:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gateway datasource credentials through API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2291135#M33962</link>
      <description>&lt;P&gt;Hi Liang,&lt;/P&gt;&lt;P&gt;Service Principal have ReadWrite scope API permissions. Not sure about gateway admin? It's some kind of role in Power BI tenant? I'm actually not using gateways because datasource is in Azure.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 13:02:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2291135#M33962</guid>
      <dc:creator>SashaSydorenko</dc:creator>
      <dc:date>2022-01-19T13:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gateway datasource credentials through API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2291151#M33963</link>
      <description>&lt;P&gt;Your original question stated "gateway datasource credentials".&amp;nbsp; Please clarify.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 13:11:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2291151#M33963</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2022-01-19T13:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gateway datasource credentials through API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2291268#M33966</link>
      <description>&lt;P&gt;Hmmm good point. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;It a bit confusing because it is how docs article is called &lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But yeah, my report don't need a gateway - datasourcse is Azure SQL DB.&lt;/P&gt;&lt;P&gt;Does i'm use wrong API to update datasource credentials in this case?&lt;/P&gt;&lt;P&gt;Didn't found any other way to do that.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 14:08:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2291268#M33966</guid>
      <dc:creator>SashaSydorenko</dc:creator>
      <dc:date>2022-01-19T14:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Changing gateway datasource credentials through API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2455928#M35531</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.powerbi.com/t5/user/viewprofilepage/user-id/347775" target="_blank"&gt;@SashaSydorenko&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Did you manage to resolve this issue?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am getting the same error.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please share if you have a solution.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&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;</description>
      <pubDate>Wed, 13 Apr 2022 21:46:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Changing-gateway-datasource-credentials-through-API/m-p/2455928#M35531</guid>
      <dc:creator>sjoeboy</dc:creator>
      <dc:date>2022-04-13T21:46:36Z</dc:date>
    </item>
  </channel>
</rss>

