<?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: PowerBINotAuthorizedException ServicePrincipal despite all access done in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/PowerBINotAuthorizedException-ServicePrincipal-despite-all/m-p/2945588#M40101</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/479142"&gt;@BoNDoK00&lt;/a&gt;&amp;nbsp;, it looks like you are trying to connect using a Service Principal to use the Power BI Admin Rest API.&amp;nbsp; There is an important part in the documentation:&amp;nbsp;&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/power-bi/enterprise/read-only-apis-service-principal-authentication" target="_blank"&gt;Enable service principal authentication for read-only admin APIs - Power BI | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DarylLynchBzy_0-1670019830438.png" style="width: 790px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/834607iEED9F854B26A1BD7/image-dimensions/790x210?v=v2" width="790" height="210" role="button" title="DarylLynchBzy_0-1670019830438.png" alt="DarylLynchBzy_0-1670019830438.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you delete all the Power BI API setting in the Azure Portal the "PowerBINotAuthorizedException" should be avoided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Dec 2022 22:28:16 GMT</pubDate>
    <dc:creator>Daryl-Lynch-Bzy</dc:creator>
    <dc:date>2022-12-02T22:28:16Z</dc:date>
    <item>
      <title>PowerBINotAuthorizedException ServicePrincipal despite all access done</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PowerBINotAuthorizedException-ServicePrincipal-despite-all/m-p/2945145#M40098</link>
      <description>&lt;P&gt;I want to use Power BI PowerShell module.&amp;nbsp; This is what I have done:&lt;/P&gt;&lt;P&gt;1. I got Power BI Moduel installed in PowerShell&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BoNDoK00_0-1669999553326.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/834456iB9709CDC43FBCA9B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BoNDoK00_0-1669999553326.png" alt="BoNDoK00_0-1669999553326.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I got an app registered with the following permissions:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BoNDoK00_1-1669999612007.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/834457iC92FF1BC7E8B8EA5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BoNDoK00_1-1669999612007.png" alt="BoNDoK00_1-1669999612007.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;(This message is shown on the top of the permissions screen)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BoNDoK00_2-1669999643109.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/834458iF56B3AB13BAF0C7C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BoNDoK00_2-1669999643109.png" alt="BoNDoK00_2-1669999643109.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. I added the Service Principal to a security group and granted him access in Power BI Admin Portal:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BoNDoK00_3-1669999708024.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/834459iB3C8EA904A3A1203/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BoNDoK00_3-1669999708024.png" alt="BoNDoK00_3-1669999708024.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;E.g.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BoNDoK00_4-1669999745988.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/834460iFE13A7D8063AAE9A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BoNDoK00_4-1669999745988.png" alt="BoNDoK00_4-1669999745988.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. I authenticate in Power Shell using this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$client_id = &amp;lt;&amp;gt;
$tenant_id =  &amp;lt;&amp;gt;
$secret =  &amp;lt;&amp;gt;

$SecurePassword = ConvertTo-SecureString $secret -Force -AsPlainText
$servicePrincipal = New-Object -TypeName PSCredential -ArgumentList $client_id, $SecurePassword

Connect-PowerBIServiceAccount -ServicePrincipal -Credential $servicePrincipal -Tenant $tenant_id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. I try to call APIs from PowerShell:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/admin/groups/&amp;lt;Group ID&amp;gt;/users' -Method Get&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following error message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Invoke-PowerBIRestMethod : One or more errors occurred.
At line:1 char:1
+ Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/adm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], AggregateException
    + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod
 
Invoke-PowerBIRestMethod : Encountered errors when invoking the command: {
  "code": "PowerBINotAuthorizedException",
  "pbi.error": {
    "code": "PowerBINotAuthorizedException",
    "parameters": {},
    "details": [],
    "exceptionCulprit": 1
  }
}
At line:1 char:1
+ Invoke-PowerBIRestMethod -Url 'https://api.powerbi.com/v1.0/myorg/adm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod) [Invoke-PowerBIRestMethod], Exception
    + FullyQualifiedErrorId : Encountered errors when invoking the command: {
  "code": "PowerBINotAuthorizedException",
  "pbi.error": {
    "code": "PowerBINotAuthorizedException",
    "parameters": {},
    "details": [],
    "exceptionCulprit": 1
  }
},Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please assist me to know what did I miss?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 16:53:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PowerBINotAuthorizedException-ServicePrincipal-despite-all/m-p/2945145#M40098</guid>
      <dc:creator>BoNDoK00</dc:creator>
      <dc:date>2022-12-02T16:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: PowerBINotAuthorizedException ServicePrincipal despite all access done</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PowerBINotAuthorizedException-ServicePrincipal-despite-all/m-p/2945588#M40101</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/479142"&gt;@BoNDoK00&lt;/a&gt;&amp;nbsp;, it looks like you are trying to connect using a Service Principal to use the Power BI Admin Rest API.&amp;nbsp; There is an important part in the documentation:&amp;nbsp;&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/power-bi/enterprise/read-only-apis-service-principal-authentication" target="_blank"&gt;Enable service principal authentication for read-only admin APIs - Power BI | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DarylLynchBzy_0-1670019830438.png" style="width: 790px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/834607iEED9F854B26A1BD7/image-dimensions/790x210?v=v2" width="790" height="210" role="button" title="DarylLynchBzy_0-1670019830438.png" alt="DarylLynchBzy_0-1670019830438.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you delete all the Power BI API setting in the Azure Portal the "PowerBINotAuthorizedException" should be avoided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Dec 2022 22:28:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PowerBINotAuthorizedException-ServicePrincipal-despite-all/m-p/2945588#M40101</guid>
      <dc:creator>Daryl-Lynch-Bzy</dc:creator>
      <dc:date>2022-12-02T22:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: PowerBINotAuthorizedException ServicePrincipal despite all access done</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PowerBINotAuthorizedException-ServicePrincipal-despite-all/m-p/2985255#M40439</link>
      <description>&lt;P&gt;I have similar issue and got the same error but only for some workspaces.&amp;nbsp; For most of the other workspaces, the powershell script works fine.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 22:13:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PowerBINotAuthorizedException-ServicePrincipal-despite-all/m-p/2985255#M40439</guid>
      <dc:creator>halamsjah</dc:creator>
      <dc:date>2022-12-22T22:13:43Z</dc:date>
    </item>
  </channel>
</rss>

