API returned PDF data sample looks like -
Below is JavaScript code which I am using to download PDF, I tried many solutions, but none of them worked.
const reportPdfDoc = await axiosBIInstance.get( `https://api.powerbi.com/v1.0/myorg/reports/${config.reportId}/exports/${exportID?.data?.id}/file`, { headers: { Authorization: 'Bearer ' + accessToken, responseType: 'arraybuffer',// I've used blob as well, but same result }, }, ); if (reportPdfDoc?.status === 200) { const blob = new Blob([reportPdfDoc.data], { type: 'application/pdf', }); const computedFileName = `${exportStatus?.data?.reportName}.pdf`; const a = document.createElement('a'); a.href = window.URL.createObjectURL(blob); a.download = computedFileName; document.body.appendChild(a); a.click(); document.body.removeChild(a);
I tried the solution posted above and it worked for me.I am reposting it below.
I got the issue, responseType property should be outside of header in axios call. like -
const reportPdfDoc = await axiosBIInstance.get( https://api.powerbi.com/v1.0/myorg/reports/${config.reportId}/exports/${exportID?.data?.id}/file, { headers: { Authorization: 'Bearer ' + accessToken, }, responseType: 'blob', }, );