Creating package with multiple document binaries, uploading with superagent.
Monday, May 9, 2016 at 08:00amHi!
I have been trying to upload multiple documents with a post request to '/api/packages' (the sandbox) url and getting getting the error indicating the number of documents sent in the payload is different from what I attached,
Could have a look at the code and let me know, what I am missing?
var httpReq = require('superagent');
var _ = require('lodash');
var createPackageReq = httpReq
.post(config.esignature.host + '/packages')
.set('Content-type', 'multipart/form-data')
.set('Accept', 'application/json')
.set(SILANIS_AUTHORIZATION); //my API Key
//req is the request passed on to this function from my UI
_.keys(req.body.documents).forEach(function(docName) {
documents.push({name: docName});
createPackageReq
.attach(docName, req.body.documents[docName].result.path);
});
var stringData = JSON.stringify({documents: documents});
createPackageReq
.field('payload', stringData)
..end(function(err, resp) {
if(err) {
// console.log(resp.error);
throw err;
}
if (resp.statusCode === 200) {
// console.log(resp.body);
res.send(resp.body);
} else {
res.sendStatus(resp.statusCode);
}
});
and below is the error I am getting,
[Error: cannot POST /api/packages (400)]
status: 400,
text: '{
"entity":null,
"messageKey":"error.validation.package.wrongNumberOfFiles",
"technical":"Number of uploaded files does not match number of documents specified in package.",
"packageId":null,
"message":"Number of uploaded files does not match number of documents specified in package.",
"code":400,
"name":"Validation Error"
}',
method: 'POST',
path: '/api/packages'
Thanks,
Vinay
Reply to: Creating package with multiple document binaries, uploading with superagent.
Monday, May 9, 2016 at 09:33amPOST /api/packages/ HTTP/1.1 Host: sandbox.e-signlive.com Authorization: Basic your_api_key Accept: application/json Cache-Control: no-cache Postman-Token: e4121be4-f632-387b-f077-415df005e2d5 Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW ----WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="file"; filename="" Content-Type: ----WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="file"; filename="" Content-Type: ----WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="payload" { "documents": [ { "name": "doc1" },{ "name": "doc2" } ], "type": "PACKAGE", "status": "DRAFT", "name": "testing this!" } ----WebKitFormBoundary7MA4YWxkTrZu0gWReply to: Creating package with multiple document binaries, uploading with superagent.
Monday, May 9, 2016 at 01:08pm