<?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: Issue with Power BI Admin API 'Get Activity Events' Call using Python F-String and Token Handlin in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4827158#M12352</link>
    <description>&lt;P&gt;&lt;SPAN&gt;May I ask if you have resolved this issue?&amp;nbsp; We would like to confirm if our community member&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/87706"&gt;@anilgavhane&lt;/a&gt;&amp;nbsp; answer resolves your query or if you need further help&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If we don’t hear back, we’ll go ahead and close this thread. For any further discussions or questions, please start a new thread in the Microsoft Fabric Community Forum we’ll be happy to assist.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for being part of the Microsoft Fabric Community.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Sep 2025 07:04:03 GMT</pubDate>
    <dc:creator>v-prasare</dc:creator>
    <dc:date>2025-09-16T07:04:03Z</dc:date>
    <item>
      <title>Issue with Power BI Admin API 'Get Activity Events' Call using Python F-String and Token Handling</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4778919#M11317</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I'm trying to use the Power BI Admin API to retrieve activity events from the past two days using Python. I'm dynamically generating the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;startDateTime&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;endDateTime&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;parameters using&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;datetime.utcnow()&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and formatting them into the required ISO 8601 format. Here is the link to the documentation: &lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events#get-audit-activity-events-within-a-time-window-example" target="_blank" rel="noopener"&gt;Get Activity Events Within Window.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
from datetime import datetime, timedelta

if "access_token" in token:
    access_token = token["access_token"]
    end_time = datetime.utcnow()
    start_time = end_time - timedelta(days=2)

    start_str = start_time.strftime('%Y-%m-%dT%H:%M:%S.000Z')
    end_str = end_time.strftime('%Y-%m-%dT%H:%M:%S.000Z')

    url = f"https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime={start_str}&amp;amp;endDateTime={end_str}"

    headers = {
        "Authorization": f"Bearer {access_token}"
    }

    response = requests.get(url, headers=headers)

    if response.status_code == 200:
        print("it worked")
    else:
        print("it didn't work")
        print(response.status_code)
        print(response.text)
        print(start_str)
        print(end_str)&lt;/LI-CODE&gt;&lt;P&gt;For some reason it continues to give me a status code as 400 or it tells me that the startDateTime and the endDateTime are invalid. Any guidance or examples of working implementations would be greatly appreaciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advanced&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jul 2025 16:00:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4778919#M11317</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-07-28T16:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Power BI Admin API 'Get Activity Events' Call using Python F-String and Token Handlin</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4794484#M11677</link>
      <description>&lt;P&gt;The format of the dates is probably incorrect. Try using Powershell and see if that works. Then, work on formatting the dates correctly in notebook.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2025 12:36:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4794484#M11677</guid>
      <dc:creator>Thomaslleblanc</dc:creator>
      <dc:date>2025-08-12T12:36:09Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Power BI Admin API 'Get Activity Events' Call using Python F-String and Token Handlin</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4800545#M11805</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;We would like to confirm if our community members answer resolves your query or if you need further help. If you still have any questions or need more support, please feel free to let us know. We are happy to help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Prashanth Are&lt;/P&gt;</description>
      <pubDate>Tue, 19 Aug 2025 06:35:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4800545#M11805</guid>
      <dc:creator>v-prasare</dc:creator>
      <dc:date>2025-08-19T06:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Power BI Admin API 'Get Activity Events' Call using Python F-String and Token Handlin</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4810427#M12022</link>
      <description>&lt;P&gt;We would like to confirm if our community members answer resolves your query or if you need further help. If you still have any questions or need more support, please feel free to let us know. We are happy to help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your patience and look forward to hearing from you.&lt;BR /&gt;Best Regards,&lt;BR /&gt;Prashanth Are&lt;/P&gt;</description>
      <pubDate>Thu, 28 Aug 2025 13:14:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4810427#M12022</guid>
      <dc:creator>v-prasare</dc:creator>
      <dc:date>2025-08-28T13:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Power BI Admin API 'Get Activity Events' Call using Python F-String and Token Handlin</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4820077#M12194</link>
      <description>&lt;P&gt;May I ask if you have resolved this issue? If so, Can you please share the resolution steps here. This will be helpful for other community members who have similar problems to solve it faster.&lt;BR /&gt;If we don’t hear back, we’ll go ahead and close this thread. For any further discussions or questions, please start a new thread in the Microsoft Fabric Community Forum we’ll be happy to assist.&lt;BR /&gt;Thank you for being part of the Microsoft Fabric Community.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 12:35:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4820077#M12194</guid>
      <dc:creator>v-prasare</dc:creator>
      <dc:date>2025-09-08T12:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Power BI Admin API 'Get Activity Events' Call using Python F-String and Token Handlin</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4820221#M12200</link>
      <description>&lt;P&gt;&lt;!--  StartFragment   --&gt;&lt;/P&gt;&lt;P&gt;@Anonymous&lt;/a&gt;&amp;nbsp;You're running into a common issue with the &lt;STRONG&gt;Power BI Admin API's Get Activity Events&lt;/STRONG&gt; endpoint. The key problem is that this API &lt;STRONG&gt;only supports querying one day at a time&lt;/STRONG&gt;—not a range of multiple days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What’s Causing the 400 Error&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The API expects:&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;startDateTime and endDateTime to be &lt;STRONG&gt;on the same calendar day&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;Both in &lt;STRONG&gt;UTC ISO 8601 format&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;You’re passing a &lt;STRONG&gt;2-day range&lt;/STRONG&gt;, which violates the API’s constraints&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to Fix It&lt;/P&gt;&lt;P&gt;Update your code to loop through each day individually. Here’s a quick fix:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from datetime import datetime, timedelta import requests if "access_token" in token: access_token = token["access_token"] headers = { "Authorization": f"Bearer {access_token}" } for i in range(2): # Loop through past 2 days day = datetime.utcnow() - timedelta(days=i) start_str = day.strftime('%Y-%m-%dT00:00:00.000Z') end_str = day.strftime('%Y-%m-%dT23:59:59.000Z') url = f"&lt;A href="https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime={start_str}&amp;amp;endDateTime={end_str" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime={start_str}&amp;amp;endDateTime={end_str&lt;/A&gt;}" response = requests.get(url, headers=headers) print(f"Day {i+1}: {response.status_code}") if response.status_code == 200: print("Success") else: print("Failed") print(response.text)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Pro Tips&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Make sure your app has &lt;STRONG&gt;AuditLog.Read.All&lt;/STRONG&gt; permission&lt;/LI&gt;&lt;LI&gt;Use &lt;STRONG&gt;UTC time&lt;/STRONG&gt; and avoid local timezone offsets&lt;/LI&gt;&lt;LI&gt;Consider paginating results if the volume is high&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;You can find more details in this &lt;A href="https://community.fabric.microsoft.com/t5/Developer/Power-BI-REST-API-Admin-Get-Activity-Events-error-400/m-p/2254564" target="_blank" rel="noopener"&gt;Microsoft Fabric Community thread&lt;/A&gt; and &lt;A href="https://stackoverflow.com/questions/75742033/get-401-error-when-try-to-get-power-bi-activity-events-audit-logs" target="_blank" rel="noopener"&gt;Stack Overflow discussion&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;!--  EndFragment   --&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 14:36:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4820221#M12200</guid>
      <dc:creator>anilgavhane</dc:creator>
      <dc:date>2025-09-08T14:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Power BI Admin API 'Get Activity Events' Call using Python F-String and Token Handlin</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4827158#M12352</link>
      <description>&lt;P&gt;&lt;SPAN&gt;May I ask if you have resolved this issue?&amp;nbsp; We would like to confirm if our community member&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/87706"&gt;@anilgavhane&lt;/a&gt;&amp;nbsp; answer resolves your query or if you need further help&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If we don’t hear back, we’ll go ahead and close this thread. For any further discussions or questions, please start a new thread in the Microsoft Fabric Community Forum we’ll be happy to assist.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for being part of the Microsoft Fabric Community.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Sep 2025 07:04:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4827158#M12352</guid>
      <dc:creator>v-prasare</dc:creator>
      <dc:date>2025-09-16T07:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with Power BI Admin API 'Get Activity Events' Call using Python F-String and Token Handlin</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4827725#M12367</link>
      <description>&lt;P&gt;Both the startDateTime and endDateTime query parameters must both be in the same UTC day and also be enclosed in single quotes.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Sep 2025 16:18:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Issue-with-Power-BI-Admin-API-Get-Activity-Events-Call-using/m-p/4827725#M12367</guid>
      <dc:creator>DaveMaiden</dc:creator>
      <dc:date>2025-09-16T16:18:00Z</dc:date>
    </item>
  </channel>
</rss>

