https://api.na1.echosign.com/api/rest/v5/agreements/{agreementId}/combinedDocument
I am trying to create a file from the body of the response, but it is creating a file that I can't open. It requires a password even though there isn't one on the file. I think this must have something to do with the encoding / decoding.
I am using a node express server. Here are the few lines of code I am using:
var request = require('request');
request({
baseUrl: 'https://api.na1.echosign.com/api/rest/v5',
url: '/agreements/' + req.params.id + '/combinedDocument',
headers: {'Access-Token': process.env.ECHOSIGN_INTEGRATIONKEY}
},
function(error, response, body){
if(error) {
res.send(error);
}
else {
var buf = new Buffer(body)
res.set({
'Content-Disposition': 'attachment; filename=test.pdf',
'Content-Type': 'application/pdf; charset=utf-8'
});
res.write(buf);
res.end();
}
}
);
This is what ended up working in the end in case somebody else stumbles across this. I think the problem was that the data being returned from the API is a stream and it needed to have the chunking logic and then get concatenated in order to avoid getting corrupted.
Also included is encoding to base64, pushing it into a database and then getting it back, decoding it and pushing it to the browser. I wasn't going to leave it like that, but had it set up that way to test the full cycle.