Showing results for 
Search instead for 
Did you mean: 
Helper II
Helper II

Automate importing PowerBI audit logs using Application or Service Principle - Python MSAL

Hi Guys

I wanted to share information about the automation of importing PowerBI audit logs using Application Permissions from PowerBI service right from App registration to using MSAL python library.

Since most of the company's we use multifactor authentication, delegated permissions will not allow any python/.net application to get automated. 



Application PermissionsApplication Permissions

The first thing we need to perform is registering an app in Azure portal or using app registration using following link


App Registration:

Perform app registration steps only as mentioned in the following blog ( and DO NOT set any permissions. Since these permissions didn't work while authenticating the token generated.



  1. After assigning Tenant.Read.All make sure you are Not accepting the admin consent as suggested by below documentation.

  1. Create Client Secret and keep this handy.


Making API calls using MSAL library:

  1. MSAL client secret example can be found here


  1. Create json parameter file(Parameters.json) with following configurations and endpoints

{    "authority": " you tenantID Here ",

    "client_id": "Enter ClientID of the app you have Registered",

    "scope": [""],

    "secret": "Enter Client Secret you created above",

    "endpoint": "$expand=datasets,dataflows,reports,dashboards,users&..."




  1. Install necessary MSAL library for Python using "pip install msal" in your command prompt
  2. You can get the code I have used to generate user activity data from git link. Even though I have mentioned an endpoint in the parameters file I am deriving my required user activity endpoint in the Python program since I have to generate several extracts with several endpoints and I want to use a single parameter file for all those extracts.


Note: There might be better ways to program in Python to extract the data from these API's but this is what I have developed which is working successfully.




Community Support
Community Support

Hi  @Sandeep3596 ,

Good idea. You can tag your own answers to the solution so that more people can see it and so you can help more people.


Best Regards


Helpful resources

Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!