<?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: API is not accessible for application: Using Python to call Admin API and get App and DatasetUse in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/API-is-not-accessible-for-application-Using-Python-to-call-Admin/m-p/3622453#M48044</link>
    <description>&lt;P&gt;Edit: I solved this, it was a human error, when using chatGPT to clean up my code it was helpfull enough to change my API from Admin/ to regular. changing it back to admin API URL for Power BI solved the problem:)&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jan 2024 11:25:37 GMT</pubDate>
    <dc:creator>D_Lav</dc:creator>
    <dc:date>2024-01-08T11:25:37Z</dc:date>
    <item>
      <title>API is not accessible for application: Using Python to call Admin API and get App and DatasetUsers</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/API-is-not-accessible-for-application-Using-Python-to-call-Admin/m-p/3619297#M47787</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a synapse workspace with a lakehouse and notebooks that i use to retrieve Power BI information from my tenant.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This include apps, workspaces, datasets, activity etc. hovewer, i want to retrieve dataset users and app users aswell.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To access these APIs i have created an App in my Azure portal which i have added in AD group and provided access to the following settings in Admin Portal,&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Allow Service principals to use Power BI APIs&lt;/P&gt;&lt;P&gt;2. Allow Service principals to use read-only admin APIs&lt;/P&gt;&lt;P&gt;3. Enhance admin APIs responses with detailed metadata&lt;/P&gt;&lt;P&gt;4.&amp;nbsp;Enhance admin APIs responses with dax and mashup expressions&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for this i tought i could use the following APIs&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/datasets-get-dataset-users-as-admin" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/admin/datasets-get-dataset-users-as-admin&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/apps-get-app-users-as-admin" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/admin/apps-get-app-users-as-admin&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i do is that i first retrieve dataset IDs (this works) and then loop over these IDs with this Python code inside my notebook.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Get a list of datasets&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;uri_datasets = &lt;/SPAN&gt;&lt;SPAN&gt;'&lt;A href="https://api.powerbi.com/v1.0/myorg/admin/datasets?$top=5" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/admin/datasets?$top=5&lt;/A&gt;'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;response_datasets = requests.get(uri_datasets,&lt;/SPAN&gt;&lt;SPAN&gt;headers&lt;/SPAN&gt;&lt;SPAN&gt;=headers)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#to loop over datasetIds and get dataset User from this API - Admin - Datasets GetDatasetUsersAsAdmin&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; response_datasets.status_code == &lt;/SPAN&gt;&lt;SPAN&gt;200&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; result = response_datasets.json()[&lt;/SPAN&gt;&lt;SPAN&gt;'value'&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; datasetUserList = []&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;for&lt;/SPAN&gt;&lt;SPAN&gt; item &lt;/SPAN&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;SPAN&gt; result:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; uri_datasets = &lt;/SPAN&gt;&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;A href="https://api.powerbi.com/v1.0/myorg/datasets/" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/datasets/&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;item[&lt;/SPAN&gt;&lt;SPAN&gt;"id"&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;/users'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; response_datasetsUser = requests.get(uri_datasets,&lt;/SPAN&gt;&lt;SPAN&gt;headers&lt;/SPAN&gt;&lt;SPAN&gt;=headers)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; df=pd.json_normalize(response_datasetsUser.json())&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; df[&lt;/SPAN&gt;&lt;SPAN&gt;'dataset_id'&lt;/SPAN&gt;&lt;SPAN&gt;]=item[&lt;/SPAN&gt;&lt;SPAN&gt;'id'&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; datasetUserList.append(df)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_concat = pd.concat(datasetUserList)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_concat = df_concat.reset_index(&lt;/SPAN&gt;&lt;SPAN&gt;drop&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;True&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_json = df_concat.to_json()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;If i try to print out df_json i get the following message and no user information is returned.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{"Message":{"0":"API is not accessible for application","1"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;i looked at the documentation and saw this under&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Required Scope&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;Tenant.Read.All or Tenant.ReadWrite.All&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Relevant only when authenticating via a &lt;EM&gt;standard delegated admin access token&lt;/EM&gt;. Must not be present when authentication via a service principal is used&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have no idea what it means with standard delegated admin access token so if anyone could help me out and get this Python code running against this API i would be very glad!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 07 Jan 2024 12:25:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/API-is-not-accessible-for-application-Using-Python-to-call-Admin/m-p/3619297#M47787</guid>
      <dc:creator>D_Lav</dc:creator>
      <dc:date>2024-01-07T12:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: API is not accessible for application: Using Python to call Admin API and get App and DatasetUse</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/API-is-not-accessible-for-application-Using-Python-to-call-Admin/m-p/3622453#M48044</link>
      <description>&lt;P&gt;Edit: I solved this, it was a human error, when using chatGPT to clean up my code it was helpfull enough to change my API from Admin/ to regular. changing it back to admin API URL for Power BI solved the problem:)&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jan 2024 11:25:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/API-is-not-accessible-for-application-Using-Python-to-call-Admin/m-p/3622453#M48044</guid>
      <dc:creator>D_Lav</dc:creator>
      <dc:date>2024-01-08T11:25:37Z</dc:date>
    </item>
  </channel>
</rss>

