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
nlombardiCL
Regular Visitor

"The remote server returned an error: (403) Forbidden." error when calling from REST service.

Hello,

 

We are using an angular2 SPA to interact with our REST API services.  We have a report service that we would like to use to call the Power BI REST API service endpoints.  We acquire an azure AD accessToken in our service and try and use that token for the PowerBI calls but keep getting the "The remote server returned an error: (403) Forbidden." error.  Our SPA is registered in Azure and we have given Power BI permissions to the application.  I have an account in Power BI as well.  Below is the code I am using to call the GetReports endpoint. The error is thrown when the GetResponse is called.  Any suggestions would be greatly appeciated.  Thanks.

 

var accessToken = Request.Headers.Authorization.Parameter;  //defined in controller and passed to method below.

Uri baseAddress = new Uri("https://api.powerbi.com/");   //defined above

 

public async Task<List<PbiReport>> GetPBIReports(string accessToken)

{

string responseData;

var powerBiApiUrl = baseAddress + "v1.0/myorg/datasets";

List<PbiReport> reports = new List<PbiReport>();

HttpWebRequest request = WebRequest.Create(powerBiApiUrl) as HttpWebRequest;

request.KeepAlive = true;

request.Method = "GET";

request.ContentLength = 0;

request.ContentType = "application/json";

request.Headers.Add("Authorization", $"Bearer {accessToken}");

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)

{

using (StreamReader reader = new StreamReader(response.GetResponseStream()))

{

reports = JsonConvert.DeserializeObject<List<PbiReport>>(reader.ReadToEnd());

}

}

return reports;

}

 

1 REPLY 1
Eric_Zhang
Microsoft Employee
Microsoft Employee

@nlombardiCL

The code looks good.

 

Ensure the accessToken is valid. You can try to access the API with POSTMAN with the accesstoken.

 

For testing purpose, you can also get a valid token with the help of Chrome dev tool(F12).

 

Capture.PNG

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.