<?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: .Net GetActivityEventsAsync fails with Bad Request in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Net-GetActivityEventsAsync-fails-with-Bad-Request/m-p/1800561#M29133</link>
    <description>&lt;P&gt;The problem was solved by enclosing the dates in single quotes:&lt;BR /&gt;&lt;BR /&gt;var logs = await client.Admin.GetActivityEventsAsync(startDateTime:string.Format("'{0:yyyy-MM-ddTHH:mm:ss.FFFZ}'", loopStart), endDateTime:&lt;BR /&gt;string.Format("'{0:yyyy-MM-ddTHH:mm:ss.FFFZ}'", loopEnd));&lt;BR /&gt;&lt;BR /&gt;If you use ContinuationToken make sure to both enclose it in sinqle quotes and UrlDecode it before passing it as a parameter.&lt;/P&gt;</description>
    <pubDate>Thu, 22 Apr 2021 13:53:42 GMT</pubDate>
    <dc:creator>perhed</dc:creator>
    <dc:date>2021-04-22T13:53:42Z</dc:date>
    <item>
      <title>.Net GetActivityEventsAsync fails with Bad Request</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Net-GetActivityEventsAsync-fails-with-Bad-Request/m-p/1792273#M29066</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying really hard to download the power bi logs but I'm failing miserabely.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The service principal is set to access the Power BI API and the user is a Power BI Admin and has a Power BI Pro license. The service principal also has granted Tenant.Read.All API Permissions. I can get a token and other parts of the API is working. I can for example refresh a dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But&amp;nbsp;GetActivityEventsAsync fails with a Bad Request. I have tried many many differents types of ways to call the function but I have not been able to succeed. I have not found any examples on the web of how to call the function properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the code I am trying. Can anyone please help me??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Gets the token for the app registration&lt;BR /&gt;//Here we need both a service principal and user identity. The user needs to be admin of the workspace and have Power BI Pro licens.&lt;BR /&gt;AuthenticationManager ta = new AuthenticationManager(log);&lt;BR /&gt;var tokenCredentials = await ta.GetToken(); //Exception is thrown if&lt;/P&gt;&lt;P&gt;// Create a Power BI Client object. It will be used to call Power BI APIs.&lt;BR /&gt;using (var client = new PowerBIClient(new Uri("&lt;A href="https://api.powerbi.com" target="_blank" rel="noopener"&gt;https://api.powerbi.com&lt;/A&gt;"), tokenCredentials))&lt;BR /&gt;{&lt;BR /&gt;DateTime start = DateTime.Today.AddDays(-1);&lt;BR /&gt;DateTime end = start.AddHours(2);&lt;/P&gt;&lt;P&gt;var logs = await client.Admin.GetActivityEventsAsync(string.Format("{0:yyyy-MM-ddTHH:mm:ss.fffZ}", start),string.Format("{0:yyyy-MM-ddTHH:mm:ss.fffZ}", end)); //Fails with bad Request&lt;BR /&gt;&lt;BR /&gt;//Do something with the logs&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code for Authentication&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;private static readonly string AuthorityUrl = "&lt;A href="https://login.windows.net/common/oauth2/token/" target="_blank" rel="noopener"&gt;https://login.windows.net/common/oauth2/token/&lt;/A&gt;";&lt;BR /&gt;private static readonly string ResourceUrl = "&lt;A href="https://analysis.windows.net/powerbi/api" target="_blank" rel="noopener"&gt;https://analysis.windows.net/powerbi/api&lt;/A&gt;";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/// &amp;lt;summary&amp;gt;&lt;BR /&gt;/// Authenticates the app registration via delegated user.&lt;BR /&gt;/// &amp;lt;/summary&amp;gt;&lt;BR /&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;BR /&gt;private async Task&amp;lt;OAuthResult&amp;gt; AuthenticateAsync()&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;Uri oauthEndpoint = new Uri(AuthorityUrl);&lt;BR /&gt;using (HttpClient client = new HttpClient())&lt;BR /&gt;{&lt;BR /&gt;HttpResponseMessage result = await client.PostAsync(oauthEndpoint, new FormUrlEncodedContent(new[]&lt;BR /&gt;{&lt;BR /&gt;new KeyValuePair&amp;lt;string, string&amp;gt;("resource", ResourceUrl),&lt;BR /&gt;new KeyValuePair&amp;lt;string, string&amp;gt;("client_id", ClientId),&lt;BR /&gt;new KeyValuePair&amp;lt;string, string&amp;gt;("client_secret", ClientSecret),&lt;BR /&gt;new KeyValuePair&amp;lt;string, string&amp;gt;("grant_type", "password"),&lt;BR /&gt;new KeyValuePair&amp;lt;string, string&amp;gt;("username", Username),&lt;BR /&gt;new KeyValuePair&amp;lt;string, string&amp;gt;("password", Password),&lt;BR /&gt;new KeyValuePair&amp;lt;string, string&amp;gt;("scope", "openid"),&lt;BR /&gt;}));&lt;/P&gt;&lt;P&gt;string content = await result.Content.ReadAsStringAsync();&lt;BR /&gt;return JsonConvert.DeserializeObject&amp;lt;OAuthResult&amp;gt;(content);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (HttpRequestException hEx)&lt;BR /&gt;{&lt;BR /&gt;_log.LogInformation(hEx.Message);&lt;BR /&gt;return null;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 09:21:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Net-GetActivityEventsAsync-fails-with-Bad-Request/m-p/1792273#M29066</guid>
      <dc:creator>perhed</dc:creator>
      <dc:date>2021-04-19T09:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: .Net GetActivityEventsAsync fails with Bad Request</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Net-GetActivityEventsAsync-fails-with-Bad-Request/m-p/1796273#M29098</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/296710"&gt;@perhed&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, I couldn't do more testing.&lt;/P&gt;
&lt;P&gt;You could try to create a support ticket. If you have a Pro account it is free.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://powerbi.microsoft.com/en-us/support/" target="_self"&gt;https://powerbi.microsoft.com/en-us/support/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Support Ticket.gif" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/498539i0FFA19D080A2528F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Support Ticket.gif" alt="Support Ticket.gif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Liang &lt;BR /&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 01:53:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Net-GetActivityEventsAsync-fails-with-Bad-Request/m-p/1796273#M29098</guid>
      <dc:creator>V-lianl-msft</dc:creator>
      <dc:date>2021-04-21T01:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: .Net GetActivityEventsAsync fails with Bad Request</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Net-GetActivityEventsAsync-fails-with-Bad-Request/m-p/1800561#M29133</link>
      <description>&lt;P&gt;The problem was solved by enclosing the dates in single quotes:&lt;BR /&gt;&lt;BR /&gt;var logs = await client.Admin.GetActivityEventsAsync(startDateTime:string.Format("'{0:yyyy-MM-ddTHH:mm:ss.FFFZ}'", loopStart), endDateTime:&lt;BR /&gt;string.Format("'{0:yyyy-MM-ddTHH:mm:ss.FFFZ}'", loopEnd));&lt;BR /&gt;&lt;BR /&gt;If you use ContinuationToken make sure to both enclose it in sinqle quotes and UrlDecode it before passing it as a parameter.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Apr 2021 13:53:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Net-GetActivityEventsAsync-fails-with-Bad-Request/m-p/1800561#M29133</guid>
      <dc:creator>perhed</dc:creator>
      <dc:date>2021-04-22T13:53:42Z</dc:date>
    </item>
  </channel>
</rss>

