1

Im making a call via Request to docusign like so:

 var options = {
    method: 'GET',
    url: `${baseUrl}/envelopes/${envelopeId}/documents/${documentId}`,
    headers: headers,
    qs: {
        encoding: 'base64'
    }
};

request(options, function (error, response, body) {
...
})

Im getting back the document string but when I write it to a .pdf I get 4 blank pages. Here is the code im using to write it to a file:

fs.writeFile('cert.pdf', body, (err) => {
            if(err) throw new Error(err)
        })

Nodejs -v 8.11.1

Meisterunner
  • 222
  • 4
  • 13

1 Answers1

0

Two issues:

  1. I'd leave out the qs: {encoding: 'base64'} option. The document will be returned as a binary file. (Which is what you want.)

  2. When you write the file, specify binary format. On a Linux system, there is no difference. But on Windows there is.

For a code example of retrieving a document, see this file.

Larry K
  • 47,808
  • 15
  • 87
  • 140