Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
D_Lav
Helper I
Helper I

API is not accessible for application: Using Python to call Admin API and get App and DatasetUsers

Hi, 

 

I have created a synapse workspace with a lakehouse and notebooks that i use to retrieve Power BI information from my tenant. 

This include apps, workspaces, datasets, activity etc. hovewer, i want to retrieve dataset users and app users aswell. 

 

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, 

1. Allow Service principals to use Power BI APIs

2. Allow Service principals to use read-only admin APIs

3. Enhance admin APIs responses with detailed metadata

4. Enhance admin APIs responses with dax and mashup expressions

 

for this i tought i could use the following APIs 

https://learn.microsoft.com/en-us/rest/api/power-bi/admin/datasets-get-dataset-users-as-admin

https://learn.microsoft.com/en-us/rest/api/power-bi/admin/apps-get-app-users-as-admin 

 

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.

 

#Get a list of datasets

response_datasets = requests.get(uri_datasets,headers=headers)

 

#to loop over datasetIds and get dataset User from this API - Admin - Datasets GetDatasetUsersAsAdmin
if response_datasets.status_code == 200:
    result = response_datasets.json()['value']
    datasetUserList = []
    for item in result:
        uri_datasets = f'https://api.powerbi.com/v1.0/myorg/datasets/{item["id"]}/users'
        response_datasetsUser = requests.get(uri_datasets,headers=headers)
        df=pd.json_normalize(response_datasetsUser.json())
        df['dataset_id']=item['id']
        datasetUserList.append(df)
df_concat = pd.concat(datasetUserList)
df_concat = df_concat.reset_index(drop=True)
df_json = df_concat.to_json()
 
If i try to print out df_json i get the following message and no user information is returned. 
{"Message":{"0":"API is not accessible for application","1"
 
i looked at the documentation and saw this under Required Scope

Tenant.Read.All or Tenant.ReadWrite.All

Relevant only when authenticating via a standard delegated admin access token. Must not be present when authentication via a service principal is used.

 

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!

1 ACCEPTED SOLUTION
D_Lav
Helper I
Helper I

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:)

View solution in original post

1 REPLY 1
D_Lav
Helper I
Helper I

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:)

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.