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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
andymc
Frequent Visitor

Using a Service Principal for the Activity Events API

Hello,

 

I have been setting up a proof of concept on accessing Activity Events API using a Service Principal account.  I have worked out most of the issues but am currently getting the error code 401 and haven't been able to pinpoint the registered application setup as well as any permissions that are needed to be added. 

 

I have followed multiple articles outlining the setup and have hopefully summarized well enough below.  But any feedback would be greatly appreciated.

 

I have started out with the Daemon Application code from the .Net Core Quick Start Code in the Azure Application Setup.

 

I am able to get authenticated correctly, using the Client Secret.  I have also confirmed that I can successfully issue my GET against the User.Read API in Microsoft.Graph.

 

When I switched the resource and call over to Power Bi I am now getting a 401 error.

 

For the call my resource is: https://analysis.windows.net/powerbi/api/.default

The call I am trying to issue is: 

https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime={startTime}&endDateTime={endTi...

 

The application permissions setup are

App Configured Permissions.jpg

 

I have setup a Security Group (PowerBiTestSecrurityGroup) in Azure with the Application Service Principal setup as a member.

 

Lastly I have gone into Power Bi and enabled the Admin API Settings for that security group.

 

Powr Bi Security Settings.JPG

 

At this point I was really hoping to identify any final adjustments that are needed to execute this call using a Daemon Application.

 

 

1 ACCEPTED SOLUTION

After a lot of trial and error I have finally solved the issue.  I am not entirely certain why this is the case but when I remove all references to Power BI API calls from Azure API Permissions setup in the Azure App Registration the call works.  

 

API Permissions.jpg

View solution in original post

4 REPLIES 4
mbutler71
Advocate I
Advocate I

This does actually work. I also removed all of the permissions of a Service Principal I wasn't using and tried to call the Power BI Admin Activity Events API, and it got back the report usage data.

v-shex-msft
Community Support
Community Support

HI @andymc,

AFAIK, these logs are pull from audit logs, have you enable this feature before the test?

Track user activities in Power BI - Power BI | Microsoft Docs

In addition, this is one of the admin rest API. it was different from common rest APIs and it requires additional admin permission to use.

For this scenario, I'd like to suggest you check the test account settings to confirm it has enough permissions.

The user must have administrator rights (such as Office 365 Global Administrator or Power BI Service Administrator) to call this API or authenticate via service principal.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

After a lot of trial and error I have finally solved the issue.  I am not entirely certain why this is the case but when I remove all references to Power BI API calls from Azure API Permissions setup in the Azure App Registration the call works.  

 

API Permissions.jpg

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.