Node SDK and client library for Power BI REST APIs.
Перейти к файлу
ali-hamud 0841c2a0e5 Merge pull request #42 from Microsoft/alihamud_deprecation
Deprecation Note of PowerBi-Node
2017-08-17 14:53:23 +03:00
.github merge master from dev (#26) 2017-02-12 11:14:25 +02:00
.vscode Started migrating to remove ts file from npm package 2016-04-29 15:21:40 -07:00
lib generate code from shared swagger file 2017-03-12 14:17:15 +02:00
test/core add dataset & scopes to token (#20) 2017-01-09 12:10:49 +02:00
.gitignore Started migrating to remove ts file from npm package 2016-04-29 15:21:40 -07:00
.npmignore Updated npm ignore file 2016-04-29 16:14:49 -07:00
.travis.yml Updated travis npm deploy config 2016-07-22 10:55:52 -07:00
LICENSE Added license file from LCA 2016-04-22 14:49:32 -07:00
README.md Update README.md 2017-08-17 14:53:04 +03:00
generate.bat generate code from shared swagger file 2017-03-12 14:17:15 +02:00
package.json Fix update connection bug 2017-02-26 17:41:16 +02:00
swagger.json Fix update connection bug 2017-02-26 17:41:16 +02:00
tsconfig.json Updated to typings 1.0 release (#5) 2016-06-10 09:33:31 -07:00
typings.json Updated to typings 1.0 release (#5) 2016-06-10 09:33:31 -07:00

README.md

Deprecation Note

Node SDK is not supported any more. The Node SDK is no longer supported. If you are interested in this SDK, and would like to see it continue, please vote for it on the Power BI ideas site.

PowerBI-Node

Node SDK and client library for the Power BI Embedded REST APIs.

Build Status NPM Version NPM Total Downloads NPM Monthly Downloads

Installation

npm install powerbi-api

Usage

Creating a new client requires referencing the Power BI SDK as well as the Microsoft Rest Client. For an example of the Node SDK in action see the Power BI Node CLI.

var powerbi = require('powerbi-api');
var msrest = require('ms-rest');

var credentials = new msrest.TokenCredentials('{AccessKey}', "AppKey");
var client = new powerbi.PowerBIClient(credentials);

// Example API call
client.workspaces.getWorkspacesByCollectionName('{WorkspaceCollection}', function(err, result) {
    // Your code here
});

APIs

The following APIs groups are available:

  • Datasets
  • Gateways
  • Imports
  • Reports
  • Workspaces

PowerBI API Calls

All API calls use the AppKey to authenticate the API calls. The AppKey can be retreived from Azure portal. Each API call sets the following HTTP header:

  • Authorization: AppKey {AccessKey}

WARNING - Never expose your access keys client side in your application. If your access key is compromised a malicious user can take over control of your workspace collection. Access keys can be re-generated for your workspace collection within the Azure portal.

Creating Embed Tokens

Power BI Embedded uses embed token, which are HMAC signed JSON Web Tokens. The tokens are signed with the access key from your Azure Power BI Embedded workspace collection. Embed tokens, by default, are used to provide read only access to a report to embed into an application.

Required Claims

  • ver: 0.2.0
  • wcn: {WorkspaceCollectionName}
  • wid: {WorkspaceId}
  • rid: {ReportId}
  • aud: https://analysis.windows.net/powerbi/api
  • nbp: Token valid not before in Unix EPOCH time
  • exp: Token expiration in Unix EPOCH time
var powerbi = require('powerbi-api');
var token = powerbi.PowerBIToken.createReportEmbedToken('{WorkspaceCollection}', '{workspaceId}', '{reportId}');

var jwt = token.generate('{AccessKey}');

Token Example

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2ZXIiOiIwLjIuMCIsIndjbiI6IlN1cHBvcnREZW1vIiwid2lkIjoiY2E2NzViMTktNmMzYy00MDAzLTg4MDgtMWM3ZGRjNmJkODA5IiwicmlkIjoiOTYyNDFmMGYtYWJhZS00ZWE5LWEwNjUtOTNiNDI4ZWRkYjE3IiwiaXNzIjoiUG93ZXJCSVNESyIsImF1ZCI6Imh0dHBzOi8vYW5hbHlzaXMud2luZG93cy5uZXQvcG93ZXJiaS9hcGkiLCJleHAiOjEzNjAwNDcwNTYsIm5iZiI6MTM2MDA0MzQ1Nn0.LgG2y0m24gg3vjQHhkXYYWKSVnGIUYT-ycA6JmTB6tg

Decoded

The following decoded JSON web token Header

{
  "typ": "JWT",
  "alg": "HS256"
}

Payload

{
  "ver": "0.2.0",
  "wcn": "SupportDemo",
  "wid": "ca675b19-6c3c-4003-8808-1c7ddc6bd809",
  "rid": "96241f0f-abae-4ea9-a065-93b428eddb17",
  "iss": "PowerBISDK",
  "aud": "https://analysis.windows.net/powerbi/api",
  "exp": 1360047056,
  "nbf": 1360043456
}

Adding Permission Scopes to Embed Tokens

When using Embed tokens, one might want to restrict usage of the resources he gives access to. For this reason, you can generate a token with scoped permissions.

Required Claims - Scopes

  • scp: {scopesClaim} scopesClaim can be either a string or array of strings, noting the allowed permissions to workspace resources (Report, Dataset, etc.)
var powerbi = require('powerbi-api');
var reportReadScope = 'Report.Read';
var token = powerbi.PowerBIToken.createReportEmbedToken('{WorkspaceCollection}', '{workspaceId}', '{reportId}', '{scopes}');

var jwt = token.generate('{AccessKey}');

Token Example - With Scopes

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2ZXIiOiIwLjIuMCIsIndjbiI6IlN1cHBvcnREZW1vIiwid2lkIjoiY2E2NzViMTktNmMzYy00MDAzLTg4MDgtMWM3ZGRjNmJkODA5IiwicmlkIjoiOTYyNDFmMGYtYWJhZS00ZWE5LWEwNjUtOTNiNDI4ZWRkYjE3Iiwic2NwIjoiUmVwb3J0LlJlYWQiLCJpc3MiOiJQb3dlckJJU0RLIiwiYXVkIjoiaHR0cHM6Ly9hbmFseXNpcy53aW5kb3dzLm5ldC9wb3dlcmJpL2FwaSIsImV4cCI6MTM2MDA0NzA1NiwibmJmIjoxMzYwMDQzNDU2fQ.M1jkWXnkfwJeGQqh1x0vIAYB4EBKbHSZFoDB6n_LZyA

Decoded

The following decoded JSON web token Header

{
  "typ": "JWT",
  "alg": "HS256"
}

Payload

{
  "ver": "0.2.0",
  "wcn": "SupportDemo",
  "wid": "ca675b19-6c3c-4003-8808-1c7ddc6bd809",
  "rid": "96241f0f-abae-4ea9-a065-93b428eddb17",
  "scp": "Report.Read",
  "iss": "PowerBISDK",
  "aud": "https://analysis.windows.net/powerbi/api",
  "exp": 1360047056,
  "nbf": 1360043456
}