Forum Discussion

IanV's avatar
IanV
Frequent Visitor
8 years ago

PowerBIClient Throwing Http Exception When trying to Access Reports

I'm trying to create a PowerBI Client to user with Power BI Embedded (app owns data)

 

I've followed the examples and looked at the sample project/configs here, but I keep getting the following error:

 

System.Net.WebException : The remote name could not be resolved: 'analysis.windows.net'

The authentication code is pretty much identical to the sample: 

 

// Create a user password credentials: My AD user for Azure and Power BI
var credential = new UserPasswordCredential(Username, Password);

// Authenticate using created credentials
// AuthorityUrl = https://login.windows.net/common/oauth2/authorize/
var authenticationContext = new AuthenticationContext(AuthorityUrl);

// ResourceUrl = https://analysis.windows.net/powerbi/api (taken from examples and is also in the sample project config)
// ClientId = the app ID from registering at https://dev.powerbi.com/apps
var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

if (authenticationResult == null)
{
    return View(new EmbedConfig()
    {
        ErrorMessage = "Authentication Failed."
    });
}

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

// ApiUrl = https://api.powerbi.com
using (var client = new Microsoft.PowerBI.Api.V2.PowerBIClient(new Uri(ApiUrl), tokenCredentials)
{
    var groups = await client.Groups.GetGroupsAsync(); // errors out here
}

Any ideas? Did I misconfigure something, or should it be pointing somewhere else?

3 Replies