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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
Anonymous
Not applicable

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

Anonymous
Not applicable

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.