Reputation: 21
axios({
method: 'get',
url: `https://demo.docusign.net/restapi/v2/accounts/{AccountID}/envelopes/{ID}/documents/1`,
headers: {
'X-DocuSign-Authentication': JSON.stringify({
"Username": docusign.username,
"Password": docusign.password,
"IntegratorKey": docusign.integratorKey
}),
'Content-Type': 'application/json'
},
}).then(response => {
fs.writeFileSync('./i.pdf', response.data, {encoding: 'binary'})
}).catch(console.log)
With the above code I am unable to save the proper file, Can you any help on this
Upvotes: 2
Views: 729
Reputation: 87
Arjun I found a solution please check the below code.
let docuResponce = axios({
method: 'get',
url:`https://demo.docusign.net/restapi/v2/accounts/{AccountID}/envelopes/{ID}/documents/1`,
headers: {
'X-DocuSign-Authentication': JSON.stringify({
"Username": docusign.username,
"Password": docusign.password,
"IntegratorKey": docusign.integratorKey
}),
'Content-Type': 'application/pdf'
},
responseType: 'stream'
});
var fs = require('fs');
var path = require('path');
// file name
var filename = envelopID + '_' + docusign.accountID + '.pdf';
var tempFile = path.resolve(__dirname, filename); // file path
// generate a file stream
docu.data.pipe(fs.createWriteStream(tempFile));
docu.data.on('end', () => {
// file has been download
res.status(200).json({ success: 'true', data: '' });
});
docu.data.on('error', (err) => {
// error in download
res.status(200).json({ success: 'false', data: '' });
});
Upvotes: 1
Reputation: 14050
Upvotes: 0