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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
pawels
New Member

Bearer generated on docs.microsoft.com works while oauth2 doesn't

Good day all,

 

I'm struggling for a while with generating Bearer for PBI REST API. Action that I'd like to make is to trigger truncating streaming data:

https://docs.microsoft.com/en-us/rest/api/power-bi/pushdatasets/datasets_deleterowsingroup

 

In order to do so I need to send DELETE message covered with bearer. When I'm using bearer generated in Try it section I've 200 OK answer - as expected.

 

I've registered app on dev.powerbi.com/apps for client id and secret with required scope Dataset.ReadWrite.All in order to generate bearer:

string resourceUri = "https://analysis.windows.net/powerbi/api";

string authorityUri = "https://login.windows.net/common/oauth2";

AuthenticationContext authContext = new AuthenticationContext(authorityUri);
string token = authContext.AcquireToken(resourceUri, new ClientCredential(clientID, clientSecret)).AccessToken;

 

Code above works and returns bearer, but once using it I've 401 UNAUTHORIZED. 

 

Question is: why bearer generated on Try it section (so on my credentials) works while bearer generated on app registration doesn't?

 

 

3 REPLIES 3
jppp
Continued Contributor
Continued Contributor

Hi @pawels ,

 

One thing that pops my mind: does your application (=clientID) has access to the workgroup/dataset?

The 'try it' option is using your account to impersonate you to connect to the REST API and the code sample you share is using a ClinetID/Secret scheme to authenticate.

 

-JP

Hey @jppp !


Thank you for reply. Could you please evaluate how to check that access or eventually how to add this access to? 

 

Cheers!
PS

jppp
Continued Contributor
Continued Contributor

Hi @pawels 

 

The SP should have been added to the 'users' that have access to the workspace, see step 5 of https://docs.microsoft.com/en-us/power-bi/developer/embed-service-principal#get-started-with-a-servi...

 

-JP

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.