Welcome to the unofficial port of the .NET SDK for Power BI to .NET Standard 2.0. Here you will find resources on how to use the SDK in .NET Core or with other .NET Standard projects.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 29 commits ahead, 20 commits behind Microsoft:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.github
samples
sdk
.gitignore
Power BI Azure Embedded Readme.md
README.md
license.txt

README.md

Power BI for .NET Standard NuGet Visual Studio Team services

For the official SDK please go to their repository.

Install from Nuget

Install-Package PowerBI.Api

Usage: Calling the GetReports API in a netcoreapp2

In the official documentation you will find references to UserPasswordCredential. This class is not available in netcoreapp2. To get a token from Azure AD you will need to call the API directly as illustrated below.

private async Task<TokenCredentials> GetAccessToken()
{
    using (HttpClient client = new HttpClient())
    {
        string tenantId = "";
        var tokenEndpoint = "";
        var accept = "application/json";
        var userName = "";
        var password = "";
        var clientId = "";

        client.DefaultRequestHeaders.Add("Accept", accept);
        string postBody = null;

        postBody = $@"resource=https%3A%2F%2Fanalysis.windows.net/powerbi/api
                        &client_id={clientId}
                        &grant_type=password
                        &username={userName}
                        &password={password}
                        &scope=openid";

        var tokenResult = await client.PostAsync(tokenEndpoint, new StringContent(postBody, Encoding.UTF8, "application/x-www-form-urlencoded"));
        tokenResult.EnsureSuccessStatusCode();
        var tokenData = await tokenResult.Content.ReadAsStringAsync();

        JObject parsedTokenData = JObject.Parse(tokenData);

        var token = parsedTokenData["access_token"].Value<string>();
        return new TokenCredentials(token, "Bearer");
    }
}
public async Task<IActionResult> Index()
{

    var tokenCredentials = await GetAccessToken();


    // Create a Power BI Client object (it will be used to call Power BI APIs)
    using (var powerBiclient = new PowerBIClient(new Uri("https://api.powerbi.com/"), tokenCredentials))
    {

        // Get a list of all groupts
        var reports = powerBiclient.Groups.GetGroups();

        // Do anything you want with the list of groups.
    }
    return View();
}

Usage: Conflict with Microsoft.Rest.ClientRuntime

Should you receive a conflict with Microsoft.Rest.ClientRuntime after adding the package, you just need to add a reference the latest version directly in your application by using: dotnet add package Microsoft.Rest.ClientRuntime