注意:我正在使用「經典」體驗,因爲新界面無法爲模板設置未來簽名人所需的字段。如何預先填充使用Docusign的REST API從模板創建的信封中的字段?
的工作流程:
- 有一堆使用API領域
的模板:
從模板創建一個信封/文檔,並分配一個新用戶簽署(此文件將成爲註冊服務協議)
- 創建新角色
- 集ROLENAME僞造簽名模板
- 添加textTabs嘗試perfill一些字段(因爲我不能沒有在模板上至少一個簽名者配置字段)。
檢索收件人
- 創建收件人視圖,使我得到的URL就擺在一個iframe
這是一種令人厭惡的,因爲我不在乎關於第一個簽署者不是用戶註冊該服務。然而,我會喜歡在簽名後將文檔複製到某個人,但是docusign似乎不支持(我已經找到了)。
下面是創建信封Node.js的代碼(在那裏我覺得我的API的使用是怎麼了?):
function createEnvelopeDefinition(templateId, userData) {
var envDef = new docusign.EnvelopeDefinition();
envDef.setEmailSubject('Signup Agreement');
envDef.setTemplateId(templateId);
var tRole = new docusign.TemplateRole();
tRole.setRoleName('RoleOne');
tRole.setName(userData.fullName);
tRole.setEmail(userData.email);
tRole.setClientUserId('2');
tRole.setTabs(new docusign.Tabs());
tRole.getTabs().setTextTabs([]);
const fieldsToPreFill = [
'field1',
'field2',
'field3',
'field4'];
fieldsToPreFill.forEach(fieldName => {
let textTab = new docusign.Text();
let value = userData[fieldName];
if (value === null || value === undefined) { value = 'not null'; }
textTab.setTabLabel(fieldName);
textTab.setValue(value);
tRole.getTabs().getTextTabs().push(textTab);
});
tRole = removeNulls(tRole);
envDef.setTemplateRoles([tRole]);
// send the envelope by setting |status| to 'sent'.
// To save as a draft set to 'created'
// sent is required for getting view URLs
envDef.setStatus('sent');
return envDef;
}
在上的DocuSign模板編輯器中,Data Field Tag Properties
顯示每個標籤field1
,field2
等
這些字段現在填寫提供的值時,我把新的信封放入iframe中。
僅供參考下面是創建API接口的代碼的其餘部分,並獲取視圖URL
import ENV from 'environment/backend';
const accountId = ENV.docusign.accountId;
var Promise = require('bluebird');
var docusign = require('docusign-esign');
export function newApiClient() {
let apiClient = new docusign.ApiClient();
apiClient.setBasePath(ENV.docusign.endpoint);
// create JSON formatted auth header
let creds = JSON.stringify({
Username: ENV.docusign.email,
Password: ENV.docusign.password,
IntegratorKey: ENV.docusign.integratorKey
});
apiClient.addDefaultHeader('X-DocuSign-Authentication', creds);
// assign api client to the Configuration object
// this probably doesn't need to be set every time...
docusign.Configuration.default.setDefaultApiClient(apiClient);
return apiClient;
}
const defaultApiClient = newApiClient();
const envelopesApi = new docusign.EnvelopesApi();
const createEnvelope = Promise.promisify(envelopesApi.createEnvelope, { context: envelopesApi });
const listRecipients = Promise.promisify(envelopesApi.listRecipients, { context: envelopesApi });
const createRecipientView = Promise.promisify(envelopesApi.createRecipientView, { context: envelopesApi });
export default defaultApiClient;
// promise resolves to the view URL, envelopeId for the user.
// returns a recipientView
export function setupDocumentForEmbeddedSigning(templateId, userData) {
let envDefinition = createEnvelopeDefinition(templateId, userData);
return createEnvelope(accountId, envDefinition, null)
.then(envelopeSummary => {
const envelopeId = envelopeSummary.envelopeId;
return createViewFromEnvelope(envelopeId);
});
}
export function createViewFromEnvelope(envelopeId) {
return getRecipients(envelopeId).then(recipients => {
// the last signer is the one we added in the
// createEnvelopeDefinition step
let signers = recipients.signers;
let lastSigner = signers[signers.length - 1];
return createView(envelopeId, lastSigner)
.then(recipientView => [recipientView.url, envelopeId]);
});
}
function getRecipients(envelopeId) {
return listRecipients(accountId, envelopeId);
}
function createView(envelopeId, signerData) {
var viewRequest = new docusign.RecipientViewRequest();
viewRequest.setReturnUrl(ENV.host);
viewRequest.setAuthenticationMethod('email');
// recipient information must match embedded recipient info
// from the createEnvelopeDefinition method
viewRequest.setEmail(signerData.email);
viewRequest.setUserName(signerData.name);
viewRequest.setRecipientId('2');
viewRequest.setClientUserId('2');
return createRecipientView(accountId, envelopeId, viewRequest);
}
// bug with the api wrapper
// https://github.com/docusign/docusign-node-client/issues/47
const removeNulls = function(obj) {
var isArray = obj instanceof Array;
for (var k in obj) {
if (obj[k] === null) isArray ? obj.splice(k, 1) : delete obj[k];
else if (typeof obj[k] == 'object') removeNulls(obj[k]);
if (isArray && obj.length == k) removeNulls(obj);
}
return obj;
};
我得到一個錯誤,現在:-(' 「{ ↵ 」錯誤碼「: 」UNSPECIFIED_ERROR「, ↵ 」消息「: 」非靜態方法需要一個目標「 ↵}」 ' 以下是我用來創建信封的json的用法:http://pastie.org/10926040 Docusign的錯誤很有幫助lol – NullVoxPopuli
所以,這就是您發送時的錯誤發送信封定義: - \ 現在,我實際上正在發送它,我得到''您確定的收件人不是指定信封的有效收件人。「# – NullVoxPopuli
您是否在」創建Ë nvelope「請求還是」Post Recipient View「請求?我建議捕捉出站請求的跟蹤(使用Fiddler或類似的東西)來排查故障 - 將請求的收件人部分與「獲取收件人」請求的結果進行比較,以確保您指定了正確的角色名稱等等。 –