docusignapistatusenvelope

How can I view a batch of Envelopes' custom fields using C# DocuSign's API


This is a question about using the DocuSign API, with their C# SDK, to send documents to recipients for digital signing, and then tracking the status changes at recipient level. I am having problems relating the status changes to the respective recipients.

There is one recipient per Envelope. I send a batch using the BulkEnvelopesAPI CreateBulkListRequest method. I then get status changes using the EnvelopesAPI ListStatusChanges method. I can see new documents when they have been sent and I can see status changes when the documents are signed.

However, I cannot relate these status changes to my recipients. So I have added a Custom Field to the Envelope to hold a unique value for the recipient. The ListStatusChanges response contains a list of Envelopes and each Envelope contains a CustomField property, but it is always null. I can get the Envelopes individually using the EnvelopesAPI ListCustomFields method, using the Envelope Id from ListStatusChanges, but this would mean a large number of API calls. I am sending about 4000 documents in batches of 1000. If I have to check envelopes individually, I will tend to hit up against the 1000-per hour API call limit.

So my question is: how do I set a Custom Field on the Envelope such that I can see it in the CustomFields property of the ListStatusChanges response Envelopes, without having to invoke the API for each Envelope in turn?

Here are some code extracts that might help:

When I create the BulkSendList, I create placeholders in its Envelope:

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

When I add recipients to the Bulk Send List, I do this:

           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;

When I request status changes I do this:

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

In theResults of that last step, I get a List of Envelopes, which includes the Envelopes sent by the BulkSendList. They all have a null CustomFields property. They do have a CustomFieldsUri property and if I use that in Postman it does show me the CustomField values that I set in CreateBulkSendList. Or I can invoke ListCustomField one Envelope at a time. But either way that would lead to too many API calls.

Any thoughts? Is there a better way to do what I am trying to do? I could just bite the bullet and implement something that manages the 1000-per-hour API call limit, but the existence of BulkSendLists gave me hope that I'd not need to. Or I could filter the ListStatusChanges call to only show Envelopes where the status has progressed beyond Sent since the last time I checked; this would reduce the number of changes returned and so reduce the number of ListCustomFields calls I need to do per hour, but there is still the risk I hit the limit.

Thanks

Steve


Solution

  • https://developers.docusign.com/docs/esign-rest-api/reference/envelopes/envelopes/liststatuschanges/ See this: enter image description here

    Your C# code should change to :

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