首页 > 解决方案 > 如何使用 C# DocuSign 的 API 查看一批信封的自定义字段

问题描述

这是一个关于使用 DocuSign API 及其 C# SDK 将文档发送给收件人进行数字签名,然后在收件人级别跟踪状态更改的问题。我在将状态更改与相应收件人相关联时遇到问题。

每个信封有一个收件人。我使用 BulkEnvelopesAPI CreateBulkListRequest 方法发送一批。然后,我使用 EnvelopesAPI ListStatusChanges 方法获取状态更改。我可以在新文档发送后看到它们,并且在文档签名后我可以看到状态变化。

但是,我无法将这些状态更改与我的收件人联系起来。因此,我在信封中添加了一个自定义字段,以保存收件人的唯一值。ListStatusChanges 响应包含一个信封列表,每个信封都包含一个 CustomField 属性,但它始终为空。我可以使用 EnvelopesAPI ListCustomFields 方法单独获取信封,使用 ListStatusChanges 中的信封 ID,但这意味着大量的 API 调用。我分批发送大约 4000 个文档,每批 1000 个。如果我必须单独检查信封,我将倾向于达到每小时 1000 个 API 调用的限制。

所以我的问题是:如何在信封上设置自定义字段,以便我可以在 ListStatusChanges 响应信封的 CustomFields 属性中看到它,而不必依次为每个信封调用 API?

以下是一些可能有帮助的代码摘录:

当我创建 BulkSendList 时,我在其信封中创建占位符:

          var theEnvelopeDefinition = new EnvelopeDefinition
            {
                TemplateId = myConfiguration["TemplateId"],
                EnvelopeIdStamping = "false",
                EmailSubject = myConfiguration["EmailSubject"],
                Status = "created",
                CustomFields = new CustomFields
                {
                    TextCustomFields =
                        new List<TextCustomField>
                        {
                            new() { Name = "FRN" }
                        }
                }
            };
:
:
:
        myEnvelopeApi.CreateEnvelope(myAccountId, theEnvelopeDefinition);

当我将收件人添加到批量发送列表时,我会这样做:

           var theBulkSendingList = new BulkSendingList
            {
                BulkCopies = new List<BulkSendingCopy>(),
                Name = "Adviser Terms of Business Mailing"
            };
            foreach (ZurichAdvisersDocuSignControl aWorkItem in myWorkItems)
            {
                var theBulkSendingCopy = new BulkSendingCopy
                {
                    CustomFields = new List<BulkSendingCopyCustomField>
                    {
                        new() { Name = "FRN", Value = aWorkItem.FcaRegistrationNumber },
                        new() { Name = "EmailAddress", Value = aWorkItem.EmailAddress }
                    },
                    EmailSubject = "This is a test email",
                    Recipients = new List<BulkSendingCopyRecipient>
                    {
                        new()
                        {
                            Name =
                                $"{aWorkItem.RecipientFirstName} {aWorkItem.RecipientLastName}",
                            Email = aWorkItem.EmailAddress,
                            RecipientId =
                                "1" // this has to match the envelope and possibly also something in the template
                        }
                    },
                    EmailBlurb =
                        string.Format(
                            CultureInfo.InvariantCulture,
                            theEmailBlurb,
                            theGreeting,
                            aWorkItem.RecipientFirstName)
                };

                theBulkSendingList.BulkCopies.Add(theBulkSendingCopy);
            }

            BulkSendingList theBulkSendList =
                myBulkEnvelopesApi.CreateBulkSendList(myAccountId, theBulkSendingList);
            myBulkListId = theBulkSendList.ListId;

当我请求更改状态时,我会这样做:

            var theEnvelopeApi = new EnvelopesApi(myApiClient);
            var theOptions = new EnvelopesApi.ListStatusChangesOptions
            {
                fromDate = DateTime.Now
                   .AddDays(-1)
                   .ToString("yyyy/MM/dd")
            };

            // Call the API method:
            EnvelopesInformation theResults =
                theEnvelopeApi.ListStatusChanges(myAccountId, theOptions);

在最后一步的结果中,我得到了一个信封列表,其中包括 BulkSendList 发送的信封。它们都有一个空的 CustomFields 属性。它们确实有一个 CustomFieldsUri 属性,如果我在 Postman 中使用它,它会显示我在 CreateBulkSendList 中设置的 CustomField 值。或者我可以一次调用 ListCustomField 一个信封。但无论哪种方式都会导致过多的 API 调用。

有什么想法吗?有没有更好的方法来做我想做的事情?我可以硬着头皮实现一些管理每小时 1000 次 API 调用限制的东西,但是 BulkSendLists 的存在给了我希望,我不需要这样做。或者我可以过滤 ListStatusChanges 调用以仅显示自上次检查以来状态已超过已发送的信封;这将减少返回的更改数量,从而减少我每小时需要执行的 ListCustomFields 调用的数量,但仍然存在达到限制的风险。

谢谢

史蒂夫

标签: docusignapistatusenvelope

解决方案


https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopes/liststatuschanges/ 见: 在此处输入图像描述

您的 C# 代码应更改为:

        var theOptions = new EnvelopesApi.ListStatusChangesOptions
        {
            include = "custom_fields",
            fromDate = DateTime.Now.AddDays(-1).ToString("yyyy/MM/dd")
        };

推荐阅读