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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Invalid status code 'Forbidden'

Hi -

 

I am using PowerBIClient to get the reports and I get 'Forbidden' error back.

 

This is what i did:

 

string authorityUrl = "https://login.windows.net/common/oauth2/authorize";
string resouurceUrl = "https://analysis.windows.net/powerbi/api";

var authenticationContext = new AuthenticationContext(authorityUrl);
var credential = new ClientCredential(clientID, clientSecret);
AuthenticationResult result = authenticationContext.AcquireTokenAsync(resouurceUrl, credential).Result;

 

var token = new TokenCredentials(result.AccessToken, "Bearer");
using (var client = new PowerBIClient(new Uri("https://api.powerbi.com"), token))

{

ODataResponseListReport reports = client.Reports.GetReports();

}

 

 

 

4 REPLIES 4
Eric_Zhang
Microsoft Employee
Microsoft Employee


@Anonymous wrote:

Hi -

 

I am using PowerBIClient to get the reports and I get 'Forbidden' error back.

 

This is what i did:

 

string authorityUrl = "https://login.windows.net/common/oauth2/authorize";
string resouurceUrl = "https://analysis.windows.net/powerbi/api";

var authenticationContext = new AuthenticationContext(authorityUrl);
var credential = new ClientCredential(clientID, clientSecret);
AuthenticationResult result = authenticationContext.AcquireTokenAsync(resouurceUrl, credential).Result;

 

var token = new TokenCredentials(result.AccessToken, "Bearer");
using (var client = new PowerBIClient(new Uri("https://api.powerbi.com"), token))

{

ODataResponseListReport reports = client.Reports.GetReports();

}

 

 

 


@Anonymous

Usually Forbidden error indicates the registered app doesn't have suffiecient permission, please check premissions in azure portal.

What is the scenario in your case, App Owns Data or User Owns Data? For App Owns data, a native app(no client_secret) is required that code snippet is like

            // Create a user password cradentials.
            var credential = new UserPasswordCredential({Username}, {Password});

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);
Anonymous
Not applicable

Hi Eric,

Thanks for your reply. My app is not a native app.

 

And I checked for permissions and PowerBI Service has all the delegate permissions checked, including Read and Write reports.

 

Please let me know if there is anything else you can think of.

 

Thanks, Shilpi

@Anonymous

So you're in the scenaio Embedding with Power BI users (users own data)?

Anonymous
Not applicable

Hi @Eric_Zhang,

 

I went with the App owns data approach and was able to authenticate using the username and password.

 

Thanks for your help.

 

I could not authenticate a web app using the client secret though.

 

Thanks, Shilpi

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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