Hi All,
I am getting an error while executing the GenerateTokenInGroupAsync(). The error "Operation returned an invalid status code 'Forbidden'".
I had users using the system all day, and the late afternoon this just stopped working. I am using the following method to get the access token.
public static async Task<AccessToken> SetAccessToken() { List<KeyValuePair<string, string>> vals = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("grant_type", "password"), new KeyValuePair<string, string>("scope", "openid"), new KeyValuePair<string, string>("resource", "https://analysis.windows.net/powerbi/api"), new KeyValuePair<string, string>("client_id", "XXXXX"), new KeyValuePair<string, string>("client_secret", "XXXXX"), new KeyValuePair<string, string>("username", "XXX"), new KeyValuePair<string, string>("password", "XXX") }; string TenantId = "XXX"; 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); return token; }
I can retrieve the report details using client.Reports.GetReportInGroupAsync().
var report = await client.Reports.GetReportInGroupAsync(groupId, reportId, CancellationToken.None); var generateTokenRequestParamaters = new GenerateTokenRequest(TokenAccessLevel.View, datasetId, allowSaveAs: null); var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(groupId, report.Id, generateTokenRequestParamaters, CancellationToken.None);
The error occurs when executing the last line of code in the code above.
Regards
Remeez