<?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 API error using service principal in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/API-error-using-service-principal/m-p/1404580#M25962</link>
    <description>&lt;P&gt;Hi. I'm trying to automate PowerBI report deployment and actions related with that. Due to organization policy I have to use service principal.&amp;nbsp;The service principal access in PowerBI is enabled and security group with created SP as a member is added. I set created SP as an admin of workspace. The following permissions for AAD app have been granted:&amp;nbsp;User.Read,&amp;nbsp;Content.Create,&amp;nbsp;Dashboard.ReadWrite.All,&amp;nbsp;Dataset.ReadWrite.All,&amp;nbsp;Gateway.ReadWrite.All,&amp;nbsp;Report.ReadWrite.All,&amp;nbsp;Report.ReadWrite.All.&amp;nbsp; When I'm using PowerBI cmdlets for Powershell everything looks fine, eg. the following code is working as expect.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$secret = $ClientKey | ConvertTo-SecureString -AsPlainText -Force 
$credential = New-Object -TypeName System.Management.Automation.PSCredential($ApplicationId, $secret) 
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $TenantId 
[...]
Remove-PowerBIReport -Id $ReportToDelete.Id -WorkspaceId $Workspace.Id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I'm trying to do the same using&amp;nbsp;Invoke-PowerBIRestMethod or Rest API sth is wrong:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$secret = $ClientKey | ConvertTo-SecureString -AsPlainText -Force 
$credential = New-Object -TypeName System.Management.Automation.PSCredential($ApplicationId, $secret) 
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $TenantId
$Headers = Get-PowerBIAccessToken 
[...] 
$Uri = 'https://api.powerbi.com/v1.0/myorg/reports/'+ $ReportToDelete.Id 
Invoke-PowerBIRestMethod -Url $Uri -Method Delete 
or 
Invoke-RestMethod -Uri $Uri -Headers $Headers -Method Delete&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error for&amp;nbsp;Invoke-PowerBIRestMethod: "One or more errors occurred. (Response status code does not indicate success: 403 (Forbidden).)"&lt;/P&gt;&lt;P&gt;Error for&amp;nbsp;Invoke-RestMethod:&amp;nbsp;"API is not accessible for application"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any ideas what's going on and what can be a problem? I need to use Rest API because PowerBI cmdlets for Powershell are not enough.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 11:22:57 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-09-30T11:22:57Z</dc:date>
    <item>
      <title>API error using service principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/API-error-using-service-principal/m-p/1404580#M25962</link>
      <description>&lt;P&gt;Hi. I'm trying to automate PowerBI report deployment and actions related with that. Due to organization policy I have to use service principal.&amp;nbsp;The service principal access in PowerBI is enabled and security group with created SP as a member is added. I set created SP as an admin of workspace. The following permissions for AAD app have been granted:&amp;nbsp;User.Read,&amp;nbsp;Content.Create,&amp;nbsp;Dashboard.ReadWrite.All,&amp;nbsp;Dataset.ReadWrite.All,&amp;nbsp;Gateway.ReadWrite.All,&amp;nbsp;Report.ReadWrite.All,&amp;nbsp;Report.ReadWrite.All.&amp;nbsp; When I'm using PowerBI cmdlets for Powershell everything looks fine, eg. the following code is working as expect.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$secret = $ClientKey | ConvertTo-SecureString -AsPlainText -Force 
$credential = New-Object -TypeName System.Management.Automation.PSCredential($ApplicationId, $secret) 
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $TenantId 
[...]
Remove-PowerBIReport -Id $ReportToDelete.Id -WorkspaceId $Workspace.Id&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I'm trying to do the same using&amp;nbsp;Invoke-PowerBIRestMethod or Rest API sth is wrong:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$secret = $ClientKey | ConvertTo-SecureString -AsPlainText -Force 
$credential = New-Object -TypeName System.Management.Automation.PSCredential($ApplicationId, $secret) 
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $TenantId
$Headers = Get-PowerBIAccessToken 
[...] 
$Uri = 'https://api.powerbi.com/v1.0/myorg/reports/'+ $ReportToDelete.Id 
Invoke-PowerBIRestMethod -Url $Uri -Method Delete 
or 
Invoke-RestMethod -Uri $Uri -Headers $Headers -Method Delete&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error for&amp;nbsp;Invoke-PowerBIRestMethod: "One or more errors occurred. (Response status code does not indicate success: 403 (Forbidden).)"&lt;/P&gt;&lt;P&gt;Error for&amp;nbsp;Invoke-RestMethod:&amp;nbsp;"API is not accessible for application"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any ideas what's going on and what can be a problem? I need to use Rest API because PowerBI cmdlets for Powershell are not enough.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 11:22:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/API-error-using-service-principal/m-p/1404580#M25962</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-30T11:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: API error using service principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/API-error-using-service-principal/m-p/1409505#M25974</link>
      <description>&lt;P&gt;It looks like the permissions issue. All the permissions granted in AAD I specified above. All the tenant permission in Power Bi Admin Portal are applied for the entire organization.&amp;nbsp;What can be missing?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 11:57:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/API-error-using-service-principal/m-p/1409505#M25974</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-02T11:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: API error using service principal</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/API-error-using-service-principal/m-p/2513755#M36090</link>
      <description>&lt;P&gt;I have exactly same issue&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 14:18:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/API-error-using-service-principal/m-p/2513755#M36090</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-05-13T14:18:07Z</dc:date>
    </item>
  </channel>
</rss>

