Register an App to access Power BI Rest API (Get Activity Events)

HK Power Platform Admin
2 min readMay 30, 2024

In order to check the usage of Power BI reports, we can download the Audit log data thru API.

The official documentation: Admin — Get Activity Events — REST API (Power BI Power BI REST APIs) | Microsoft Learn

I am not sure why Microsoft make the document so difficult to understand. You can ignore that and read my summary below.

Register an App (Service Principal) to access Admin API

  1. Sign into the MS Entra Admin Center.
  2. Select App registration > New registration
  3. Input the name and other information of the new App, leave the permission blank.

Enable service principal authentication for read-only admin APIs — Microsoft Fabric | Microsoft Learn

Create a security group for Admin API access

  1. Create a security group (require Global admin permission)
  2. Add the Service Principal you created in previous step into this group
  3. (require Fabric admin permission) Goto Power BI Admin portal (https://app.powerbi.com/admin-portal/tenantSettings), under Admin Settings > Admin API settings > Service principals can access read-only admin APIs. Change to “Enable” and add the security group.

Common Error

Get 401 error without error message.

According to official document: When running under service principal authentication, an app must not have any admin-consent required permissions for Power BI set on it in the Azure portal.

It means you either the global admin, or you should not have any permission. To fix it, goto App Registration > API Permissions.

If all you need is getting the event log, then remove ALL permission that have “Admin consent required=Yes”.

Expected literal type token but found token / Your code is passing continuationToken without quotation mark

Use use the continuationUri instead of continuationToken in your POST request. The continuationUri contain entire Uri which save you the trouble to build your string with continuationToken.

Get 403 error: “API is not accessible for application”

Double check the “Create a security group for Admin API access” section above.

404 error

404 means file not find. It may means your App is trying to access a workspace that don’t have permission.

Goto Power BI portal (https://app.powerbi.com/), click on WorkSpaces, click the “…” at the right of target workspace, click on “Workspace access”. Add your security group with Admin permission here.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

HK Power Platform Admin
HK Power Platform Admin

Written by HK Power Platform Admin

Cannot find SharePoint job. Switched to Power Platform.

No responses yet

Write a response