<?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: App registration: Token only works for admin api in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/App-registration-Token-only-works-for-admin-api/m-p/4263303#M58073</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/194221"&gt;@h4tt3n&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can refer the following link to get it:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/grant-admin-consent?pivots=portal" target="_blank" rel="noopener"&gt;Grant tenant-wide admin consent to an application - Microsoft Entra ID | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;DIV id="tinyMceEditor_12e4c8fa1e49e9vyiruanmsft_0" class=""&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vyiruanmsft_1-1730269092557.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1191544i78C4F4CB83DFCE37/image-size/large?v=v2&amp;amp;px=999" role="button" title="vyiruanmsft_1-1730269092557.png" alt="vyiruanmsft_1-1730269092557.png" /&gt;&lt;/span&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 30 Oct 2024 06:19:00 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-10-30T06:19:00Z</dc:date>
    <item>
      <title>App registration: Token only works for admin api</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/App-registration-Token-only-works-for-admin-api/m-p/4254515#M57990</link>
      <description>&lt;P&gt;Ih all, hope you can help me with this.&lt;BR /&gt;&lt;BR /&gt;I have registered an app in Azure an use its tenant id, client id, an client secret to successfully access the Power BI admin api. However, shouldn't the same token grant me access to the other api's, such as dataset, group etc?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I keep getting 400 errors such as&amp;nbsp;"API is not accessible for application" when attempting to access any other than the admin api.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I missing?&lt;BR /&gt;&lt;BR /&gt;Here is my PS function for acquiring the token:&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;Function GetPowerBiServiceAdminApiToken 
{
    [CmdLetBinding()]
    Param 
    ( 
        [Parameter(Mandatory=$true, Position=0)] [string] $tenantId,
        [Parameter(Mandatory=$true, Position=1)] [string] $clientId,
        [Parameter(Mandatory=$true, Position=2)] [string] $clientSecret
    )

    $requestUri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"

    $requestBody = @{
        client_id     = $clientId
        client_secret = $clientSecret
        grant_type    = "client_credentials"
        scope         = "https://analysis.windows.net/powerbi/api/.default"
    }

    $tokenResponse = Invoke-RestMethod -Method Post -Uri $requestUri -ContentType "application/x-www-form-urlencoded" -Body $requestBody
    
    return $tokenResponse.access_token
}&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;&lt;BR /&gt;And here is a function for retrieving a dataset, which fails with the error message "API is not accessible for application" using the token retrieved above.&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;Function GetDataset
{
    [CmdLetBinding()]
    Param 
    ( 
        [Parameter(Mandatory=$true, Position=0)] [string] $token,
        [Parameter(Mandatory=$true, Position=1)] [string] $datasetId
    )

    $headers = @{
        Authorization = "Bearer $token"
    }
    
    $url = "https://api.powerbi.com/v1.0/myorg/datasets/$datasetId"
    
    $dataset = Invoke-RestMethod -Uri $url -Headers $headers

    return $dataset
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally, here is a function that gets all datasets through the admin api. It works perfectly using the token:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Function GetAllDatasetsAsAdmin
{
    [CmdLetBinding()]
    Param 
    ( 
        [Parameter(Mandatory=$true, Position=0)] [string] $token
    )

    $headers = @{
        Authorization = "Bearer $token"
    }
    
    $url = "https://api.powerbi.com/v1.0/myorg/admin/datasets"
    
    $datasets = Invoke-RestMethod -Uri $url -Headers $headers

    $datasetCustomObject = @()

    foreach ($dataset in $datasets.value) {
        
        $ds = New-Object PSObject -Property @{
            id        = $dataset.id
            name      = $dataset.name
            workspaceId = $dataset.workspaceId
        }
        
        $datasetCustomObject += $ds
    }
        
    return $datasetCustomObject
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Cheers, Mike&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 13:55:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/App-registration-Token-only-works-for-admin-api/m-p/4254515#M57990</guid>
      <dc:creator>h4tt3n</dc:creator>
      <dc:date>2024-10-23T13:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: App registration: Token only works for admin api</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/App-registration-Token-only-works-for-admin-api/m-p/4255406#M57997</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/194221"&gt;@h4tt3n&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Base on your description, it&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;sounds&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;like&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;you're&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;encountering&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;an&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;issue&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;with&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;API&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;access&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;permissions. The token works for admin-level REST API bt not for normal REST API. Please check if grant the proper API permission and grant admin consent to those permissions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1.&amp;nbsp;Go to Azure Portal, navigate to&amp;nbsp; Microsoft Entra ID -&amp;gt;&amp;nbsp; App registrations -&amp;gt; Find your registered app. Select&amp;nbsp; API permissions to add the neccessary API permission:&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Dataset.ReadWrite.All&lt;/EM&gt; &lt;/STRONG&gt;or &lt;EM&gt;&lt;STRONG&gt;Dataset.Read.All&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp;&lt;SPAN&gt;Grant admin consent to the above permissions&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vyiruanmsft_0-1729740627080.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1188295i27D123615928A871/image-size/large?v=v2&amp;amp;px=999" role="button" title="vyiruanmsft_0-1729740627080.png" alt="vyiruanmsft_0-1729740627080.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 03:31:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/App-registration-Token-only-works-for-admin-api/m-p/4255406#M57997</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-10-24T03:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: App registration: Token only works for admin api</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/App-registration-Token-only-works-for-admin-api/m-p/4255540#M57999</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are some noticeable differences between the menu in your screenshot and the menu I am presented with. The grant admin consent button is grayed out. Status column is empty. Also, there is a warning and notice at the top of the screen. I am unsure what to make of them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The full text of the "admin consent required" notice is:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The "Admin consent required" column shows the default value for an organization. However, user consent can be customized per permission, user, or app. This column may not reflect the value in your organization, or in organizations where this app will be used.&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://go.microsoft.com/fwlink/?linkid=2152292" target="_blank" rel="noopener"&gt;Learn more&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What are your thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2024-10-24 07_34_36-Power BI report upload tool - Microsoft Azure.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1188387iD5AEDFC8F848FC39/image-size/large?v=v2&amp;amp;px=999" role="button" title="2024-10-24 07_34_36-Power BI report upload tool - Microsoft Azure.png" alt="2024-10-24 07_34_36-Power BI report upload tool - Microsoft Azure.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers, Mike&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 06:07:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/App-registration-Token-only-works-for-admin-api/m-p/4255540#M57999</guid>
      <dc:creator>h4tt3n</dc:creator>
      <dc:date>2024-10-24T06:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: App registration: Token only works for admin api</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/App-registration-Token-only-works-for-admin-api/m-p/4263303#M58073</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/194221"&gt;@h4tt3n&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can refer the following link to get it:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/grant-admin-consent?pivots=portal" target="_blank" rel="noopener"&gt;Grant tenant-wide admin consent to an application - Microsoft Entra ID | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;DIV id="tinyMceEditor_12e4c8fa1e49e9vyiruanmsft_0" class=""&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vyiruanmsft_1-1730269092557.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1191544i78C4F4CB83DFCE37/image-size/large?v=v2&amp;amp;px=999" role="button" title="vyiruanmsft_1-1730269092557.png" alt="vyiruanmsft_1-1730269092557.png" /&gt;&lt;/span&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 30 Oct 2024 06:19:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/App-registration-Token-only-works-for-admin-api/m-p/4263303#M58073</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-10-30T06:19:00Z</dc:date>
    </item>
  </channel>
</rss>

