Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
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;
}
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).
User | Count |
---|---|
14 | |
6 | |
2 | |
2 | |
2 |
User | Count |
---|---|
3 | |
3 | |
3 | |
2 | |
2 |