![1707701425_large.pngcharsetUTF-8](https://quantinsightsnetwork.com/wp-content/uploads/2024/02/1707701425_large.png;charset=UTF-8-678x193.png;charset=utf-8)
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:
- 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.
- 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.
- Execute the Reports-Get File of Export to File in Group Rest API to get the Bearer code.
- In the Postman software, get the Power BI Report in PDF format.
Tip: The position of groupId and reportId is in the URL:
Sample data:
Get data: Samples — Human Resources Sample.
PBIX visual:
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
3). Click Run, generate the exportId we need, and save the exportId
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
3). Click Run and find that the message “status: Succeeded” appears, the session is successful.
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
3). Click Run, If the execution is successful, the Bearer code and Request URL will be obtained, then the experiment is a success.
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”
2). On the new interface that appears, place the Request URL and change it to GET.
3). Click Authorization, change the Type to Bearer Token, and place the Bearer code obtained in the Token column.
4). Click Headers, copy and paste the prepared groupId, reportId and exportId into the right places.
5). Click Send, the PBIX visual object is generated in the Body interface below, and click Save Response-Save to file.
6). Generate PDF.
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:
Web version of Postman:
Download Postman:
https://www.postman.com/downloads/
Hope this article can help you solve similar problems.
Author: Yang Liu
Reviewer: Ula Huang, Kerry Wang
Be the first to comment