2015-11-12 80 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號的現有文檔將被新文檔替換。