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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.