我正在使用DocuSign NodeJS SDK从我已经从DocuSign控制台设置的模板创建签名请求。我还在文档上设置了一个文本字段。我想在发送签名请求时自动填充此字段。
以下是我的代码的相关部分(大部分内容只是从食谱中复制而来):
var envDef = new docusign.EnvelopeDefinition();
envDef.setEmailSubject('Ready for Signing');
envDef.setTemplateId(templateId);
// create a template role with a valid templateId and roleName and assign signer info
var tRole = new docusign.TemplateRole();
tRole.setRoleName("Role1");
tRole.setName(role1FullName);
tRole.setEmail(role1Email);
tRole.setClientUserId(role1UserId);
/**************SET TABS******************/
//set tabs
var text = new docusign.Text();
text.setTabLabel("textFoo"); //This is the data label I setup from the console.
text.setValue("Foo Bar Zoo"); //Some text I want to have pre-populated
var textTabs = [];
textTabs.push(text);
var tabs = new docusign.Tabs();
tabs.setTextTabs(textTabs);
tRole.setTabs(tabs);
/**************END SET TAB******************/
// create a list of template roles and add our newly created role
var templateRolesList = [];
templateRolesList.push(tRole);
// assign template role(s) to the envelope
envDef.setTemplateRoles(templateRolesList);
// send the envelope by setting |status| to 'sent'. To save as a draft set to 'created'
envDef.setStatus('sent');
当我运行时,我收到以下错误:
Bad Request
at Request.callback (C:\Users\janak\NodeProjects\DocuFire\node_modules\superagent\lib\node\index.js:823:17)
at IncomingMessage.<anonymous> (C:\Users\janak\NodeProjects\DocuFire\node_modules\superagent\lib\node\index.js:1046:12)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:975:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
注意:如果我注释掉SET TABS
部分,此代码运行正常,我可以检索签名网址并将用户重定向到那里。
我做错了什么?
在使用某种形式的XML API请求时,StackOverflow post似乎回答了这个问题。但是我如何使用NodeJs SDK做到这一点?
答案 0 :(得分:1)
看来我的代码是正确的,但SDK中存在错误:Unable to send tabs #50。
<强>解决方案:强>
我正确构建了请求 - 但是节点客户端使用null
填充所有空模型参数在提交请求之前以递归方式从信封中删除空值为我解决了这个问题:
removeNulls = function(envelope) { var isArray = envelope instanceof Array; for (var k in envelope) { if (envelope[k] === null) isArray ? obj.splice(k, 1) : delete envelope[k]; else if (typeof envelope[k] == "object") removeNulls(envelope[k]); if (isArray && envelope.length == k) removeNulls(envelope); } return envelope; }
我像这样使用这个功能:
tRole.setTabs(removeNulls(tabs));