Forum Discussion
trpeel
2 years agoFrequent 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 ba...
- Anonymous2 years ago
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
Anonymous
2 years agoNot 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