Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
WilliamTit
New Member

Operation returned an invalid status code 'Unauthorized''

Hi,

 

I am trying to run sample report  https://docs.microsoft.com/en-us/power-bi/developer/embedded/embed-sample-for-customers?tabs=net-cor...  and getting error "Operation returned an invalid status code 'Unauthorized''" at var pbiReport = pbiClient.Reports.GetReportInGroup(workspaceId, reportId);

 

I gave the user account admin right to the workspace, report and dataset.

 

Can someone please help?

 

Thanks,

 

William.

 

 

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @WilliamTit ,

Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yiruan-msft
Community Support
Community Support

Hi @WilliamTit ,

If you are using service principal authentication, please check whether you have enabled "Allow service principals to use Power BI APIs" feature in Admin portal.

yingyinr_0-1648696968257.png

Also, has the service principal been added as member or admin of workspace?

yingyinr_1-1648697072726.png

And you can refer the following video to check if something is missing...

Embed Power BI Report for Customers using App Own Concept and Service Principal

Embed Power BI Report for Customers using App Owns Data and Master User

In addition, the followings are the ones which has similar problem with yours. Hope they can help you.

Operation returned an invalid status code 'Unauthorized''


Based on your description, I assumed that you are using the Access token for Power BI users (user owns data) approach. I would recommend you use https://jwt.io/ to decode the access_token after successfully invoked authContext.AcquireTokenAsync. Make sure the aud is https://analysis.windows.net/powerbi/api and check the permissions scope property scp.

For Get Groups, the required scope would look as follows:

Required scope: Group.Read.All or Group.ReadWrite.All or Workspace.Read.All or Workspace.ReadWrite.All

You could also use fiddler or postman to simulate the request against the get groups endpoint with the access_token received in your WPF application to narrow down this issue.

Moreover, you could follow Register an application to check your Azure AD app and make sure the required delegated permissions to Power BI Service (Microsoft.Azure.AnalysisServices) API have been correctly configured.


401 when accessing any Power BI API endpoints


I found something that work and documented it (with code) here: https://bitbucket.org/omnistream/powerbi-api-example

Hopefully it would help other people in need!

It's not entirely satisfying: I'm notably not too sure why I should use this authentication endpoint instead of the one I found in other documentation, nor why I have to use a username/password on top of the app credentials, especially since it's not a super secure way to do it; I'm concerned it may get deprecated in the future. But it works.


Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.