Giter Club home page Giter Club logo

powerbi-node's Introduction

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
}

powerbi-node's People

Contributors

ali-hamud avatar aluong avatar msftgits avatar ranbreuer avatar wbreza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

powerbi-node's Issues

Post Import expects filePath as string

I'm trying to upload a pbix file using the imports.postImport function, but it results in an HTTP 400 response.

It expects importInfo containing the filePath as the 4th parameter.
The filePath is sent on the request body, while it should be sending contents of the pbix file, as in the API docs example.

If I try to send the file data, I get the following error:
Error "importInfo.filePath with value '[object Object]' must be of type string." occurred in serializing the payload

I did succeed in uploading a pbix file by making a call to the Post Import API directly using a ReadStream to send the contents of the file.

Support for DELETE workspace API

Once the underlying API is available add DELETE workspace support into Node JS SDK

Steps:

  1. Update swagger doc for the delete API
  2. Regenerate Node client from swagger using autorest

Error TS2307: Cannot find module 'http'

Hi,

I'm trying to develop a client side webpart for SharePoint Online environment. This webpart would embed a powerbi report from powerbi workspace.

While developing the webpart, below steps are taken:

From command line instance, created a folder “BISteria_webPart”, and navigated to it.

Then I ran the yeoman SharePoint generator with “yo @microsoft/sharepoint” and stick to the default values.

Added the additional dependencies via:

npm install powerbi-client
npm install powerbi-api

Then, I ran npm install command to install all dependencies.

In webpart.ts file, following libraries are included

import * as pbi from 'powerbi-client';
import * as pbi_api from 'powerbi-api';

And finally I ran gulp serve command to debug the webpart.

As I run the gulp serve command, I got the below errors:

Error - typescript - node_modules\ms-rest\lib\index.d.ts(0,24): error TS2307: Cannot find module 'stream'
Error - typescript - node_modules\ms-rest\lib\index.d.ts(1,22): error TS2307: Cannot find module 'http'.

Please find the below attached Source file for the same

PowerBiSteriaWebPart.zip

Thanks
Shilpi Venaik

Cannot authenticate Using the JWT received from Node

I am using this method to acquire a jwt. When I use this method, I test out the token here:

https://microsoft.github.io/PowerBI-JavaScript/demo/code-demo/index.html#

Yet when I use the token I get a "Not Authorized" and the PowerBI report will not show. I can use the ProvisionSample C# CLI provided here: https://github.com/Azure-Samples/power-bi-embedded-integrate-report-into-web-app/tree/master/ProvisionSample
Everything will work fine when I use this method and I am able to get report to render. When I use the ProvisionSample, I am logged into visual studio 2015. I have tried to run node code in visual studio while signed in as well as outside authenticated environment. Am I doing something wrong with the request? Please help. Thank you

var powerbi = require('powerbi-api');

var token = powerbi.PowerBIToken.createReportEmbedToken(workspaceCollectionName = 'wcn'
, workspaceId = 'wid'
, reportId = 'rid'
, did = ''
, scp = 'Report.Read'
, username = 'user'
, roles = ''
, expiration = new Date(2905804496111));//'2062-01-29T23:54:56.111Z'

console.log("Token: ", token);

var jwt = token.generate(process.env.pbiAccessKey);

console.log("JWT: ", jwt);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.