Он не читает свойство res.body.signatureRequestId
для моего Express js сервера. Как передать свойство, чтобы избежать ошибки в типовой ошибке? Я поделился своим журналом ошибок, json ответом, express js кодом с нижеследующим.
Журнал ошибок:
{
account: {
account_id: 'aaa',
email_address: 'xxx@gmail.com',
is_locked: false,
is_paid_hs: false,
is_paid_hf: false,
quotas: {
templates_left: 0,
documents_left: 2,
api_signature_requests_left: 0
},
callback_url: 'https://hellosigntest.info/api/callback',
role_code: null
},
resHeaders: {
'access-control-allow-headers': 'Authorization, Origin, X-Requested-With, Content-Type, Accept',
'access-control-allow-methods': 'GET, POST, OPTIONS',
'access-control-allow-origin': '*',
'content-type': 'application/json',
date: 'Fri, 10 Apr 2020 10:01:26 GMT',
p3p: 'CP="NOP3PPOLICY"',
server: 'Apache',
'strict-transport-security': 'max-age=15768000',
'user-agent': 'HelloSign API',
vary: 'Accept-Encoding',
'x-ratelimit-limit': '2000',
'x-ratelimit-limit-remaining': '1999',
'x-ratelimit-reset': '1586512887',
'content-length': '329',
connection: 'Close'
},
statusCode: 200,
statusMessage: 'OK'
}
Hello API Event Received
TypeError: Cannot read property 'signature_request_id' of undefined
at /Desktop/nodejs/helloSignDemo/routes/index.js:50:54
at Layer.handle [as handle_request] (/Desktop/nodejs/helloSignDemo/node_modules/express/lib/router/layer.js:95:5)
at next (/Desktop/nodejs/helloSignDemo/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Desktop/nodejs/helloSignDemo/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Desktop/nodejs/helloSignDemo/node_modules/express/lib/router/layer.js:95:5)
at /Desktop/nodejs/helloSignDemo/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Desktop/nodejs/helloSignDemo/node_modules/express/lib/router/index.js:335:12)
at next (/Desktop/nodejs/helloSignDemo/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/Desktop/nodejs/helloSignDemo/node_modules/express/lib/router/index.js:174:3)
at router (/Desktop/nodejs/helloSignDemo/node_modules/express/lib/router/index.js:47:12)
События, отправленные на ваш URL обратного вызова, будут отформатированы как JSON строка, содержащаяся в параметре json POST. Полную информацию об объекте события можно найти в разделе событий справочной страницы API. Вот пример события, которое может быть получено:
{
"account_guid": "aaa", // DEPRECATED: use reported_for_account_id instead
"client_id": null, // DEPRECATED: use reported_for_app_id instead
"event": {
"event_time": "1348177752",
"event_type": "signature_request_sent",
"event_hash": "aaa",
"event_metadata": {
"related_signature_id": "aaa",
"reported_for_account_id": "aaa",
"reported_for_app_id": null
}
},
signature_request: {
signature_request_id: 'aaaaa',
test_mode: true,
title: 'PDF Sign via Node Server',
original_title: 'PDF Sign via Node Server',
subject: 'PDF Sign via Node Server',
message: 'Please sign this pdf.',
metadata: {},
created_at: 1586507276,
is_complete: false,
is_declined: false,
has_error: false,
custom_fields: [],
response_data: [],
signing_url: 'https://xxxcom/aaa',
signing_redirect_url: null,
final_copy_uri: '/v3/signature_request/final_copy/aaa',
files_url: 'https://api.hellosign.com/v3/signature_request/files/aaa',
details_url: 'https://app.hellosign.com/home/manage?guid=aaa',
requester_email_address: 'xxx@gmail.com',
signatures: [ [Object] ],
cc_email_addresses: [],
template_ids: null
}
}
маршрутов / индекс js:
const express = require('express');
const router = express.Router();
const hellosign = require('hellosign-sdk')({ key: 'key' });
const fs = require('fs');
hellosign.account.update({
callback_url: process.env.HOST_URL+'/api/callback'
}).then((res) => {
// handle response
console.log(res)
}).catch((err) => {
// handle error
console.log(err)
});
router.post('/sign',(req,res)=>{
const opts = {
test_mode: 1,
title: 'PDF Sign via Node Server',
subject: 'PDF Sign via Node Server',
message: 'Please sign this pdf.',
signers: [
{
email_address: 'xxx@gmail.com',
name: 'xxx'
}
],
files: ['nda.pdf']
};
hellosign.signatureRequest.send(opts).then((res) => {
// handle response
console.log(res)
}).catch((err) => {
// handle error
console.log(err)
});
});
router.post('/callback',(req,res)=>{
res.send('Hello API Event Received');
res.send(res.body);
try {
hellosign.signatureRequest.download(res.body.signatureRequestId, { file_type: 'zip' }, (err, res) => {
const file = fs.createWriteStream('files.zip');
res.pipe(file);
file.on('finish', () => {
file.close();
});
});
}catch (e) {
console.log(e)
}
});
router.get('/', (req, res) => {
res.send("Server is listening...")
});
module.exports = router;
index. js
const express = require('express');
const app = express();
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.use('/api',require('./routes/index'));
app.listen(process.env.PORT,function(){
console.log("Started on PORT "+process.env.PORT);
});