Forum Discussion
https //api.powerbi.com/v1.0/myorg/datasets 403 forbidden
- 9 years ago
I gave all permission to my app but isues was something different.I was trying to get token based on azure active directy app client id and app secerete key.After doing google i found that i need to pass credentials of azure login account too.
Below code worked for me with valide token:
private async void SetAccessToken()
{
List<KeyValuePair<string, string>> vals = new List<KeyValuePair<string, string>>();
vals.Add(new KeyValuePair<string, string>("grant_type", "password"));
vals.Add(new KeyValuePair<string, string>("scope", "openid"));
vals.Add(new KeyValuePair<string, string>("resource", "https://analysis.windows.net/powerbi/api"));
vals.Add(new KeyValuePair<string, string>("client_id", "..........."));
vals.Add(new KeyValuePair<string, string>("client_secret", "........"));
vals.Add(new KeyValuePair<string, string>("username", "................."));
vals.Add(new KeyValuePair<string, string>("password", "................."));
string TenantId = "............com";//your organizaion name
string url = string.Format("https://login.windows.net/{0}/oauth2/token", TenantId);
HttpClient hc = new HttpClient();
HttpContent content = new FormUrlEncodedContent(vals);
HttpResponseMessage hrm = hc.PostAsync(url, content).Result;
string responseData = "";
if (hrm.IsSuccessStatusCode)
{
Stream data = await hrm.Content.ReadAsStreamAsync();
using (StreamReader reader = new StreamReader(data, Encoding.UTF8))
{
responseData = reader.ReadToEnd();
}
}
AccessToken Token = JsonConvert.DeserializeObject<AccessToken>(responseData);
var result = await CallResoureApi(Token);
}public async Task<string> CallResoureApi(AccessToken token)
{
var baseAddress = new Uri("https://api.powerbi.com/");
string jsonresult = "";
string requestUrl = baseAddress + "v1.0/myorg/datasets";
var client = new RestClient(baseAddress);
var request = new RestRequest("v1.0/myorg/datasets", Method.GET);
request.AddHeader("authorization", "Bearer " + token.access_token);
// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content;
return content;
}
- sddrakesh9 years agoFrequent Visitor
I gave all permission to my app but isues was something different.I was trying to get token based on azure active directy app client id and app secerete key.After doing google i found that i need to pass credentials of azure login account too.
Below code worked for me with valide token:
private async void SetAccessToken()
{
List<KeyValuePair<string, string>> vals = new List<KeyValuePair<string, string>>();
vals.Add(new KeyValuePair<string, string>("grant_type", "password"));
vals.Add(new KeyValuePair<string, string>("scope", "openid"));
vals.Add(new KeyValuePair<string, string>("resource", "https://analysis.windows.net/powerbi/api"));
vals.Add(new KeyValuePair<string, string>("client_id", "..........."));
vals.Add(new KeyValuePair<string, string>("client_secret", "........"));
vals.Add(new KeyValuePair<string, string>("username", "................."));
vals.Add(new KeyValuePair<string, string>("password", "................."));
string TenantId = "............com";//your organizaion name
string url = string.Format("https://login.windows.net/{0}/oauth2/token", TenantId);
HttpClient hc = new HttpClient();
HttpContent content = new FormUrlEncodedContent(vals);
HttpResponseMessage hrm = hc.PostAsync(url, content).Result;
string responseData = "";
if (hrm.IsSuccessStatusCode)
{
Stream data = await hrm.Content.ReadAsStreamAsync();
using (StreamReader reader = new StreamReader(data, Encoding.UTF8))
{
responseData = reader.ReadToEnd();
}
}
AccessToken Token = JsonConvert.DeserializeObject<AccessToken>(responseData);
var result = await CallResoureApi(Token);
}public async Task<string> CallResoureApi(AccessToken token)
{
var baseAddress = new Uri("https://api.powerbi.com/");
string jsonresult = "";
string requestUrl = baseAddress + "v1.0/myorg/datasets";
var client = new RestClient(baseAddress);
var request = new RestRequest("v1.0/myorg/datasets", Method.GET);
request.AddHeader("authorization", "Bearer " + token.access_token);
// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content;
return content;
}- Anonymous6 years agoNot applicable
and for anyone like me trying to do the same but with Postman to the Power BI APIs, the same applied - you have to add valid Power BI credentials to the GET while creating an AAD token:
API calls now work 🙂
Complete lack of documentation from Microsoft on this 😞 Even their 'Try It' wizard does not indicate the need for username & password ( https://docs.microsoft.com/en-us/rest/api/power-bi/groups/getgroups )
Sam