<?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 Generate PowerBI Embed Token gives me Forbidden/500 Internal Server Error in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Generate-PowerBI-Embed-Token-gives-me-Forbidden-500-Internal/m-p/242526#M7575</link>
    <description>&lt;P&gt;I have a Native App. I am trying to Embed (App Owns Data) power bi content to my Native App. I am trying to embed a report/ dashboard. To do so I have to generate the Embed Token. When I try to generate the embed token&amp;nbsp;it gives me 500 internal Server error or Forbidden status. Please see the attached error information. What could the reason for this error ?&amp;nbsp;Is this because of Access issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code:&lt;/P&gt;&lt;P&gt;public async Task&amp;lt;ActionResult&amp;gt; GetReportByID(String Id)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;var error = GetWebConfigErrors();&lt;BR /&gt;if (error != null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = error&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Create a user password cradentials.&lt;BR /&gt;var credential = new UserPasswordCredential(Username, Password);&lt;/P&gt;&lt;P&gt;// Authenticate using created credentials&lt;BR /&gt;var authenticationContext = new AuthenticationContext(AuthorityUrl);&lt;BR /&gt;var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);&lt;/P&gt;&lt;P&gt;if (authenticationResult == null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = "Authentication Failed."&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");&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(ApiUrl), tokenCredentials))&lt;BR /&gt;{&lt;BR /&gt;// Get a list of reports.&lt;BR /&gt;var reports = await client.Reports.GetReportsInGroupAsync(GroupId);&lt;/P&gt;&lt;P&gt;var report = reports.Value.FirstOrDefault();&lt;BR /&gt;// Get the first report in the group.&lt;BR /&gt;foreach (var item in reports.Value)&lt;BR /&gt;{&lt;BR /&gt;if (Id == item.Id)&lt;BR /&gt;{&lt;BR /&gt;report = item;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (report == null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = "Group has no reports."&lt;BR /&gt;});&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// Generate Embed Token.&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, Id, generateTokenRequestParameters);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;if (tokenResponse == null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = "Failed to generate embed token."&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Generate Embed Configuration.&lt;BR /&gt;var embedConfig = new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;EmbedToken = tokenResponse,&lt;BR /&gt;EmbedUrl = report.EmbedUrl,&lt;BR /&gt;Id = report.Id&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;return View(embedConfig);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
    <pubDate>Wed, 30 Aug 2017 21:27:23 GMT</pubDate>
    <dc:creator>n02378281</dc:creator>
    <dc:date>2017-08-30T21:27:23Z</dc:date>
    <item>
      <title>Generate PowerBI Embed Token gives me Forbidden/500 Internal Server Error</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Generate-PowerBI-Embed-Token-gives-me-Forbidden-500-Internal/m-p/242526#M7575</link>
      <description>&lt;P&gt;I have a Native App. I am trying to Embed (App Owns Data) power bi content to my Native App. I am trying to embed a report/ dashboard. To do so I have to generate the Embed Token. When I try to generate the embed token&amp;nbsp;it gives me 500 internal Server error or Forbidden status. Please see the attached error information. What could the reason for this error ?&amp;nbsp;Is this because of Access issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code:&lt;/P&gt;&lt;P&gt;public async Task&amp;lt;ActionResult&amp;gt; GetReportByID(String Id)&lt;BR /&gt;{&lt;/P&gt;&lt;P&gt;var error = GetWebConfigErrors();&lt;BR /&gt;if (error != null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = error&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Create a user password cradentials.&lt;BR /&gt;var credential = new UserPasswordCredential(Username, Password);&lt;/P&gt;&lt;P&gt;// Authenticate using created credentials&lt;BR /&gt;var authenticationContext = new AuthenticationContext(AuthorityUrl);&lt;BR /&gt;var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);&lt;/P&gt;&lt;P&gt;if (authenticationResult == null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = "Authentication Failed."&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");&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(ApiUrl), tokenCredentials))&lt;BR /&gt;{&lt;BR /&gt;// Get a list of reports.&lt;BR /&gt;var reports = await client.Reports.GetReportsInGroupAsync(GroupId);&lt;/P&gt;&lt;P&gt;var report = reports.Value.FirstOrDefault();&lt;BR /&gt;// Get the first report in the group.&lt;BR /&gt;foreach (var item in reports.Value)&lt;BR /&gt;{&lt;BR /&gt;if (Id == item.Id)&lt;BR /&gt;{&lt;BR /&gt;report = item;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;if (report == null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = "Group has no reports."&lt;BR /&gt;});&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// Generate Embed Token.&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, Id, generateTokenRequestParameters);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;if (tokenResponse == null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = "Failed to generate embed token."&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Generate Embed Configuration.&lt;BR /&gt;var embedConfig = new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;EmbedToken = tokenResponse,&lt;BR /&gt;EmbedUrl = report.EmbedUrl,&lt;BR /&gt;Id = report.Id&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;return View(embedConfig);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 21:27:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Generate-PowerBI-Embed-Token-gives-me-Forbidden-500-Internal/m-p/242526#M7575</guid>
      <dc:creator>n02378281</dc:creator>
      <dc:date>2017-08-30T21:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Generate PowerBI Embed Token gives me Forbidden/500 Internal Server Error</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Generate-PowerBI-Embed-Token-gives-me-Forbidden-500-Internal/m-p/243636#M7597</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="40729" data-lia-user-login="n02378281" class="lia-mention lia-mention-user"&gt;n02378281&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have a Native App. I am trying to Embed (App Owns Data) power bi content to my Native App. I am trying to embed a report/ dashboard. To do so I have to generate the Embed Token. When I try to generate the embed token&amp;nbsp;it gives me 500 internal Server error or Forbidden status. Please see the attached error information. What could the reason for this error ?&amp;nbsp;Is this because of Access issue?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is my code:&lt;/P&gt;
&lt;P&gt;public async Task&amp;lt;ActionResult&amp;gt; GetReportByID(String Id)&lt;BR /&gt;{&lt;/P&gt;
&lt;P&gt;var error = GetWebConfigErrors();&lt;BR /&gt;if (error != null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = error&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;// Create a user password cradentials.&lt;BR /&gt;var credential = new UserPasswordCredential(Username, Password);&lt;/P&gt;
&lt;P&gt;// Authenticate using created credentials&lt;BR /&gt;var authenticationContext = new AuthenticationContext(AuthorityUrl);&lt;BR /&gt;var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);&lt;/P&gt;
&lt;P&gt;if (authenticationResult == null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = "Authentication Failed."&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");&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(ApiUrl), tokenCredentials))&lt;BR /&gt;{&lt;BR /&gt;// Get a list of reports.&lt;BR /&gt;var reports = await client.Reports.GetReportsInGroupAsync(GroupId);&lt;/P&gt;
&lt;P&gt;var report = reports.Value.FirstOrDefault();&lt;BR /&gt;// Get the first report in the group.&lt;BR /&gt;foreach (var item in reports.Value)&lt;BR /&gt;{&lt;BR /&gt;if (Id == item.Id)&lt;BR /&gt;{&lt;BR /&gt;report = item;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;if (report == null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = "Group has no reports."&lt;BR /&gt;});&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// Generate Embed Token.&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, Id, generateTokenRequestParameters);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;if (tokenResponse == null)&lt;BR /&gt;{&lt;BR /&gt;return View(new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;ErrorMessage = "Failed to generate embed token."&lt;BR /&gt;});&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;// Generate Embed Configuration.&lt;BR /&gt;var embedConfig = new EmbedConfig()&lt;BR /&gt;{&lt;BR /&gt;EmbedToken = tokenResponse,&lt;BR /&gt;EmbedUrl = report.EmbedUrl,&lt;BR /&gt;Id = report.Id&lt;BR /&gt;};&lt;/P&gt;
&lt;P&gt;return View(embedConfig);&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="40729" data-lia-user-login="n02378281" class="lia-mention lia-mention-user"&gt;n02378281&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The above code works in my test. Usually Forbidden error indicates the registered app doesn't have suffiecient permission, please &lt;A href="https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-register-app/#apply-permissions-to-your-application-within-azure-ad" target="_self"&gt;check premissions in&amp;nbsp;azure portal&lt;/A&gt;. For other issues, to have a better troubleshooting, please add try..catch block to get more detailed error information.&lt;/P&gt;
&lt;PRE&gt;                try
                {
                    // Generate Embed Token.
                    var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
                    var  tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, report.Id, generateTokenRequestParameters);

                    if (tokenResponse == null)
                    {
                        return View(new EmbedConfig()
                        {
                            ErrorMessage = "Failed to generate embed token."
                        });
                    }

                    // Generate Embed Configuration.
                    var embedConfig = new EmbedConfig()
                    {
                        EmbedToken = tokenResponse,
                        EmbedUrl = report.EmbedUrl,
                        Id = report.Id
                    };

                    return View(embedConfig);
                }

                catch (HttpOperationException ex)
                {
                    //debug content for error details&lt;BR /&gt;
                    var &lt;FONT size="4"&gt;&lt;STRONG&gt;content&lt;/STRONG&gt; &lt;/FONT&gt;= ex.Response.Content; 
                }&lt;/PRE&gt;
&lt;P&gt;By the way, when playing with Power BI API lib, I'd like to test the correlated rest api(&lt;A href="https://msdn.microsoft.com/en-US/library/mt784614.aspx" target="_self"&gt;GenerateToken&lt;/A&gt; in this case) with &lt;A href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" target="_self"&gt;Postman&lt;/A&gt;&amp;nbsp;at first.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2017 09:02:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Generate-PowerBI-Embed-Token-gives-me-Forbidden-500-Internal/m-p/243636#M7597</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-09-01T09:02:30Z</dc:date>
    </item>
  </channel>
</rss>

