Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

v-yiruan-msft

How to use Power BI Rest API to export the Power BI Report in PDF format

Scenarios

In Power BI Service, we can export reports in PDF format and easily create documents or slides based on Power BI Reports. Here is another way that allows us to use the Rest API call and export the Power BI Report in PDF. This method cannot be run in Pro and PPU, it is only suitable for implementation in premium workspace.

The specific operation is:

  1. Call the Report – Export to File in Group Rest API and the prepared groupId and reportId, and issue the Post command to get the exportId.
  2. Call the Reports-Get Export to File Status in Group Rest API and the prepared groupId, reportId and exportId to query the current status. If the session is successful, go to the third step, if it does not appear, follow the error message to repair.
  3. Execute the Reports-Get File of Export to File in Group Rest API to get the Bearer code.
  4. In the Postman software, get the Power BI Report in PDF format.

Tip: The position of groupId and reportId is in the URL:

yingyinr_0-1636436969202.png

Sample data:

Get data: Samples -- Human Resources Sample.

yingyinr_1-1636436997705.png

PBIX visual:

yingyinr_2-1636436997711.png

Expected result:

Successfully exported Power BI Report in PDF format through Rest API.

Step 1: Execute the first Rest API and issue the Post command to get the exportId.

            Go to the Report – Export to File in Group page.

            1). Enter the Report – Export to File in Group page

            2). Click Try It, copy the prepared groupId and reportId, and fill in format: "PDF" in the Body

            yingyinr_0-1636437531233.png

            3). Click Run, generate the exportId we need, and save the exportId

           yingyinr_5-1636439248923.png

            Notice:

            Introduction of the information in the Body column:

              "@odata.context": The content of the Post request sent

               "id": action ID of the operation

               "createdDateTime": the time when the operation was created

               "lastActionDateTime": the last time of the operation

               "reportId": report action ID

               "status": Status

               "percentComplete": complete percentage progress

               "expirationTime": the expiration time of operation   

Step 2: Execute the second Rest API to query the current status. If the session is successful, go to the third step.

            1). Enter the Reports-Get Export to File Status in Group interface

            2). Click Try It , copy and paste the prepared groupId, reportId and exportId into the right places

            yingyinr_6-1636439430363.png

           3). Click Run and find that the message "status: Succeeded" appears, the session is successful.

            yingyinr_7-1636439464047.png

Step 3: Execute the third Rest API, get the Bearer code, and experiment with PDF export.

            1). Enter the Reports-Get File of Export to File in Group interface

            2). Click Try It, copy and paste the prepared groupId, reportId and exportId into the right places

           yingyinr_8-1636439888464.png

          3). Click Run, If the execution is successful, the Bearer code and Request URL will be obtained, then the experiment is a success.

           yingyinr_9-1636439888473.png

Step 4: Enter the Postman software and get the PDF file of the Power BI Report.

           1). Go to Collections--PBI_API—click the ellipsis—click “Add request”

           yingyinr_10-1636439888483.png

           2). On the new interface that appears, place the Request URL and change it to GET.

           yingyinr_11-1636439888485.png

           3). Click Authorization, change the Type to Bearer Token, and place the Bearer code obtained in the Token column.

           yingyinr_12-1636439888493.png

            4). Click Headers, copy and paste the prepared groupId, reportId and exportId into the right places.

           yingyinr_13-1636440429197.png

           5). Click Send, the PBIX visual object is generated in the Body interface below, and click Save Response-Save to file.

           yingyinr_14-1636440429213.png

           6). Generate PDF.

           yingyinr_15-1636440429220.png 

Note

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.

Postman related information:

https://www.postman.com/

Web version of Postman:

https://identity.getpostman.com/signup?continue=https%3A%2F%2Fgo.postman.co%2Fbuild&_ga=2.103938564....

Download Postman:

https://www.postman.com/downloads/

 

Hope this article can help you solve similar problems.

 

Author: Yang Liu 

Reviewer: Ula Huang, Kerry Wang

Comments