Skip to content

BennyM/PowerBI-CSharp

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code
This branch is 34 commits ahead, 475 commits behind microsoft:master.

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
sdk
 
 
 
 
 
 
 
 

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

For more information regarding onboarding to Power BI Embedded see our Embedding documentation.

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 groups = 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

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%