API Reference
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

const axios = require('axios');  
const fs = require('fs');

// Replace these with your actual values  
const EQUIDAM_BASE_URL = 'EQUIDAM_BASE_URL' ///'<https://obiwan.equidam.com'>;  
const companyId = 'YOUR_COMPANY_ID';  
const reportId = 'YOUR_REPORT_ID';  
const authToken = 'YOUR_AUTH_TOKEN';  
const filename = 'report.pdf';

const getCompanyReport = async (cid, rid, authToken) => {  
    const response = await axios.get(`${EQUIDAM_BASE_URL}/api/v3/companies/${cid}/reports/${rid}?format=pdf`, {  
        headers: {  
            Authorization: `Bearer ${authToken}`,  
        },  
        responseType: 'arraybuffer' // telling axios to handle binary data  
    });  
    return response.data;  
}

const saveReportToFile = async (cid, rid, authToken, filename) => {  
    const reportData = await getCompanyReport(cid, rid, authToken);  
    fs.writeFile(filename, reportData, 'binary', (err) => {  
        if (err) {  
            console.error("An error occurred while saving the report file:", err);  
        } else {  
            console.log("Report saved successfully.");  
        }  
    });  
}



saveReportToFile(companyId, reportId, authToken, filename);