Forum Discussion
how to get data about users from powerbi rest api without been administrator
- 1 year ago
Thank you for this overview.
I still have a question when you say :
"Set up a separate service principal account with the required role and permissions, and use that identity for your API calls."
I do not understand beacause when a make ma api call, i use my service principal informations to get data.Here this is my python witch give me the token :
import msalimport requestsimport pandas as pd# === Paramètres ===TENANT_ID = 'my tenant id'CLIENT_ID = 'my client id of my enterprise application'CLIENT_SECRET = 'My secret '# === Authentification ===def get_graph_access_token():app = msal.ConfidentialClientApplication(client_id=CLIENT_ID,client_credential=CLIENT_SECRET)result = app.acquire_token_for_client(scopes=GRAPH_SCOPE)if "access_token" in result:return result['access_token']else:raise Exception(f"Échec de l'authentification : {result}")# === Script principal ===if __name__ == "__main__":token = get_graph_access_token()With this a can get data for microsoft graph api in is v1.0 version but for the auditlog i need to use the beta version and at this time i receive a error.
So if i understand i receive a token witch is connecting to my service principal so in this case a should not have error of permissions ?
Do i understand correct ?
If not coult you give me the solution to use my service principal correcty ?
Thank you Poojara_D12 - 1 year ago
HI Toi69___ ,
I have included the previously resolved thread and learning documents. They may help you resolve the issue
We truly appreciate your continued engagement and thank you for being an active and valued member of the community.
If you're still experiencing any challenges, please don’t hesitate to reach out we’d be more than happy to assist you further.
We look forward to hearing from you.
Best regards,
LakshmiSolved: Re: Extracting power BI Usage logs without powerBI... - Microsoft Fabric Community
Microsoft Graph permissions reference - Microsoft Graph | Microsoft Learn
Hi Toi69___
You're attempting to access Power BI activity events or audit logs using the Power BI REST API or Microsoft Graph API by leveraging an Azure AD app registration with a service principal and secret. You've correctly assigned both delegated and application-level permissions such as AuditLog.Read.All, Directory.Read.All, Report.Read.All, and Tenant.Read.All, which are required to query audit and activity data. However, despite this setup, you're encountering errors when trying to retrieve the activity data, and the key limitation here is that you do not hold an administrator role in your tenant.
This is important because accessing audit logs—whether through the Power BI REST API (GetActivityEvents) or Microsoft Graph API (/auditLogs)—requires elevated privileges that only users in certain administrative roles can exercise. Specifically, you need to be assigned a role such as Global Administrator, Compliance Administrator, Security Administrator, or Report Reader with audit log access. Without this, even though your app technically has the required API permissions, the underlying user context or service principal identity is not authorized to access tenant-level audit data.
In summary, the error you’re facing is due to insufficient directory-level permissions tied to your role, not just the API permissions in Azure. To resolve this, you’ll need to request that a tenant administrator either:
Assign you an appropriate admin role (like Compliance Admin), or
Set up a separate service principal account with the required role and permissions, and use that identity for your API calls.
Without admin role privileges, Microsoft blocks access to sensitive logs for security and compliance reasons, regardless of the app permissions granted in Azure AD.
Thank you for this overview.
I still have a question when you say :
"Set up a separate service principal account with the required role and permissions, and use that identity for your API calls."
I do not understand beacause when a make ma api call, i use my service principal informations to get data.
Here this is my python witch give me the token :
So if i understand i receive a token witch is connecting to my service principal so in this case a should not have error of permissions ?
Do i understand correct ?
If not coult you give me the solution to use my service principal correcty ?
Thank you Poojara_D12