使用 Docusign API 使用 c# sdk 将多个文档添加到信封

Add multiple documents to envelope using c# sdk using Docusign API

我在 Docusign 中有一个模板需要发送给 joe@acme.com

但是 Joe 负责管理 10 个客户,而不是我向 Joe 发送 10 个单独的信封让他签名,我想向 Joe 发送 1 个包含 10 份文件的信封,Joe 需要在信封中的所有 10 份文件上签名。除了模板文本字段中填写的不同数据外,这些文档完全相同

我正在使用 Docusign 提供的 C# SDK,我可以使用 EnvelopeDefinition class 和 TemplateRole class 在信封中发送一份文档,但我不知道如何在一个信封中创建 10 个文档

以下方法可以做到,但它在 python 中并使用 REST API,我不确定如何将其转换为等效的 C# SDK https://www.docusign.com/developer-center/recipes/send-multiple-docs

在class EnvelopeDefinition 中有属性 Documents,您可以在其中添加多个文档。

当我想检查如何实现功能时,我使用 DocuSign 的 REST API Explorer

            enDef = new EnvelopeDefinition();
            doc = new Document();

            doc.DocumentBase64 = System.Convert.ToBase64String(System.IO.File.ReadAllBytes(filename));
            doc.Name = DocName;
            doc.DocumentId = "1"; // increment this

            enDef.Documents = new List<Document>();
            enDef.Documents.Add(doc);

已添加

对于乘法模板角色,在 EnvelopeDefinition 中还存在一个名为 TemplateRoles 的 属性。在那里你可以添加多个。

            tempRole = new TemplateRole();
            tempRole.Name = Rolename;

            enDef.TemplateRoles = new List<TemplateRole>();
            enDef.TemplateRoles.Add(tempRole);`

您可以使用compositeTemplates and reuse the same server template multiple times in the envelope. The below code uses the same server Template and repeats it 10 times in the envelope. See full example here

public void CreateEnvelope()
{
  var envDef = new EnvelopeDefinition()
  {
      EmailSubject = "Envelope with multiple documents",
      Status = "sent",
      CompositeTemplates = new List<CompositeTemplate>()
  };

  for (int docNumber = 1; docNumber <= 10; docNumber++)
  {
      var compostiteTemplate = BuildCompositeTemplate(docNumber.ToString());
      envDef.CompositeTemplates.Add(compostiteTemplate);

  }

  EnvelopesApi envelopesApi = new EnvelopesApi();
  EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
  Console.WriteLine(envelopeSummary);
}

public CompositeTemplate BuildCompositeTemplate(string docNumber)
{
    string serverTemplateId = "";//Add your server template ID here
    return new CompositeTemplate()
    {
          ServerTemplates = new List<ServerTemplate>()
          {
              new ServerTemplate()
              {
                  TemplateId = serverTemplateId,
                  Sequence = docNumber
              }
          },
          InlineTemplates = new List<InlineTemplate>()
          {
              new InlineTemplate()
              {
                  Sequence = docNumber,
                  Recipients = new Recipients()
                  {
                      Signers = new List<Signer>()
                      {
                          new Signer()
                          {
                              Email = "Janedoe@acme.com",
                              Name = "Jane Doe",
                              RecipientId = "1",
                              RoleName = "Signer1",
                              Tabs = new Tabs()
                              {
                                  TextTabs = new List<Text>()
                                  {
                                      new Text()
                                      {
                                          DocumentId = docNumber,
                                          PageNumber = "1",
                                          XPosition = "100",
                                          YPosition = "100",
                                          Width = 120, 
                                          Value = "Some Tab Value " + docNumber
                                      }
                                  }

                              }
                          }
                      }
                  }
              }
          }
    }
}