guyinacube / Embed-API-Sample

A sample application to use the Power BI APIs for embedding. This makes use of the Power BI .NET SDK which in turn calls the Power BI REST API.
GNU General Public License v3.0
22 stars 22 forks source link

operation returned an invalid status code forbidden in client.Reports.GenerateTokenInGroupAsync #6

Open vickykrbu opened 4 years ago

vickykrbu commented 4 years ago

Hi Team,

I have used one application from Github called (AppsOwnData) In this application i passed the application id created(Which created in Azure AAD) and userid and password of Power bi service where my power bi report is present. So end user can have it without passing any credentials.

I passed the specific report workspace id and report id in application and found like the report is loading in the application.

Now below is my issue scenario: I needed on private workspace which could be access by only specific user. To do that i requested my admin to crated Power bi Embedded service in Azure and there i given one specific name to this service.

Once he done he created one new workspace with his credentials in Power bi service and linked Power bi Embedded service to this workspace. He provided permission to me and provided role called contributor.

Also he uploaded one sample .pbix file to this new workspace id and load the report and shared me the report url e.g: https://app.powerbi.com/groups/{someid}/reports/{someid}/ReportSection3?noSignUpCheck=1&refreshAccessToken=true

When i accessed that url with my credentials in power bi service i could see the new workspace created there and reports loading for me.

Now when i tried to load this report through application with passing my user credentials then getting below exception:

operation returned an invalid status code forbidden in below line of code: var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, report.Id, generateTokenRequestParameters);

Below is the complete stack trace: at Microsoft.PowerBI.Api.V2.Reports.d22.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.PowerBI.Api.V2.ReportsExtensions.d53.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at DevExpress_3D.PowerBILanding.d__17.MoveNext() in D:\Vikash\IMT-Jan_20032020\Application\DevExpress_3D\PowerBILanding.aspx.cs:line 151

Note: The previous credentials which i used to embed the report in application was having public workspace.

Please help me to fix the above issue.

vickykrbu commented 4 years ago

I found the solution for the above issue asked, The issue was like the workspace where the report was listed i did not had the admin access provided. Once i provided admin access to the workspace, After that i was able to embed the report through application.

Thank you to all of your support., Vikash