2015-11-12 44 views
0

我正在使用以下代码尝试使用c#API的AddDocument函数将多个文档添加到现有模板的PDF文档,但结果始终为false。所有预设文件发送正确后,模板将成功发送。我如何正确添加PDF文档?我必须使用代码添加pdf文档,因为每次我们发送模板时,这个特定的文档都是不同的。我测试过GetIPS函数,它返回了pdf文档的字节[],所以我知道这不是问题。将文档添加到docusign信封始终返回false

这里是我的代码

  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(); 

回答

1

为了使用AddDocument功能,一个信封必须处于草案状态(你也可以在备注栏看到在source code此功能)。因此,对于您的情况,您必须首先创建草稿信封(将信封状态更改为“已创建”),然后调用函数,最后将信封状态更新为“发送”以发送信封。

例如:

. 
. 
. 
template.Status = "created"; 
var result = template.Create(); 

bool status = template.AddDocument(ips, "IPS.pdf", 2); 

template.Status = "sent"; 
result = template.UpdateStatus(); 

注意,文件索引的文档ID,并且必须在模板的现有文档的ID不同。否则,具有相同ID号的现有文档将被新文档替换。