我正在使用以下代码尝试使用c#API的AddDocument函数将pdf文档添加到包含多个文档的现有模板,但结果始终为false。成功发送模板,并正确发送所有预设文档。如何正确添加pdf文档?我必须使用代码添加pdf文档,因为每次发送模板时此特定文档都不同。我测试了GetIPS函数,它返回了pdf文档的byte [],所以我知道这不是问题。
这是我的代码
byte[] ips = GetIPS("");
RestSettings.Instance.DocuSignAddress = "https://demo.docusign.net";
RestSettings.Instance.WebServiceUrl = RestSettings.Instance.DocuSignAddress + "/restapi/v2";
RestSettings.Instance.IntegratorKey = integratorKey;
DocuSign.Integrations.Client.Account account = new DocuSign.Integrations.Client.Account();
account.Email = username;
account.Password = password;
var loginResult = account.Login();
Template template = new Template();
template.TemplateId = templateId;
template.Login = account;
template.EmailSubject = emailSubject;
template.EmailBlurb = emailMessage;
var documents = template.GetDocuments();
TemplateRole tr = new TemplateRole();
var roles = new List<TemplateRole>();
//Handle Primary Client
roles.Add(new TemplateRole
{
roleName = "Primary Client",
name = primaryClientName,
email = primaryClientEmail,
tabs = new RoleTabs
{
textTabs = new RoleTextTab[] {
new RoleTextTab {
tabLabel = "FeeEffectiveDate",
value = effectiveDate
},
new RoleTextTab {
tabLabel = "FeePercentage",
value = fee
}
}
},
});
if (secondaryClientName.Trim().Length != 0)
{
roles.Add(new TemplateRole
{
roleName = "Secondary Client",
name = secondaryClientName,
email = secondaryClientEmail,
});
}
roles.Add(new TemplateRole
{
roleName = "President",
name = presidentName,
email = presidentEmail,
});
roles.Add(new TemplateRole
{
roleName = "Css",
name = cssName,
email = cssEmail,
});
template.TemplateRoles = roles.ToArray<TemplateRole>();
template.Status = "sent";
//The following code always return false
bool status = template.AddDocument(ips, "IPS.pdf", 1);
var result = template.Create();
答案 0 :(得分:1)
为了使用AddDocument
函数,信封必须处于草稿状态(您也可以在source code中的此函数的备注中看到)。因此,在您的情况下,您必须首先创建一个草稿信封(通过将信封状态更改为&#34;创建&#34;),然后调用AddDocument
功能,最后将信封状态更新为&#34 ;发送&#34;发送信封。
例如:
.
.
.
template.Status = "created";
var result = template.Create();
bool status = template.AddDocument(ips, "IPS.pdf", 2);
template.Status = "sent";
result = template.UpdateStatus();
请注意,文档索引是文档ID,必须与模板中现有文档的ID不同。否则,具有相同ID号的现有文档将被新文档替换。