This topic was automatically generated from Slack. You can find the original thread here.
Neil Lovelace : Good Morning Everyone,
I have another issue that I can’t seem to figure out. I’m needing to download a PDF from my e-signature platform PandaDoc via Axios; to do this I must use authentication, which I am doing. It works in PostMan, but I’m missing something in PipeDream.
In my code, I am calling this async function using await download(...) which is supposed to write to the /tmp directory but am continuing to get a 401 error and the message indicating that I must await all promises, which is puzzling as I am using async/await function as well as await Axios to download the file. Any suggestions are welcomed.
async function download(token, doc_id, fileName){
const AXIOS = require("axios");
const FS = require("fs");
// SET THE FILE PATH FOR TEMP STORAGE
const filePath = `/tmp/${fileName}`;
// DOWNLOAD ATTACHMENT
const response = await AXIOS({
url: `${PD_BASEURL}/public/v1/documents/${doc_id}/download`,
method: 'GET',
responseType: 'stream',
headers: AXIOS_HDR(token)});
}
//WRITE THE FILE TO TEMP STORAGE
response.data.pipe(FS.createWriteStream(filePath));
return new Promise((resolve, reject) => {
response.data.on('end', () =>{
resolve();
});
response.data.on('error', err => {
reject(err);
});
});
console.log(`File Saved To /tmp`);
Giao Phan : May not be an answer to your problem, but I’ve found using nodejs stream.pipeline is less error prone than trying to handle the callbacks yourself: Stream | Node.js v10.24.0 Documentation
Dylan Sather (Pipedream) : the 401 error suggests that’s the token either isn’t getting passed correctly, or the access token could be expired. How are you generating that access token? Could it be expired?
Neil Lovelace : Feel free.
I just noticed that maybe I need to place the function that builds the header inside of the download function. Perhaps it is a scope thing after all.
Neil Lovelace : My Checkpoint step is turned off at the moment. It ends the workflow when no metadata is returned… which is all of those errors stating that it can’t read property substring from undefined.
Dylan Sather (Pipedream) : are you able to get the workflow back to the state where you were encountering the 401s? I’d like to make a small change just to enable more logging in the HTTP request, which should help us identify the core issue
Dylan Sather (Pipedream) : would you mind triggering a new request? I made the change but I’m hitting your checkpoint logic trying to process a previous event