<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get 401 Error when try to Get Activity Events (Audit Logs) in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/3138174#M41797</link>
    <description>&lt;P&gt;Thank you error disappear when i remove Tenant.ReadAll and Tenant.ReadWriteAll. It writted in documentation.&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events#permissions" target="_blank"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events#permissions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Mar 2023 08:18:14 GMT</pubDate>
    <dc:creator>VSmart</dc:creator>
    <dc:date>2023-03-17T08:18:14Z</dc:date>
    <item>
      <title>Get 401 Error when try to Get Activity Events (Audit Logs)</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/3132806#M41736</link>
      <description>&lt;P&gt;I'm trying to get Power BI audit logs using service principal.&lt;/P&gt;&lt;P&gt;I follow every step in creating Azure principal&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal#add-a-service-principal-or-security-group-by-using-powershell" target="_blank" rel="noopener"&gt;Embed Power BI content in an embedded analytics application with service principal and an application secret - Power BI | Microsoft Learn&lt;/A&gt;&lt;/P&gt;&lt;P&gt;1.Create app&lt;/P&gt;&lt;P&gt;2.Create secret&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Add app into group&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. Give all permitions to app&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Tenant.Read.All, Tenant.ReadWrite.All;&lt;/SPAN&gt;&lt;SPAN&gt;Report.ReadWrite.All, Report.Read.All, Dataset.Read.All;&lt;/SPAN&gt;&lt;SPAN&gt;Auditlog.Read.All; Workspace.Read.All;&lt;/SPAN&gt;&lt;SPAN&gt;Workspace.ReadWrite.All; and many other permitions.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;5. Enable "Allow service principal to use Power BI API's" and "Enable content in apps" in Power BI admin portal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can get acces token and run few API calls like :&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;"&lt;A href="https://api.powerbi.com/v1.0/myorg/groups" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups&lt;/A&gt;" and&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports&lt;/A&gt;"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;But when try to get&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;activity events&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;"&lt;A href="https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2023-02-13T07:55:00.000Z'&amp;amp;endDateTime='2023-02-13T08:55:00.000Z'&amp;amp;$filter=Activity" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2023-02-13T07:55:00.000Z'&amp;amp;endDateTime='2023-02-13T08:55:00.000Z'&amp;amp;$filter=Activity&lt;/A&gt;" and&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"&lt;A href="https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime=" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime=&lt;/A&gt;'" + activityDate + "T00:00:00'&amp;amp;endDateTime='" + activityDate + "T23:59:59'"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;SPAN&gt;- &lt;STRONG&gt;get 401 error&lt;/STRONG&gt;.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Or post this request "&lt;SPAN&gt;&lt;A href="https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/refreshes" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/datasets/{datasetId}/refreshes&lt;/A&gt;&lt;/SPAN&gt;" get 403 error.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;My Python script is follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;TENANT_ID = '1eb27ef3-976f-4600-a791-*******'
CLIENT_ID = 'd5376b05-a655-463b-ae9f-*******'
CLIENT_SECRET = '**************************'
SCOPE_BASE = ['https://analysis.windows.net/powerbi/api/.default']
AUTHORITY_URL = 'https://login.microsoftonline.com/organizations'
try:
    authority = AUTHORITY_URL.replace('organizations', TENANT_ID)
    clientapp = msal.ConfidentialClientApplication(CLIENT_ID, client_credential=CLIENT_SECRET, authority=authority)
    response = clientapp.acquire_token_for_client(scopes=SCOPE_BASE)
    try:
        access_token = response['access_token']
        activityDate = date.today() - timedelta(days=1)
        activityDate = activityDate.strftime("%Y-%m-%d")

        url = "https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='" + activityDate + "T00:00:00'&amp;amp;endDateTime='" + activityDate + "T23:59:59'"
        header = {'Content-Type':'application/json', 'Authorization':f'Bearer {access_token}'}
        api_call = requests.get(url=url, headers=header)
        print(api_call)
        print(api_call.json())

    except KeyError:
        raise Exception(response['error_description'])

except Exception as ex:
    raise Exception('Error retrieving Access token\n' + str(ex))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 07:55:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/3132806#M41736</guid>
      <dc:creator>VSmart</dc:creator>
      <dc:date>2023-03-15T07:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: Get 401 Error when try to Get Activity Events (Audit Logs)</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/3137738#M41791</link>
      <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="526822" data-lia-user-login="VSmart" class="lia-mention lia-mention-user"&gt;VSmart&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Perhaps you can take a look at the following link that mentions about the similar issues:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="https://community.powerbi.com/t5/Developer/Using-a-Service-Principal-for-the-Activity-Events-API/m-p/1936680" target="_blank"&gt;Solved: Using a Service Principal for the Activity Events ... - Microsoft Power BI Community&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 03:02:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/3137738#M41791</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-17T03:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Get 401 Error when try to Get Activity Events (Audit Logs)</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/3138174#M41797</link>
      <description>&lt;P&gt;Thank you error disappear when i remove Tenant.ReadAll and Tenant.ReadWriteAll. It writted in documentation.&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events#permissions" target="_blank"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events#permissions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 08:18:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/3138174#M41797</guid>
      <dc:creator>VSmart</dc:creator>
      <dc:date>2023-03-17T08:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Get 401 Error when try to Get Activity Events (Audit Logs)</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/3146569#M41866</link>
      <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;HI&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="526822" data-lia-user-login="VSmart" class="lia-mention lia-mention-user"&gt;VSmart&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;I'm glad to hear you find the root causing and share the resolution here, they will help others who faced the similar issues.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2023 08:13:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/3146569#M41866</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-03-22T08:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Get 401 Error when try to Get Activity Events (Audit Logs)</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/4814776#M62947</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="526822" data-lia-user-login="VSmart" class="lia-mention lia-mention-user"&gt;VSmart&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried this. Removed all the admin-consent required from API permissions. Still getting 401 error for activity events data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I have added my Service Principal security group in "&lt;SPAN&gt;Service principals can call Fabric public APIs" &amp;amp; "&lt;/SPAN&gt;Service principals can access read-only admin APIs" in PBI Service Admin portal,&lt;/LI&gt;&lt;LI&gt;Assigned Fabric Admin role to API security group&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But still getting 401 error for activity events. I'm able to get the reports/datasets list though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if I'm doing anything wrong.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2025 14:31:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-401-Error-when-try-to-Get-Activity-Events-Audit-Logs/m-p/4814776#M62947</guid>
      <dc:creator>PravinPCUK</dc:creator>
      <dc:date>2025-09-02T14:31:18Z</dc:date>
    </item>
  </channel>
</rss>

