<?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 &amp;quot;Get Activity Events&amp;quot; REST API only returns 1 entry at a time in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/quot-Get-Activity-Events-quot-REST-API-only-returns-1-entry-at-a/m-p/3435263#M44497</link>
    <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;I am using the "Get Activity Events" REST API in order to extract and archive audit logs. I am using the API according to this documentation [1]. I am using a service principal and I believe I have given it all the necessary rights in the Admin portal.&lt;/P&gt;&lt;P&gt;The REST API works, but it only gives me 1 entry at a time - together with a continuation token (see screenshot below). If I use the continuation token I get another single entry with another continuation token.&lt;/P&gt;&lt;P&gt;According to [2] the API should return 5000-10000 entries at a time, which seems more reasonable.&lt;/P&gt;&lt;P&gt;Does anyone have an idea what could cause this? Minimal code is as in [3].&lt;/P&gt;&lt;P&gt;Very grateful for any hints!&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;Alex&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[1]&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events&lt;/A&gt;&lt;/P&gt;&lt;P&gt;[2]&amp;nbsp;&lt;A href="https://powerbi.microsoft.com/de-ch/blog/the-power-bi-activity-log-makes-it-easy-to-download-activity-data-for-custom-usage-reporting/" target="_blank" rel="noopener"&gt;https://powerbi.microsoft.com/de-ch/blog/the-power-bi-activity-log-makes-it-easy-to-download-activity-data-for-custom-usage-reporting/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;[3]&amp;nbsp;&lt;BR /&gt;$bearer_token="MY_BEARER_TOKEN"&lt;/P&gt;&lt;P&gt;$postParams = @{&lt;BR /&gt;&amp;nbsp;"Authorization"="Bearer $bearer_token"&lt;BR /&gt;&amp;nbsp;}&lt;BR /&gt;$url_get_logs = "&lt;A href="https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2023-09-11T00:00:00'&amp;amp;endDateTime='2023-09-11T23:59:59" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2023-09-11T00:00:00'&amp;amp;endDateTime='2023-09-11T23:59:59&lt;/A&gt;'"&lt;BR /&gt;$response = Invoke-RestMethod -Uri $url_get_logs -Method get -Headers $postParams&lt;BR /&gt;$response | ConvertTo-Json&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="alexschindler_0-1695013614696.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/969855iF61EDBCFD5DAFE44/image-size/medium?v=v2&amp;amp;px=400" role="button" title="alexschindler_0-1695013614696.png" alt="alexschindler_0-1695013614696.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Sep 2023 05:09:14 GMT</pubDate>
    <dc:creator>alexschindler</dc:creator>
    <dc:date>2023-09-18T05:09:14Z</dc:date>
    <item>
      <title>"Get Activity Events" REST API only returns 1 entry at a time</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/quot-Get-Activity-Events-quot-REST-API-only-returns-1-entry-at-a/m-p/3435263#M44497</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;I am using the "Get Activity Events" REST API in order to extract and archive audit logs. I am using the API according to this documentation [1]. I am using a service principal and I believe I have given it all the necessary rights in the Admin portal.&lt;/P&gt;&lt;P&gt;The REST API works, but it only gives me 1 entry at a time - together with a continuation token (see screenshot below). If I use the continuation token I get another single entry with another continuation token.&lt;/P&gt;&lt;P&gt;According to [2] the API should return 5000-10000 entries at a time, which seems more reasonable.&lt;/P&gt;&lt;P&gt;Does anyone have an idea what could cause this? Minimal code is as in [3].&lt;/P&gt;&lt;P&gt;Very grateful for any hints!&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;Alex&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[1]&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events&lt;/A&gt;&lt;/P&gt;&lt;P&gt;[2]&amp;nbsp;&lt;A href="https://powerbi.microsoft.com/de-ch/blog/the-power-bi-activity-log-makes-it-easy-to-download-activity-data-for-custom-usage-reporting/" target="_blank" rel="noopener"&gt;https://powerbi.microsoft.com/de-ch/blog/the-power-bi-activity-log-makes-it-easy-to-download-activity-data-for-custom-usage-reporting/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;[3]&amp;nbsp;&lt;BR /&gt;$bearer_token="MY_BEARER_TOKEN"&lt;/P&gt;&lt;P&gt;$postParams = @{&lt;BR /&gt;&amp;nbsp;"Authorization"="Bearer $bearer_token"&lt;BR /&gt;&amp;nbsp;}&lt;BR /&gt;$url_get_logs = "&lt;A href="https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2023-09-11T00:00:00'&amp;amp;endDateTime='2023-09-11T23:59:59" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2023-09-11T00:00:00'&amp;amp;endDateTime='2023-09-11T23:59:59&lt;/A&gt;'"&lt;BR /&gt;$response = Invoke-RestMethod -Uri $url_get_logs -Method get -Headers $postParams&lt;BR /&gt;$response | ConvertTo-Json&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="alexschindler_0-1695013614696.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/969855iF61EDBCFD5DAFE44/image-size/medium?v=v2&amp;amp;px=400" role="button" title="alexschindler_0-1695013614696.png" alt="alexschindler_0-1695013614696.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 05:09:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/quot-Get-Activity-Events-quot-REST-API-only-returns-1-entry-at-a/m-p/3435263#M44497</guid>
      <dc:creator>alexschindler</dc:creator>
      <dc:date>2023-09-18T05:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: "Get Activity Events" REST API only returns 1 entry at a time</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/quot-Get-Activity-Events-quot-REST-API-only-returns-1-entry-at-a/m-p/3439379#M44553</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/530792"&gt;@alexschindler&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;If I understand correctly,&amp;nbsp;&lt;SPAN&gt;you can only get one entry when calling the "Get Activity Events" REST API using a service principal and a continuation token. And you want to know the cause. In order to make troubleshooting, could you please try the following things:&lt;/SPAN&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;STRONG&gt;Check the query parameters:&lt;/STRONG&gt; Make sure that the query parameters you specified in the API call are correct and match the events you are trying to retrieve. As checked the info in the screenshot, the date range is between '2023-9-11 00:00:00' and&amp;nbsp;'2023-9-11 23:59:59', please refer &lt;A href="https://learn.microsoft.com/en-us/power-bi/admin/service-admin-auditing#search-power-bi-activities" target="_self"&gt;this link&lt;/A&gt; to check and confirm the events info of that date .&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;STRONG&gt;Check the continuation token:&lt;/STRONG&gt; Double-check the continuation token to ensure that it is being passed correctly in the API call. &lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;STRONG&gt;Test with different parameters:&lt;/STRONG&gt; Try testing the API call with different query parameters to see if you get the expected results.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;&lt;STRONG&gt;&lt;STRONG&gt;Using Powersell:&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vyiruanmsft_0-1695192256300.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/970959iA63560E53A00435F/image-size/large?v=v2&amp;amp;px=999" role="button" title="vyiruanmsft_0-1695192256300.png" alt="vyiruanmsft_0-1695192256300.png" /&gt;&lt;/span&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 06:45:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/quot-Get-Activity-Events-quot-REST-API-only-returns-1-entry-at-a/m-p/3439379#M44553</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-09-20T06:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: "Get Activity Events" REST API only returns 1 entry at a time</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/quot-Get-Activity-Events-quot-REST-API-only-returns-1-entry-at-a/m-p/3439413#M44555</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@v-yiuran-msft&lt;/P&gt;&lt;P&gt;Thanks for your answer.&lt;/P&gt;&lt;P&gt;- I think the query parameters are correct. I am trying to get the events from a whole day. There is more than 1 entry per day.&lt;/P&gt;&lt;P&gt;- I'm not sure about the continuation token: the problem is alreay with the very first request. I would expect that the first request gives me 5000-10000 entries.&lt;/P&gt;&lt;P&gt;- I tried using different days. On one of the days I got 2 entries instead of 1, but still ...&lt;/P&gt;&lt;P&gt;- I also tried the PowerBI commandlet (Get-PowerBIActivityEvent) this works great. However, I would like to use the REST API with a service principal, so the commandlet is not an option for me.&lt;/P&gt;&lt;P&gt;Any other ideas about the REST API?&lt;/P&gt;&lt;P&gt;I was also wondering if it could have to do with the scope of the token. I am using:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;scope='https://analysis.windows.net/powerbi/api/.default'&lt;/LI-CODE&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 07:01:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/quot-Get-Activity-Events-quot-REST-API-only-returns-1-entry-at-a/m-p/3439413#M44555</guid>
      <dc:creator>alexschindler</dc:creator>
      <dc:date>2023-09-20T07:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: "Get Activity Events" REST API only returns 1 entry at a time</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/quot-Get-Activity-Events-quot-REST-API-only-returns-1-entry-at-a/m-p/3449243#M44695</link>
      <description>&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;Found a solution ... and documenting it for posternity. I tried to go all the way and see what happens if I keep using the continuation token with a while loop.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;$url_get_logs = "https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2023-09-01T00:00:00'&amp;amp;endDateTime='2023-09-01T09:59:59'"
$response = Invoke-RestMethod -Uri $url_get_logs -Method get -Headers $postParams
$completeListOfActivityEvents = @()
$completeListOfActivityEvents += $response.ActivityEventEntities
$continuationToken = $response.continuationToken
$continuationUri = $response.continuationUri
while ($ContinuationToken -ne $null)
{
  $response = Invoke-RestMethod -Uri $continuationUri -Method get  -Headers $postParams
  $continuationUri = $response.continuationUri
  $continuationToken = $response.continuationToken
  $completeListOfActivityEvents += $response.ActivityEventEntities
}&lt;/LI-CODE&gt;&lt;P&gt;Turns out this REST API is quite whimsical. Very stingy at the beginning – and then it starts going. It gave me 1 entry, then another 1, then 4, then 10, then 33, then 523, ...&lt;/P&gt;&lt;P&gt;So everything ok at the end ... but I feel like it would be good if this behaviour was documented.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Alex&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="alexschindler_0-1695802593847.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/973798i6509CDA7FA006627/image-size/medium?v=v2&amp;amp;px=400" role="button" title="alexschindler_0-1695802593847.png" alt="alexschindler_0-1695802593847.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 08:20:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/quot-Get-Activity-Events-quot-REST-API-only-returns-1-entry-at-a/m-p/3449243#M44695</guid>
      <dc:creator>alexschindler</dc:creator>
      <dc:date>2023-09-27T08:20:50Z</dc:date>
    </item>
  </channel>
</rss>

