POWER BI Report Integration

Aug 04, 2020

Here we will see how we can access Power BI Embed reports and Dashboards in ASP.NET MVC applications.

Let’s start with a small introduction to Power BI. Power BI is a reporting tool provided by Microsoft. It is accessible in two forms windows version and web version. Using windows version, we can design reports and then publish it to the Power BI server and Web version Power BI can be used to view that Published report.

Power BI server URL: https://powerbi.microsoft.com/en-us/

 

Prerequisite to Start with Power BI:

  1. Visual Studio 2017 (https://visualstudio.microsoft.com/vs/older-downloads/)
  2. Power BI Desktop (https://powerbi.microsoft.com/en-us/downloads/)
  3. Azure subscription to register the application. (http://portal.azure.com/)

Please follow the below steps to set up the Environment before starting with integration.

  1. Create an Active Directory on AZURE portal
  2. Register Application on Azure Portal.

Note: Copy these details to somewhere User Id, Password, ClientID, Client Secret Key

  1. Grant All Access Permissions to application. Later on, you can remove extra permissions as per requirement.
  2. Register on the Power BI server to host reports and create the workspace.
  3. Create one sample report and Deploy on the Workspace we create on power BI server

We can access this report directly without any authorization with the help of the URL. In that case, there is no data security. That’s why we are using Power BI Embed, and this report will be loaded with the help of Embedded URL and We’ll use Authorization Token for Authentication.

 

Power Integration Steps

  1. Generate Bearer token for Authenticate your application with Azure Active Directory with help of User Id, Password, ClientID, Client Secret key of Azure portal. We are going to generate this with the help of Postman. This bearer token will be used to access all the APIs related to Power BI.

I.E. Get Workspace list inside Active Directory, Get Workspace items list, etc.

API URL for generating Bearer token: https://login.microsoftonline.com/common/oauth2/token 

 

  1. Now, we have Bearer Token. We’ll get Workspace (Groups) list with the help of that bearer token. Below API will provide Workspace Details. Like Workspace Name, id, IsReadOnly, etc.

API URL:  https://api.powerbi.com/v1.0/myorg/groups/

 

  1. Now we have bearer Token and group details. Based on these all details. We’ll get report details which we hosted for integration.  We have different API methods for fetch report details, which will be used to integrate with our application. It will provide report id, name, report type, Web URL, Embed URL, Dataset Id, etc.

Web URL: It can be accessed without authentication, which is open for all. You can access reports by browsing the URL in the browser directly.

Embed URL: It is Secure URL which we are going to use for secure integration purpose.

API URL: https://api.powerbi.com/v1.0/myorg/groups/{GroupID}/reports

 

  1. Now we have all the required details to access the Power BI report. But still, we cannot access the report. It will require an Authentication token for that specific report to access it.  So, we’ll generate a Token for it.

API URL:   https://api.powerbi.com/v1.0/myorg/groups/{GroupID}/reports/{ReportId}/generatetoken
 

 

  1. We’ll Use Embed URL and Report Authentication Token to integrate a report with Existing Application.  
    1. Create a sample MVC application
    2. Create All the API methods as explained in step 1 to 4
    3. Add below code in the controller  

    1. Add the below code in the view.

    1. Now, Run the project it will display sample reports in a web browser.

Conclusion:

After reading the blog, We have learned about Power BI API and the integration of those APIs into ASP.NET MVC application.

 

RELATED BLOGS:

What is meant by MSBI?

Rashesh Chothani

About the Author

Rashesh Chothani

Experienced Software Engineer with a demonstrated history of working in the information technology and services industry. Skilled in SQL, Web Applications, C#, jQuery, Javascript. Strong engineering professional with a Bachelor's degree focused in Computer Software Engineering from veerayatan group of institution.