Quantcast
Channel: All Developer posts
Viewing all articles
Browse latest Browse all 48903

Re: 403 Forbidden error occured when using REST API

$
0
0

I'm having the same error message. 

 

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 = newUri("https://api.powerbi.com/");   //defined above

 

publicasyncTask<List<PbiReport>> GetPBIReports(string accessToken)

{

string responseData;

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

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

HttpWebRequest request = WebRequest.Create(powerBiApiUrl) asHttpWebRequest;

request.KeepAlive = true;

request.Method = "GET";

request.ContentLength = 0;

request.ContentType = "application/json";

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

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

{

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

{

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

}

}

return reports;

}


Viewing all articles
Browse latest Browse all 48903

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>