James
James

Reputation: 777

How to call the Power BI Embedded API

I'm investigating the usage of Power BI Embedded although I'm not able to get a working version.

I've generated a dummy report in power bi online and I've managed to publish the report and then successfully displayed the report within a simple HTML page. However I now want to integrate with the same report but through the REST API.

I'm not able to get this working because I'm not sure how to get the access token for the API. The screen shots below show my code so far (using React).

The 'playground' screen shot shows my dummy report visible in the portal. To make this possible I've added the 'embed URL' value and then clicked 'Run'

picture shows dummy report within power bi online

Javascript code snippet

import React, { Component } from 'react';
import { Report } from 'react-powerbi-client';

class App extends Component {   

  constructor(props) {
    super(props); 
    this.state = {
        embedUrl: 'https://app.powerbi.com/view?r=xxx'
    };
  }
  render() {
    return (
      <div>
          ...

          <Report 
              id={this.state.id}
              embedUrl={this.state.embedUrl}
              accessToken={this.state.accessToken}
              filterPaneEnabled={true}
              navContentPaneEnabled={false}
              onEmbedded={this.onEmbedded}
          />
      </div>
    );
  }
}
export default App;

Notice the react-powerbi-client library code needs the access token value - not sure where I get this from?

Thanks,

Upvotes: 0

Views: 1675

Answers (1)

mayur_007X
mayur_007X

Reputation: 784

In order to embed a Power BI report, you need to generating an access token. To generate the access token, you are required to register an Azure AD application. You can refer to this document to register an AAD app.

After registering the AAD app, you can generate the access token using MSAL. Plus, you can refer to this GitHub repository (provided by Microsoft) and follow the steps provided in the README file.

This repo will surely be helpful to you as you are embedding the Power BI report in React.

Upvotes: 1

Related Questions