Forum Discussion
Exporting report to PDF using REST API returns blank file
Hello guys,
I'm trying to export a paginated report to PDF file using Power BI REST API. My account is currently in free trial, but I've created Premium Per User workspace, where I have my Paginated Report:
I'm calling these API endpoints:
1. Export To File (to initialize exporting)
2. Get Export To File Status (for polling status)
3. Get File Of Export To File (retrieve the file)
When I try to export .PDF file, I get just blank pages. However, when I tried to export to simple .CSV, it works. Also tried .PPTX and when trying to open file it says it's corrupted.
I'm trying to also read through consideration and limitations for exporting paginated reports, but that wasn't that much helpful and it doesn't explain why the CSV would work and PDF not.
Any help will be appreciated. Thanks!
Found an error in my implementation. When using Axios for getting binary file data, I need to specify
responseType: 'arraybuffer'in the config. So it wasn't really a problem in the APIs itself, just my implementation. Full sample code:
const config = { headers: { Authorization: `Bearer ${authToken}`, }, responseType: 'arraybuffer' }; // Send the GET request axios.get(apiUrl, config) .then((response) => { // Handle the response data here const pdfFilePath = path.join(__dirname, 'ExportedReport.pdf'); fs.writeFileSync(pdfFilePath, response.data); })
5 Replies
- lbendlinSuper User
Try the same through Power Automate. Note that the PDF export is especially prone to rendering timeouts.
- pejRegular Visitor
Seems like that didn't work as well. For some reason, I wasn't able to send the PDF file as attachment to email using Power Automate, but Exporting to a PDF file generated some output like:
{"statusCode":200,.......,"body":{"$content-type":"application/pdf","$content":"JVBERi0xLjc............"}I just tried to save the decoded $content to a .PDF file manually, but that didn't work.
- pejRegular Visitor
I managed to make it work with Power Automate in such flow:
It successfully export the Paginated Report to PDF and upload it to SharePoint site (for some reason sending an email with attachment didn't work for me).
However, that really doesn't solve my issue of using simple REST API calls. This is a sample code of how I'm executing the 3rd API call to get the file content and save it:
axios.get(apiUrl, config) .then((response) => { const pdfData = response.data; const pdfFilePath = path.join(__dirname, 'ExportedReport.pdf'); fs.writeFileSync(pdfFilePath, pdfData); }), where apiUrl is Get File Of Export To File endpoint with exportId and reportId parameters.