<?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: 401 - Unauthorized error during Dataset Refresh in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/401-Unauthorized-error-during-Dataset-Refresh/m-p/436666#M13475</link>
    <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Dataset.ReadWrite.All is the required permission that you're PowerBi Application should have &lt;SPAN&gt;in order to execute a refresh action.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/refreshdatasetingroup" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/refreshdatasetingroup&lt;/A&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If this is the problem, you should go to Azure Active Directory find the powerbi application and add the above permissions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hope it helps.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanos&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Jun 2018 07:33:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-06-11T07:33:01Z</dc:date>
    <item>
      <title>401 - Unauthorized error during Dataset Refresh</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/401-Unauthorized-error-during-Dataset-Refresh/m-p/433125#M13358</link>
      <description>&lt;P&gt;I am trying to do the Dataset refresh for a PowerBI Report. I created the gateway and I am able to do the dataset refresh from the admin portal. I could validate that the refresh happend successfully from UI i.e. Last Refresh column in the Admin portal. But when I try to do the refresh from a C# webapi code, I am getting the below mentioned error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Error Message:
The remote server returned an error: (401) Unauthorized.

Stack Trace:
at System.Net.HttpWebRequest.GetResponse()
at BlueSkyPowerBIService.Controllers.PowerBIController.&amp;lt;RefreshDatasetsForReports&amp;gt;d__13.MoveNext() in C:\Krishnan\RSI\SourceCode\Bluesky Developement\BlueSky Development\BlueSkyPowerBIService\BlueSkyPowerBIService\Controllers\PowerBIController.cs:line 258&lt;/PRE&gt;&lt;P&gt;Before the refresh code, I am able to do the authentication agains the Azure AD and it succeeds and generated the auth token, but when it call the API to refresh it crashes with the above said error.&lt;/P&gt;&lt;P&gt;Please find my code which i am use for data refresh&lt;/P&gt;&lt;PRE&gt;List&amp;lt;ReportDetails&amp;gt; reportDetailsList = new List&amp;lt;ReportDetails&amp;gt;();

            var result = new EmbedConfig();
            ReportDetails reportDetails = new ReportDetails();
            try
            {
                result = new EmbedConfig { Username = username, Roles = roles };
                var error = GetWebConfigErrors();
                if (error != null)
                {
                    result.ErrorMessage = error;
                    //return View(result);
                    return null;
                }
                var credential = new UserPasswordCredential(Username, Password);

                var authenticationContext = new AuthenticationContext(AuthorityUrl);
                var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

                if (authenticationResult == null)
                {
                    result.ErrorMessage = "Authentication Failed.";
                    //return View(result);
                    return null;
                }

                var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");

                // Create a Power BI Client object. It will be used to call Power BI APIs.
                using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
                {
                    // Get a list of reports.
                    var reports = await client.Reports.GetReportsAsync();
                    for (int index = 0; index &amp;lt; reports.Value.Count; index++)
                    {
                        reportDetails = new ReportDetails();
                        Report report = reports.Value[index];

                        HttpWebRequest request;

                        if (report.Id == "6317f207-57d3-4f5f-9644-18bfbb9bef99")
                        {
                            var url = "https://api.powerbi.com/v1.0/myorg/groups/{0}/datasets/{1}/refreshes";
                            request = System.Net.HttpWebRequest.CreateHttp(String.Format(url, GroupId, report.DatasetId));

                            request.KeepAlive = true;
                            request.Method = "POST";
                            request.ContentLength = 0;

                            request.Headers.Add("Authorization", String.Format("Bearer {0}", authenticationResult.AccessToken));

                            using (Stream writer = request.GetRequestStream())
                            {
                                var response = (HttpWebResponse)request.GetResponse();
                                Console.WriteLine("Dataset refresh request{0}", response.StatusCode.ToString());
                            }
                        }
                    }//end for(int index=0; index&amp;lt; reports.Value.Count; index++)
                    return reportDetailsList;
                }
            }
            catch (HttpOperationException exc)
            {
                result.ErrorMessage = string.Format("Status: {0} ({1})\r\nResponse: {2}\r\nRequestId: {3}", exc.Response.StatusCode, (int)exc.Response.StatusCode, exc.Response.Content, exc.Response.Headers["RequestId"].FirstOrDefault());
            }
            catch (Exception exc)
            {
                result.ErrorMessage = exc.ToString();
            }&lt;/PRE&gt;&lt;P&gt;Any ideas why I am getting this error? How to fix this issue?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jun 2018 02:08:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/401-Unauthorized-error-during-Dataset-Refresh/m-p/433125#M13358</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-06T02:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: 401 - Unauthorized error during Dataset Refresh</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/401-Unauthorized-error-during-Dataset-Refresh/m-p/436375#M13460</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's in the "PowerBIController.cs:line 258"? The error message indicates something wrong here. I would suggest you check if the user has the Edit permission of the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Dale&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jun 2018 15:21:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/401-Unauthorized-error-during-Dataset-Refresh/m-p/436375#M13460</guid>
      <dc:creator>v-jiascu-msft</dc:creator>
      <dc:date>2018-06-10T15:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: 401 - Unauthorized error during Dataset Refresh</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/401-Unauthorized-error-during-Dataset-Refresh/m-p/436666#M13475</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Dataset.ReadWrite.All is the required permission that you're PowerBi Application should have &lt;SPAN&gt;in order to execute a refresh action.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/refreshdatasetingroup" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/datasets/refreshdatasetingroup&lt;/A&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If this is the problem, you should go to Azure Active Directory find the powerbi application and add the above permissions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hope it helps.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanos&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jun 2018 07:33:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/401-Unauthorized-error-during-Dataset-Refresh/m-p/436666#M13475</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-06-11T07:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: 401 - Unauthorized error during Dataset Refresh</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/401-Unauthorized-error-during-Dataset-Refresh/m-p/438317#M13523</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;" lang="en-US"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: 'Segoe UI'; font-size: 10.5pt; color: #333333;"&gt;Could you please mark the proper answers as solutions?&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;" lang="en-US"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: 'Segoe UI'; font-size: 10.5pt; color: #333333;"&gt;Best Regards,&lt;/P&gt;
&lt;P style="margin: 0in; font-family: 'Segoe UI'; font-size: 10.5pt; color: #333333;"&gt;Dale&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 01:58:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/401-Unauthorized-error-during-Dataset-Refresh/m-p/438317#M13523</guid>
      <dc:creator>v-jiascu-msft</dc:creator>
      <dc:date>2018-06-13T01:58:00Z</dc:date>
    </item>
  </channel>
</rss>

