Welcome to the .NET developer community for Power BI. Here you will find resources for the .NET SDKs for Power BI Embedded V2.0.0
Перейти к файлу
Amos Hersch 4ad33dd6bd
Merge pull request #211 from microsoft/dev/amhersch/mirror_4_22_0
mirror SDK 4.22.0
2024-10-15 10:21:44 +03:00
.github Merged PR 139698: Fix typo in PR template 2021-01-17 13:57:05 +00:00
.version Cdpx pipelines for PowerBI Csharp sdk 2020-04-22 16:02:39 +00:00
samples remove samples 2017-06-09 01:10:53 +03:00
scripts Merged PR 626230: Revert Patch 2024-10-13 12:48:34 +00:00
sdk Merge remote-tracking branch 'ado/master' into dev/amhersch/mirror_4_22_0 2024-10-15 09:16:22 +03:00
.gitignore update gitignore 2022-03-09 11:31:55 +02:00
README.md Merged PR 229173: Update README.md 2022-01-12 14:57:03 +02:00
SECURITY.md Merged PR 144014: Added SECURITY.md 2021-02-03 09:01:52 +00:00
azure-pipelines.yml Set up CI with Azure Pipelines 2020-01-08 14:42:26 +02:00
global.json Merged PR 390941: Fix the .Net SdK error in OneBranch PR pipeline. 2023-05-03 17:24:35 +00:00
license.txt Added license file 2016-07-14 09:15:40 -07:00

README.md

Power BI REST APIs for .NET

Overview

The Power BI REST APIs provide service endpoints for embedding, user resources management, administration and governance.

For more information about Power BI REST APIs, see Power BI REST APIs overview.

Power BI API library

The Microsoft.PowerBI.Api library for .NET enables you to work with Power BI REST APIs in your .NET or NET Core application.

Install the NuGet package directly from the Visual Studio Package Manager console.

Visual Studio Package Manager

Install-Package Microsoft.PowerBI.Api

Examples

Below are basic examples demonstrating some of the most common capabilities of the SDK. Full examples including authentication are avaliable in PowerBI-Developer-Samples

Get the list of datasets and reports in a Power BI workspace

...
using (PowerBIClient client = new PowerBIClient(credentials))
{

    Console.WriteLine("\r*** DATASETS ***\r");

    // List of datasets in a workspace
    Datasets datasets = client.Datasets.GetDatasets(groupId);

    foreach(Dataset ds in datasets.Value)
    {
        Console.WriteLine(ds.Id + " | " + ds.Name);
    }

    Console.WriteLine("\r*** REPORTS ***\r");

    // List of reports in a workspace
    Reports reports = client.Reports.GetReports(groupId);

    foreach (Report rpt in reports.Value)
    {
        Console.WriteLine(rpt.Id + " | " + rpt.Name +  " | DatasetID = " + rpt.DatasetId);
    }
}
...

Creating an Embed Token to reports and datasets

Embed tokens are used to provide access to Power BI artifacts like reports and datasets to embed into an application. To create a report embed token you will need a Power BI Embedded capacity, and the Ids of the workspaces and artifacts to provide access to. For more information about Power BI Embedded visit the Power BI Embedded Analytics Playground

...
using (PowerBIClient client = new PowerBIClient(credentials))
{
    // Create a request for getting Embed token
    var tokenRequest = new GenerateTokenRequestV2(datasets: datasets, reports: reports, targetWorkspaces: workspaces, identities: identities);

    // Get Embed token
    var embedToken = client.EmbedToken.GenerateToken(tokenRequest);
}
...

Get Reports As Admin

Returns a list of reports for the organization. The caller must have administrator rights.

...
using (PowerBIClient client = new PowerBIClient(credentials))
{
    Console.WriteLine("\r*** REPORTS ***\r");

    // List of reports in the organization.
    AdminReports reports = client.Reports.GetReportsAsAdmin();

    foreach (AdminReport rpt in reports.Value)
    {
        Console.WriteLine(rpt.Id + " | " + rpt.Name);
    }
}
...