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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.