powerbipowerbi-embeddedpowerbi-custom-visualspowerbi-rest-api

PowerBIClient does not have any value


I am trying to read powerbi report using powerbi SDk. I got correct access token (tested in postman). Same access token is passed for TokenCredentials. but not getting any value in _powerBIClient. it has no value. I'm using below code.

var functionCred = new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(_configuration[BotConfigurationEnum.FunctionClientId.GetDescription()], _configuration[BotConfigurationEnum.FunctionClientSecret.GetDescription()]);

var userAssertion = (!string.IsNullOrWhiteSpace(token)) ? new Microsoft.IdentityModel.Clients.ActiveDirectory.UserAssertion(token, "urn:ietf:params:oauth:grant-type:jwt-bearer") : null;

var context = new AuthenticationContext("https://login.microsoftonline.com/{tenentid}");
var res = await context.AcquireTokenAsync("https://analysis.windows.net/powerbi/api",
functionCred, userAssertion);

var tokenCredentials = new TokenCredentials(res.AccessToken, "Bearer");

var _powerBIClient = new PowerBIClient(new Uri("https://api.powerbi.com/"), tokenCredentials);
var pbiReport = _powerBIClient.Reports.GetReport(reportId);

Solution

  • there was small correction in my code.. I have removed '/' in new Uri and it worked. I know its silly..

     var _powerBIClient = new PowerBIClient(new Uri("https://api.powerbi.com"), tokenCredentials);