<?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 PowerBI API Returns &amp;quot;PowerBINotAuthorizedException&amp;quot; despite permissions in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/PowerBI-API-Returns-quot-PowerBINotAuthorizedException-quot/m-p/2876779#M39516</link>
    <description>&lt;P&gt;Hi - I am trying to access the API to download usage statistics from PowerBI and integrate with other reports. When I run the below code&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="python"&gt;import requests
import json

base_url = "https://api.powerbi.com/v1.0/myorg/admin/"
url = "https://login.microsoftonline.com/my_tenant_id_goes_here/oauth2/token"
scope = "https://analysis.windows.net/powerbi/api/.default"
grant_type = "client_credentials"
client_id = "my_client_id"
client_secret = "my_client_secret"
resource = "https://analysis.windows.net/powerbi/api"

header = {
    "scope": scope,
    "grant_type": grant_type,
    "client_id": client_id,
    "client_secret": client_secret,
    "resource": resource
}

r = requests.post(url, data = header)
login_result = r.json()
print(login_result)

token_type = login_result.get("token_type")
access_token = login_result.get("access_token")

authorization_key = token_type + " " + access_token
print('Authentication Key Generated')
headers = {'Content-Type':'application/json','Authorization': authorization_key}
print('Consuming Dashboards Rest End Point')
data = requests.get(base_url + 'dashboards', headers=headers)
print(data)
json_data = data.content
print(json_data)&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;When I print login_result I get what seems to be a correct response.&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;{'token_type': 'Bearer', 'expires_in': '3599', 'ext_expires_in': '3599', 'expires_on': '1667296164', 'not_before': '1667292264', 'resource': 'https://analysis.windows.net/powerbi/api', 'access_token': 'longlongalphanumericstring'}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However when I print data I get a &amp;lt;401&amp;gt; error, and the json_data reads&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;b'{"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;&lt;BR /&gt;I have checked in Azure for the permissions. I have the Dashboard.Read.All permission.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ubersparky_0-1667294993315.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/814540i23B270CCB5D1E5D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ubersparky_0-1667294993315.png" alt="ubersparky_0-1667294993315.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Can anyone please let me know what I could be doing wrong?&lt;/P&gt;</description>
    <pubDate>Tue, 01 Nov 2022 09:31:26 GMT</pubDate>
    <dc:creator>ubersparky</dc:creator>
    <dc:date>2022-11-01T09:31:26Z</dc:date>
    <item>
      <title>PowerBI API Returns "PowerBINotAuthorizedException" despite permissions</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PowerBI-API-Returns-quot-PowerBINotAuthorizedException-quot/m-p/2876779#M39516</link>
      <description>&lt;P&gt;Hi - I am trying to access the API to download usage statistics from PowerBI and integrate with other reports. When I run the below code&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="python"&gt;import requests
import json

base_url = "https://api.powerbi.com/v1.0/myorg/admin/"
url = "https://login.microsoftonline.com/my_tenant_id_goes_here/oauth2/token"
scope = "https://analysis.windows.net/powerbi/api/.default"
grant_type = "client_credentials"
client_id = "my_client_id"
client_secret = "my_client_secret"
resource = "https://analysis.windows.net/powerbi/api"

header = {
    "scope": scope,
    "grant_type": grant_type,
    "client_id": client_id,
    "client_secret": client_secret,
    "resource": resource
}

r = requests.post(url, data = header)
login_result = r.json()
print(login_result)

token_type = login_result.get("token_type")
access_token = login_result.get("access_token")

authorization_key = token_type + " " + access_token
print('Authentication Key Generated')
headers = {'Content-Type':'application/json','Authorization': authorization_key}
print('Consuming Dashboards Rest End Point')
data = requests.get(base_url + 'dashboards', headers=headers)
print(data)
json_data = data.content
print(json_data)&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;When I print login_result I get what seems to be a correct response.&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;{'token_type': 'Bearer', 'expires_in': '3599', 'ext_expires_in': '3599', 'expires_on': '1667296164', 'not_before': '1667292264', 'resource': 'https://analysis.windows.net/powerbi/api', 'access_token': 'longlongalphanumericstring'}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However when I print data I get a &amp;lt;401&amp;gt; error, and the json_data reads&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;b'{"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;&lt;BR /&gt;I have checked in Azure for the permissions. I have the Dashboard.Read.All permission.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ubersparky_0-1667294993315.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/814540i23B270CCB5D1E5D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ubersparky_0-1667294993315.png" alt="ubersparky_0-1667294993315.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Can anyone please let me know what I could be doing wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 09:31:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PowerBI-API-Returns-quot-PowerBINotAuthorizedException-quot/m-p/2876779#M39516</guid>
      <dc:creator>ubersparky</dc:creator>
      <dc:date>2022-11-01T09:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: PowerBI API Returns "PowerBINotAuthorizedException" despite permissions</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/PowerBI-API-Returns-quot-PowerBINotAuthorizedException-quot/m-p/2878075#M39529</link>
      <description>&lt;P&gt;When you use the admin api you need to grant access to this in the tenant admin. Because you use service principal this need to be added in a security group, and this group needs to be granted admin api access in the tenant admin portal.&lt;/P&gt;&lt;P&gt;When this is done, I,ve experienced it can take up to 20-30 min before it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Br&lt;/P&gt;&lt;P&gt;Marius&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 19:07:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/PowerBI-API-Returns-quot-PowerBINotAuthorizedException-quot/m-p/2878075#M39529</guid>
      <dc:creator>mariussve1</dc:creator>
      <dc:date>2022-11-01T19:07:37Z</dc:date>
    </item>
  </channel>
</rss>

