5

I am trying to download a PDF from a website using Javascript in the "Code" step in Zapier. I am struggling to find documentation on how to output the file object. Here is my basic code so far. unfortunately, the file that comes back is garbage characters. Perhaps it needs to be encoded? I would also like any advice you might have on how I would modify this code if the file I wanted was on a website that required basic authentication. Any advice would be greatly appreciated:

fetch('http://www.pdf995.com/samples/pdf.pdf')
  .then(function(res) {
    return res.text();
  })
  .then(function(body) {
    var output = {id: 1234, myPDF: body};
    callback(null, output);
  })
 .catch(callback);
  • Any update on this issue, ?i'm facing the same problem on Zapier , i need to download a zip file. The re is no documentation on how to handle it – Safety Mar 29 '22 at 23:28

1 Answers1

0

You're code should work fine. If you're doing something like sending an email or uploading to Dropbox, you can select "Run JavaScript" in the attachment or upload document option and choose your JavaScript action.

I've only been able to generate a PDF locally so far using res.buffer() instead of res.text() and then passing the buffer to fs.writeFile().

dahveed707
  • 907
  • 6
  • 14