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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Admin - Get Activity Events - Response code: 400

Hello,

 

I'm trying to get the API Rest Get Activity Events information on my tenant

I've made a small test on https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events using my account (am Azure admin and Power BI admin) but it seems there is a problem:

 

Samuel_Decideom_0-1727796128727.png

Samuel_Decideom_1-1727796153122.png

 

One of my coworkers tried this test on his client (where's he's not admin) and he gets en error 401 "Unauthorized", but I'm getting an error 400 “Bad Request”, why?

 

 

The Develeper settings in the Power BI tenant admin portal are correctly set:

Samuel_Decideom_2-1727796395236.png

 

As the Microsoft Azure App registration:

Samuel_Decideom_3-1727796529120.png

 

 

I also tryed to call the API using Postman with a generated Token, but it keeps saying PowerBINotAuthorizedException

 

Samuel_Decideom_4-1727796747682.png

 

Generating the Token:

Samuel_Decideom_5-1727796856937.png

 

Calling the activityevents:

Samuel_Decideom_6-1727796919919.png

 

Have I missed something?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from lbendlin , please allow me to provide another insight: 
Hi  @Anonymous ,

 

Based on the official documentation mentioned, "

When running under service prinicipal authentication, an app must not have any admin-consent required premissions for Power BI set on it in the Azure portal.", it means that all the Power BI permissions granted for this must be un-consent and removed for a new service principal AAD token to grant for the rest API running, as long as you have enabled this tenant admin setting

Admin - Get Activity Events - REST API (Power BI Power BI REST APIs) | Microsoft Learn

vyangliumsft_0-1728627220519.jpeg

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Cassie_9
New Member

Cassie_9_0-1741047596023.png

With same App registration config (delegated), I had the same activityEventEntities response 400 issue recently, it has been fixed by updating the date formatting. Try matching the date format of "CreationTime" to "2025-03-03T00:00:14".

Or anyone using Python can follow the code below:
date = (datetime.now() - timedelta(days=1)).date().strftime("%Y-%m-%d")
 
----- Python code Start -----
# define powerbi-api-secret
client_id = 'xxx'
tenant_id = 'xxx'
client_secret = dbutils.secrets.get(scope="xxx", key="xxx")
 
# define get_auth_token
def get_auth_token(tenant_id,client_id, client_secret😞
    credentials = ClientSecretCredential(
        client_id=client_id,
        client_secret=client_secret,
        tenant_id=tenant_id,
    )
    auth_token = credentials.get_token("https://analysis.windows.net/powerbi/api/.default").token
    return auth_token
 
 # test your activityEventEntities result use below
auth_token = get_auth_token(tenant_id, client_id, client_secret)
date = (datetime.now() - timedelta(days=1)).date().strftime("%Y-%m-%d")

url = f"https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='{date}T00:00:00'&endDateTime='{date}T23:59:59'"
headers = {'Authorization': f'Bearer {auth_token}'}
response = requests.get(url=url, headers=headers)
if response.status_code == 200:
    response_json = response.json()  
    print(f"Success {response.status_code}: {response.reason}\nTotal activityEventEntities: {len(response_json['activityEventEntities'])}")
    print(json.dumps(response_json, indent=4))  
else:
    print(f"Error {response.status_code}: {response.reason}")
----- Python code End -----
 
Cheers
Cass
Anonymous
Not applicable

Thanks for the reply from lbendlin , please allow me to provide another insight: 
Hi  @Anonymous ,

 

Based on the official documentation mentioned, "

When running under service prinicipal authentication, an app must not have any admin-consent required premissions for Power BI set on it in the Azure portal.", it means that all the Power BI permissions granted for this must be un-consent and removed for a new service principal AAD token to grant for the rest API running, as long as you have enabled this tenant admin setting

Admin - Get Activity Events - REST API (Power BI Power BI REST APIs) | Microsoft Learn

vyangliumsft_0-1728627220519.jpeg

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Permissions
The user must have administrator rights (such as Office 365 Global Administrator or Power BI Service Administrator) or authenticate using a service principal.
Delegated permissions are supported.
When running under service prinicipal authentication, an app must not have any admin-consent required premissions for Power BI set on it in the Azure portal.
Anonymous
Not applicable

Are you speaking about this, I can't turn it off?

 

Samuel_Decideom_0-1727852591078.png

 

 

I also tried those 2 options in Azure Portal but it ain't changing anything:

Samuel_Decideom_1-1727853456067.png

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.