node.js - 使用 NodeJs SDK 填充 DocuSign 信封定义上的选项卡

标签 node.js docusignapi

我正在使用 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 部分,此代码可以正常运行,我可以检索签名 URL 并将用户重定向到那里。

我做错了什么?

这个StackOverflow post当使用某种形式的 XML API 请求时,似乎回答了这个问题。但是我如何使用 NodeJs SDK 来做到这一点?

最佳答案

看起来我的代码是正确的,但是SDK中有一个错误:Unable to send tabs #50 .

解决方案:

I was correctly constructing the request -- but the node client populates all empty model parameters with null

Recursively stripping the nulls from the envelope before submitting the request solved this issue for me:

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;
}

Reference

我像这样使用这个函数:

tRole.setTabs(removeNulls(tabs));

关于node.js - 使用 NodeJs SDK 填充 DocuSign 信封定义上的选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39585598/

相关文章:

javascript - 如何从 MongoDB 中清除重复的对象

javascript - 异步函数中的可选参数

javascript - npm 'module not found' ,但一切似乎都设置正确

c# - 发送信封后从嵌入式签名切换到远程签名

docusignapi - 如何取消使用 anchor 标记放置的复选框的分组

javascript - 如何使用一个新的 Error() 显示多个 javascript 错误?

javascript - 如何比较 Node js中的两个数组?

docusignapi - OAuth - DocuSign 登录页面显示 'The client id provided is not registered with DocuSign.'

python - 在使用新生成的 token 进行 API 调用时遇到问题。 PARTNER_AUTHENTICATION_FAILED?

java - DocuSign Rest API 轮询状态更新