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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
s8nRrG
Regular Visitor

403 Forbidden error occured when using REST API

I'm developing API that allows to send data directly to Power BI. There must not be any user's interaction to authenticate the request. The user can set only clientId and clientSecret values. But all my requests retrun 403 status code. For instance, let's look at my code that I use to get data about all my datasets:

 

 

private static string GetAccessToken()
{
    const string clientId = "valid client id";
    const string clientSecret = "valid client secret";
    var clientCredentials = new ClientCredential(clientId, clientSecret);
    const string authorityUri = "https://login.windows.net/common/oauth2/authorize";
    const string resourceUri = "https://analysis.windows.net/powerbi/api";
	
    authContext = new AuthenticationContext(authorityUri, new TokenCache());
    var token = authContext.AcquireTokenAsync(resourceUri, clientCredentials).Result.AccessToken;
    return token;
}

private static string GetDatasets()
{
    var powerBIApiUrl = "https://api.powerbi.com/v1.0/myorg/datasets";

    var token = GetAccessToken();

    HttpWebRequest request = WebRequest.Create(powerBIApiUrl) as HttpWebRequest;
    request.Method = "GET";
    request.ContentLength = 0;

    request.Headers.Add("Authorization", $"Bearer {token}");
// 403 The remote server returned an error: (403) Forbidden. using (var httpResponse = request.GetResponse() as HttpWebResponse { using (var reader = new StreamReader(httpResponse.GetResponseStream())) { var responseContent = reader.ReadToEnd(); return responseContent; } } }

 

I get token "eyJ0...cceA" that seems valid. However, request.GetResponse() returns 403 status code. All permissions were delegated to Power BI Service in in Azure Active Directory.

 

Do you have any idea how to fix this? I really appreciate any help.

 

 

24 REPLIES 24


@Sunkari wrote:

I hope your registered your app with Azure Active directory  and provided proper clientid,clientkey,username and pwd.

 

https://login.microsoftonline.com/yourdirectorykey/oauth2/token

 

Provide proper directory key to resolve your issues.

 

Let me know if you need any further details


 

I use correct directory key. If I used wrong directory key, I'd got the exception No service namespace named 'wrong directory key' was found in the data store during obtaining access token.

Try the following API end point

I believe its still in beta mode.

https://api.powerbi.com/beta/myorg/datasets


@hari_seenivasan wrote:

Try the following API end point

I believe its still in beta mode.

https://api.powerbi.com/beta/myorg/datasets

It works with the same 403 status code.

Redirect response to HTML and share here, we will get more details on what went wrong.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.