Forum Discussion
itsmebvk
3 years agoContinued Contributor
Power BI Admin API Report Refresh Issues
Hi Experts, I am trying to create an Power BI audit report as suggested some of the blogs mentioned below. Everything seems to be working in my desktop version, when I publish this report powe...
itsmebvk
3 years agoContinued Contributor
ibarrau agree with you. Can you please provide any blog or reference document which talks about this implementation using python .
Thanks in advance.
ibarrau
3 years agoSuper User
I think the doc is pretty straight forward.
https://github.com/ladataweb/SimplePBI
You can check how to get the token and use admin requests right there. Getting the activity logs it's an admin request. If you check the example using admin then just look for the correct method for the admin object "a" and capture the result in a variable. I think you can even convert the result from json to pandas (a library for dataframes) in the parameters. It gets a single day or the last 30 in a single line. It handles pagination.
I guess it would be like this:
from simplepbi import token
from simplepbi import admin
TENANT_ID = "XXXXXX"
power_bi_client_id = 'XXXXXX'
# Regular Login
power_bi_username = '[email protected]'
power_bi_password = 'XXXXXX'
tok = token.Token(tenant_id, app_client_id, username, password, None, use_service_principal=False)
# Service Principal Login
power_bi_secret = 'XXXXXX'
tok = token.Token(tenant_id, app_client_id, None, None, app_secret_key, use_service_principal=True)
# Create admin object
ad = admin.Admin(tok.token)
# Last day pandas response
frame_result = ad. get_activity_events_preview(activity_date="2023-05-03", return_pandas=True)
# Last 30 days pandas response
result = ad.get_activity_events_last_30_days_preview()
I hope that helps,