<?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: Power BI Get Activity REST API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3565155#M45621</link>
    <description>&lt;P&gt;According to Chris Webb you can only make this work with custom connectors, not with regular Power Query script.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2023 01:16:15 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2023-12-04T01:16:15Z</dc:date>
    <item>
      <title>Power BI Get Activity REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3564225#M45598</link>
      <description>&lt;P&gt;I had obtained this "code" from the BI Elite team via a very cool Youtube Series on how to build a Power BI Usage Repot.&lt;/P&gt;&lt;P&gt;This was working an jsut stopped some months ago.&lt;/P&gt;&lt;P&gt;(** is there a way to upload a file to this forum?&amp;nbsp; I can upload a PBIX file that has all the code that then would just need to be updated with specific app id/client secret and username/password credentials **)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble executing the Power BI admin REST APIs -&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;A href="https://api.powerbi.com/v1.0/myorg/admin/activityevents" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/admin/activityevents&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;A href="https://api.powerbi.com/v1.0/myorg/admin/admin/groups" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/admin/admin/groups&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to get an access token but when I then call the above REST APIs I get&amp;nbsp; an error:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Expression.Error: Access to the resource is forbidden.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the "code" i use.&amp;nbsp; This used to work ... and to get around this error I go to the Power BI Rest API pages and "try" the get activity events which asks me to login and then provides a bearer token.&amp;nbsp; I plug that token into my code rather than getting a token via the function i created ...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code in the Activity Table basically calls teh Get Activity Function and passes the returned value from the Get Access Token Function.&amp;nbsp; I know the Get access token function is returning a Token but seems that token does not work to call the Get Activity endpoint.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;FONT size="5"&gt;&lt;U&gt;&lt;STRONG&gt;Get Access Token FUNCTION&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;let&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; Source = () =&amp;gt;&lt;/DIV&gt;&lt;DIV&gt;let&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; body = "grant_type=password&amp;amp;resource=&lt;A href="https://graph.microsoft.com&amp;amp;" target="_blank"&gt;https://graph.microsoft.com&amp;amp;&lt;/A&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; username=USERNAME@MS365DOMAIN.com&amp;amp;password=PASSWORD&amp;amp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; client_id=MYCLIENT_ID&amp;amp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; secret_id=MY_SECRET_ID&amp;amp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; client_secret=MY_CLIENT_SECRET",&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; Data=Json.Document(Web.Contents("&lt;A href="https://login.microsoftonline.com/MY_TENNANT_ID/oauth2/token" target="_blank"&gt;https://login.microsoftonline.com/MY_TENNANT_ID/oauth2/token&lt;/A&gt;", [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content=Text.ToBinary(body)])),&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; access_token = Data[access_token]&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;in&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; access_token&lt;/DIV&gt;&lt;DIV&gt;in&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; Source&lt;/DIV&gt;&lt;DIV&gt;****************************************************************************&lt;/DIV&gt;&lt;DIV&gt;****************************************************************************&lt;/DIV&gt;&lt;DIV&gt;****************************************************************************&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Get Activity FUNCTION&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;let&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; Source = (accessToken as text, optional startDate as text, optional endDate as text, optional continuationToken as text, optional loop as number, optional data as list) =&amp;gt;&lt;/DIV&gt;&lt;DIV&gt;let&lt;/DIV&gt;&lt;DIV&gt;Source = Json.Document(Web.Contents("&lt;A href="https://api.powerbi.com/v1.0/myorg/" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/&lt;/A&gt;",&lt;/DIV&gt;&lt;DIV&gt;[&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; RelativePath=if loop = 0&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; then "admin/activityevents?startDateTime=" &amp;amp; startDate &amp;amp; "&amp;amp;endDateTime=" &amp;amp; endDate&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else "admin/activityevents?continuationToken='" &amp;amp; continuationToken &amp;amp; "'",&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; Headers=[Authorization="Bearer " &amp;amp; accessToken]&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;]&lt;/DIV&gt;&lt;DIV&gt;)),&lt;/DIV&gt;&lt;DIV&gt;token = Source[continuationToken],&lt;/DIV&gt;&lt;DIV&gt;currentData = Source[activityEventEntities],&lt;/DIV&gt;&lt;DIV&gt;appendedData = List.Combine({data, currentData}),&lt;/DIV&gt;&lt;DIV&gt;loopNum = loop + 1,&lt;/DIV&gt;&lt;DIV&gt;output =&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if token is null or loopNum &amp;gt; 100&lt;/DIV&gt;&lt;DIV&gt;then appendedData&lt;/DIV&gt;&lt;DIV&gt;else @#"GET Activity"(accessToken, "", "", token, loopNum, appendedData)&lt;/DIV&gt;&lt;DIV&gt;in&lt;/DIV&gt;&lt;DIV&gt;output&lt;/DIV&gt;&lt;DIV&gt;in&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; Source&lt;/DIV&gt;&lt;DIV&gt;****************************************************************************&lt;/DIV&gt;&lt;DIV&gt;****************************************************************************&lt;/DIV&gt;&lt;DIV&gt;****************************************************************************&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="5"&gt;&lt;U&gt;&lt;STRONG&gt;ACTIVITY TABLE&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;let&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Source = List.Dates,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Invoked FunctionSource" = Source(Date.AddDays(DateTime.Date(DateTime.FixedLocalNow()), -30), 30, #duration(1, 0, 0, 0)),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Converted to Table" = Table.FromList(#"Invoked FunctionSource", Splitter.SplitByNothing(), null, null, ExtraValues.Error),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Added Custom" = Table.AddColumn(#"Renamed Columns", "StartDate", each "'" &amp;amp; Date.ToText([Date], "YYYY-MM-DD") &amp;amp; "T00:00:00.000Z" &amp;amp; "'"),&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Added Custom1" = Table.AddColumn(#"Added Custom", "EndDate", each "'" &amp;amp; Date.ToText([Date], "YYYY-MM-DD") &amp;amp; "T23:59:59.999Z" &amp;amp; "'"),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Invoked Custom Function" = Table.AddColumn(#"Added Custom1", "GETActivity", each #&lt;STRONG&gt;"GET Activity"&lt;/STRONG&gt;(&lt;STRONG&gt;#"GET Access Token"()&lt;/STRONG&gt;, [StartDate], [EndDate], null, 0, {})),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Expanded GETActivity" = Table.ExpandListColumn(#"Invoked Custom Function", "GETActivity"),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Expanded GETActivity1" = Table.ExpandRecordColumn(#"Expanded GETActivity", "GETActivity",&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"Id", "RecordType", "CreationTime", "Operation", "OrganizationId", "UserType", "UserKey", "Workload", "UserId", "ClientIP", "UserAgent", "Activity", "ItemName", "WorkSpaceName", "DatasetName", "CapacityId", "CapacityName", "WorkspaceId", "ObjectId", "DatasetId", "DataConnectivityMode", "ArtifactId", "ArtifactName", "IsSuccess", "RequestId", "ActivityId", "RefreshType", "LastRefreshTime", "ArtifactKind", "RefreshEnforcementPolicy", "DataflowId", "DataflowName", "DataflowAccessTokenRequestParameters", "DataflowType", "CustomVisualAccessTokenResourceId", "CustomVisualAccessTokenSiteUri", "ImportId", "ImportSource", "ImportType", "ImportDisplayName", "ReportName", "ReportId", "ReportType", "DistributionMethod", "ConsumptionMethod"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;},&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;"Id", "RecordType", "CreationTime", "Operation", "OrganizationId", "UserType", "UserKey", "Workload", "UserId", "ClientIP", "UserAgent", "Activity", "ItemName", "WorkSpaceName", "DatasetName", "CapacityId", "CapacityName", "WorkspaceId", "ObjectId", "DatasetId", "DataConnectivityMode", "ArtifactId", "ArtifactName", "IsSuccess", "RequestId", "ActivityId", "RefreshType", "LastRefreshTime", "ArtifactKind", "RefreshEnforcementPolicy", "DataflowId", "DataflowName", "DataflowAccessTokenRequestParameters", "DataflowType", "CustomVisualAccessTokenResourceId", "CustomVisualAccessTokenSiteUri", "ImportId", "ImportSource", "ImportType", "ImportDisplayName", "ReportName", "ReportId", "ReportType", "DistributionMethod", "ConsumptionMethod"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Changed Type" = Table.TransformColumnTypes(#"Expanded GETActivity1",&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;{"Date", type date},{"StartDate", type text}, {"EndDate", type text}, {"Id", type text}, {"RecordType", Int64.Type}, {"CreationTime", type datetime}, {"Operation", type text}, {"OrganizationId", type text}, {"UserType", Int64.Type}, {"UserKey", type text}, {"Workload", type text}, {"UserId", type text}, {"ClientIP", type text}, {"UserAgent", type text}, {"Activity", type text}, {"ItemName", type text}, {"WorkSpaceName", type text}, {"DatasetName", type text}, {"ReportName", type text}, {"WorkspaceId", type text}, {"ObjectId", type text}, {"DatasetId", type text}, {"ReportId", type text}, {"IsSuccess", type logical}, {"ReportType", type text}, {"RequestId", type text}, {"ActivityId", type text}, {"DistributionMethod", type text}, {"ImportId", type any}, {"ImportSource", type any}, {"ImportType", type any}, {"ImportDisplayName", type any}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"StartDate", "EndDate"}),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Renamed Columns1" = Table.RenameColumns(#"Removed Columns",{{"UserId", "Email"}}),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Filtered Rows" = Table.SelectRows(#"Renamed Columns1", each ([Id] &amp;lt;&amp;gt; null))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;in&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#"Filtered Rows"&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 02 Dec 2023 14:59:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3564225#M45598</guid>
      <dc:creator>Ray_Brosius</dc:creator>
      <dc:date>2023-12-02T14:59:58Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Get Activity REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3565113#M45619</link>
      <description>&lt;P&gt;That's not how you are supposed to consume the activity reports.&amp;nbsp; Keep in mind they are ephemeral and will disappear after 30 days.&amp;nbsp; You are supposed to download the JSON extracts daily (via PowerShell), store them in a central repository and maybe feed a dataflow from the files - or read them in to datasets directly.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 00:22:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3565113#M45619</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-12-04T00:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Get Activity REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3565136#M45620</link>
      <description>&lt;P&gt;Thanks for your reply&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes I know that...&amp;nbsp; &amp;nbsp;we are working in parallel to build scripts to run a daily extrace and utilize our Snowflake instance to save.&amp;nbsp; &amp;nbsp;I put this "version" here as our first go around on this was to just get the last 30 days worth of Activity..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your response does not help solve the problem I posted.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The essence of the problem is that while I can get an Access Token, but that token does not&amp;nbsp; work as the bearer token when calling the Admin-Get Activity endpoint..&amp;nbsp; &amp;nbsp;If I go to the Power BI Rest API page&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events" target="_blank"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events&lt;/A&gt;&amp;nbsp;and "try"&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can take the Bearer token that is provided and plug it in to my Power BI code and it all works..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So why does that bearer token work and not the one from my code at the top here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This could be a problme with our Azure APP but hoping someone on here can comment if something has changed in the Authentication process / library to get a proper Access Token..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 00:46:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3565136#M45620</guid>
      <dc:creator>Ray_Brosius</dc:creator>
      <dc:date>2023-12-04T00:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Get Activity REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3565155#M45621</link>
      <description>&lt;P&gt;According to Chris Webb you can only make this work with custom connectors, not with regular Power Query script.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 01:16:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3565155#M45621</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-12-04T01:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Get Activity REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3566122#M45630</link>
      <description>&lt;P&gt;This used to work all by itself and I can make it work as I described by manually getting an Auth Token from the Power BI Rest API documentation pages by running it from there..&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And even then, the same "logic" and endpoints need to be used in Python code to get activity data from Powe BI..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 12:50:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3566122#M45630</guid>
      <dc:creator>Ray_Brosius</dc:creator>
      <dc:date>2023-12-04T12:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Get Activity REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3566514#M45633</link>
      <description>&lt;P&gt;when did it stop working all by itself?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 15:47:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3566514#M45633</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-12-04T15:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Get Activity REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3574398#M45705</link>
      <description>&lt;P&gt;I was able to solve the problem.&lt;/P&gt;&lt;P&gt;1) I setup the Azure APP to be a member of the security group that is configured in the PBI Admin Console to have access to the REST APIs&lt;/P&gt;&lt;P&gt;2) I have a PBI file that can go and get the last 30 days of activity, but as is mentioned here that was always just a rolling 30 day window.&amp;nbsp; IF that works for you then that is an option for sure..&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) I edited the "GET TOKEN" function to the below: ..&lt;/P&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;() =&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;let&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; body = " grant_type=client_credentials&amp;amp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;resource=&lt;A href="https://analysis.windows.net/powerbi/api&amp;amp;" target="_blank" rel="noopener"&gt;https://analysis.windows.net/powerbi/api&amp;amp;&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;client_id=CLIENT_ID&amp;amp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; username=USERNAME&amp;amp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;password=PASSWORD&amp;amp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; client_secret=CLIENT_SECRET",&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Data=Json.Document(&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Web.Contents("&lt;A href="https://login.microsoftonline.com/YOUR_TENNANT_ID/oauth2/token/" target="_blank" rel="noopener"&gt;https://login.microsoftonline.com/YOUR_TENNANT_ID/oauth2/token/",&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [ Headers=[#"Content-Type"="application/x-www-form-urlencoded"],&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Content=Text.ToBinary(body)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ])),&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;access_token = Data[access_token]&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;in&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&lt;FONT face="comic sans ms,sans-serif" size="2"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;access_token&lt;/FONT&gt;&lt;/FONT&gt;&lt;DIV&gt;&amp;nbsp;&lt;DIV&gt;4) Lastly and the key to this is I found an excellent source for the Python code to build a process that will get the activities from the day prior and save the results into a csv file.&amp;nbsp; I edited that code to save the data to our SNOWFLAKE database table.&lt;DIV&gt;&lt;A href="https://pbi-guy.com/2022/03/10/power-bi-and-activity-logs-with-python/" target="_blank" rel="noopener"&gt;https://pbi-guy.com/2022/03/10/power-bi-and-activity-logs-with-python/&lt;/A&gt;&lt;DIV&gt;&amp;nbsp;&lt;DIV&gt;here is the Python code .. you will need to replace with your parameters as appropriate.&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Import necessary libraries
import msal
import requests
import json
import pandas as pd
from datetime import date, timedelta
import snowflake.connector
import sqlalchemy

# Function to insert a row into the Snowflake table
def insert_row(row):
    sql_insert = f"INSERT INTO DATABASE.SCHEMA.TABLE(Id, RecordType, CreationTime, Operation, OrganizationId, UserType, UserKey, Workload, UserId, ClientIP, UserAgent, Activity, IsSuccess, RequestId, ActivityId, ItemName, WorkSpaceName, DatasetName, ReportName, WorkspaceId, ObjectId, DatasetId, ReportId, ReportType, DistributionMethod, ConsumptionMethod) VALUES ('{row['Id']}','{row['RecordType']}','{row['CreationTime']}','{row['Operation']}','{row['OrganizationId']}','{row['UserType']}','{row['UserKey']}','{row['Workload']}','{row['UserId']}','{row['ClientIP']}','{row['UserAgent']}','{row['Activity']}','{row['IsSuccess']}','{row['RequestId']}','{row['ActivityId']}','{row['ItemName']}','{row['WorkSpaceName']}','{row['DatasetName']}','{row['ReportName']}','{row['WorkspaceId']}','{row['ObjectId']}','{row['DatasetId']}','{row['ReportId']}','{row['ReportType']}','{row['DistributionMethod']}','{row['ConsumptionMethod']}')"
    cursor.execute(sql_insert)

#Set SnowFlake parameters and create Connection
con = snowflake.connector.connect(
    account="SNOWFLAKE ACCOUNT",
    user= "USER",
    password= "PASSWORD",
    warehouse= "WAREHOUSE",
    database= "DATABASE",
    schema= "SCHEMA"
    )

#Get yesterdays date and convert to string
activityDate = date.today() - timedelta(days=1)
activityDate = activityDate.strftime("%Y-%m-%d")

# Replace with your Azure AD app details
client_id = 'CLIENT_ID'
client_secret = 'CLIENT_SECRET'
tenant_id = 'TENNANT_ID'
authority_url = "https://login.microsoftonline.com/YOURDOMAIN"
scope = ["https://analysis.windows.net/powerbi/api/.default"]

#Set Power BI REST API to get Activities for today
url = "https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='" + activityDate + "T00:00:00'&amp;amp;endDateTime='" + activityDate + "T23:59:59'"


#Use MSAL to grab token
app = msal.ConfidentialClientApplication(client_id, authority=authority_url, client_credential=client_secret)
result = app.acquire_token_for_client(scopes=scope)

#Get latest Power BI Activities
if 'access_token' in result:
    access_token = result['access_token']
    header = {'Content-Type':'application/json', 'Authorization':f'Bearer {access_token}'}
    api_call = requests.get(url=url, headers=header)
    
    #Specify empty Dataframe with all columns
    column_names = ['Id', 'RecordType', 'CreationTime', 'Operation', 'OrganizationId', 'UserType', 'UserKey', 'Workload', 'UserId', 'ClientIP', 'UserAgent', 'Activity', 'IsSuccess', 'RequestId', 'ActivityId', 'ItemName', 'WorkSpaceName', 'DatasetName', 'ReportName', 'WorkspaceId', 'ObjectId', 'DatasetId', 'ReportId', 'ReportType', 'DistributionMethod', 'ConsumptionMethod']
    df = pd.DataFrame(columns=column_names)

    #Set continuation URL
    contUrl = api_call.json()['continuationUri']
    
    #Get all Activities for first hour, save to dataframe (df1) and append to empty created df
    result = api_call.json()['activityEventEntities']
    df1 = pd.DataFrame(result)
    pd.concat([df, df1])

    #Call Continuation URL as long as results get one back to get all activities through the day
    while contUrl is not None:        
        api_call_cont = requests.get(url=contUrl, headers=header)
        contUrl = api_call_cont.json()['continuationUri']
        result = api_call_cont.json()['activityEventEntities']
        df2 = pd.DataFrame(result)
        df = pd.concat([df, df2])
    
    #Set Cursor for Snowflake 
    cursor = con.cursor()  
    # Apply the function to each row of the DataFrame
    df.apply(insert_row, axis=1)
    
    # Commit the transaction to save the changes
    con.commit()
    con.close()
    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 12:47:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Get-Activity-REST-API/m-p/3574398#M45705</guid>
      <dc:creator>Ray_Brosius</dc:creator>
      <dc:date>2023-12-08T12:47:42Z</dc:date>
    </item>
  </channel>
</rss>

