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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
trpeel
Frequent Visitor

Get File Of Export To File In Group - NodeJS / React

Hello. I am trying to figure out how to stream/download the exported PDF file from a Power BI API Export call. I'm using a NodeJS backend with a React frontend. Here's what I'm trying to do in the backend:

 

 

const queryResults = await fetch(`https://api.powerbi.com/v1.0/myorg/groups/${workspaceId}/reports/${reportId}/exports/${exportId}/file`, {
      method: 'GET',
      headers: {
        'content-type': 'application/pdf',
        authorization: `Bearer ${(await getAccessToken()).accessToken}`
      }
    });

    return queryResults;

 

 
 
All I get is a JSON response of { size: 0, timeout: 0}. I've found some C# samples online for streaming the PDF file back to the browser, but nothing for NodeJS. Any help would be appreciated.
 
Thanks.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @trpeel ,

It sounds like you are trying to download a PDF file that has been exported from a Power BI report using the Power BI API. However, it return size 0. The possible reason is the API call is not correctly authenticated. Please update the code as below and check if it can return the expected result...

const fetch = require('node-fetch');
const workspaceId = '<your workspace ID>';
const reportId = '<your report ID>';
const exportId = '<your export ID>';
const accessToken = '<your access token>';
const url = `https://api.powerbi.com/v1.0/myorg/groups/${workspaceId}/reports/${reportId}/exports/${exportId}/file`;
const options = {
  method: 'GET',
  headers: {
    'Content-Type': 'application/pdf',
    'Authorization': `Bearer ${accessToken}`
  }
};
fetch(url, options)
  .then(response => {
    if (!response.ok) {
      throw new Error(`HTTP error ${response.status}`);
    }
    return response.buffer();
  })
  .then(buffer => {
    // Do something with the PDF buffer, such as write it to a file or send it to the client
  })
  .catch(error => {
    console.error(error);
  });

Best Regards

View solution in original post

2 REPLIES 2
trpeel
Frequent Visitor

Thank you very much. The response.buffer was the part I was missing. I appreciate the help.

Anonymous
Not applicable

Hi @trpeel ,

It sounds like you are trying to download a PDF file that has been exported from a Power BI report using the Power BI API. However, it return size 0. The possible reason is the API call is not correctly authenticated. Please update the code as below and check if it can return the expected result...

const fetch = require('node-fetch');
const workspaceId = '<your workspace ID>';
const reportId = '<your report ID>';
const exportId = '<your export ID>';
const accessToken = '<your access token>';
const url = `https://api.powerbi.com/v1.0/myorg/groups/${workspaceId}/reports/${reportId}/exports/${exportId}/file`;
const options = {
  method: 'GET',
  headers: {
    'Content-Type': 'application/pdf',
    'Authorization': `Bearer ${accessToken}`
  }
};
fetch(url, options)
  .then(response => {
    if (!response.ok) {
      throw new Error(`HTTP error ${response.status}`);
    }
    return response.buffer();
  })
  .then(buffer => {
    // Do something with the PDF buffer, such as write it to a file or send it to the client
  })
  .catch(error => {
    console.error(error);
  });

Best Regards

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.