首页 > 解决方案 > DocuSignAPI nuget c# REST 包:将新文档添加到现有信封时未添加 UpdateRecipients 和 UpdateDocuments 选项卡

问题描述

我正在使用 nuget c# REST 包。当我尝试将包含新收件人的文档添加到现有信封时,收件人和文档显示在信封中,但没有与新文档关联的选项卡,即使在我调用 UpdateRecipients 时为新收件人列出了选项卡。

我已检查以确保选项卡中的 DocID 与在 EnvelopeDefinition 中发送到 UpdateDocuments 的新 DocID 匹配,并且所有其他数据似乎都是正确的,但没有为新收件人显示选项卡。

我试过只传入 2 个新收件人或传入整个收件人列表(3 个以前的 + 2 个新的)。在这两种情况下,所有收件人都会从 UpdateRecipients 返回成功消息,但不添加任何选项卡。

这是我的一些代码。

            EnvelopeDefinition envDef = new EnvelopeDefinition();
            envDef.Documents = new List<Document>();

            foreach (DSDocumentIN docIN in documents)
            {

                // Add a document to the envelope
                Document doc = new Document();
                doc.Name = docIN.Name;
                doc.DocumentBase64 = docIN.FileBase64;
                doc.DocumentId = docIN.DocID;

                envDef.Documents.Add(doc);
            }

            int iCounter = 1;

            List<Signer> signerList = new List<Signer>();

            List<DSSigner> fullSignerList = new List<DSSigner>();
            fullSignerList = GetDSSigners(existingEnvelopeId);
            foreach (DSSigner newSigner in signers)
            {
                fullSignerList.Add(newSigner);
            }

            foreach (DSSigner s in fullSignerList)
            {
                Signer docSigner = new Signer();
                docSigner.Email = s.Email;
                docSigner.Name = s.FirstName + " " + s.LastName;
                docSigner.RoleName = s.Role;
                if (string.IsNullOrEmpty(s.RecipientId))
                    docSigner.RecipientId = Guid.NewGuid().ToString();
                else
                    docSigner.RecipientId = s.RecipientId;
                if (string.IsNullOrEmpty(s.RoutingOrder))
                    docSigner.RoutingOrder = iCounter.ToString();
                else
                    docSigner.RoutingOrder = s.RoutingOrder;
                if (string.IsNullOrEmpty(s.State))
                    docSigner.Status = "Created";
                else
                    docSigner.Status = s.State;


                docSigner.Tabs = AllTabs(docSigner, documents);

                signerList.Add(docSigner);
                iCounter++;
            }

            envDef.Recipients = new Recipients();
            envDef.Recipients.Signers = new List<Signer>();
            envDef.Recipients.Signers = signerList;

            RecipientsUpdateSummary recipientsUpdateSummary = apiInstance.UpdateRecipients(accountId, existingEnvelopeId, envDef.Recipients);


            EnvelopesApi.UpdateDocumentsOptions UpdateDocOptions = new EnvelopesApi.UpdateDocumentsOptions();
            UpdateDocOptions.applyDocumentFields = "True";  // string | When true, Document fields can be added or modified while adding or modifying envelope documents. (optional)  

            // Adds one or more documents to an existing envelope document.
            EnvelopeDocumentsResult result = apiInstance.UpdateDocuments(accountId, existingEnvelopeId, envDef, UpdateDocOptions);
            Debug.WriteLine(result);

            //Get recipients to find RecipientIdGuid (which becomes RecipientId when sending). RecipientId is key field in db. -- DocuSign does not appear to have this RecipientIdGuid/RecipientId documented
            Recipients recips = apiInstance.ListRecipients(accountId, existingEnvelopeId);

2018 年 6 月 12 日更新:目前,我正在添加新文档,然后是收件人。我为这种方法提供了一个日志链接: DocuSign Log

(具体参见 04_OK_AddDocumentsToEnvelope.txt 和 03_OK_UpdateEnvelopeRecipients.txt)

标签: docusignapi

解决方案


我想我已经弄清楚了。

去清理它并确保它按要求工作然后我会在这里发布更多细节。

2018 年 6 月 13 日更新:
此答案专门用于使用 nuget c# REST 包。由于标签是收件人对象的一部分,我希望在收件人对象中包含标签然后将收件人添加到信封中会起作用。但是,在调用 UpdateRecipients 方法时情况并非如此。新的收件人被添加,但没有新的标签。相反,必须单独添加选项卡。

同样有趣的是必须调用的函数的名称如下:
添加新文档 = UpdateDocuments
添加新收件人 = UpdateRecipients
添加新选项卡 =创建选项卡

可能还有其他可行的方法,但这里是对我有用的代码的核心:

    public string AddDocumentsToEnvelope(List<DSDocumentIN> documents, List<DSSigner> signers, string clientAppNo, int PDFRequestID, string envelopeID)
    {

        string username = "randys@balboacapital.com";
        string password = "555Tmppwd";
        string integratorKey = "321e15cb-89a1-4958-a444-6b2d33fc7005";


        string retEnvelopeID = "";
        ExceptionDispatchInfo exInfo = null;

        try
        {

            var pdfDocCtrl = new BalboaLeaseCL.PDFDocController();
            var apiInstance = new EnvelopesApi();

            string existingEnvelopeId = envelopeID;

            // initialize client for desired environment (for production change to www)
            ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
            Configuration.Default.ApiClient = apiClient;

            // configure 'X-DocuSign-Authentication' header
            string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            // we will retrieve this from the login API call
            string accountId = null;

            /////////////////////////////////////////////////////////////////
            // STEP 1: LOGIN API        
            /////////////////////////////////////////////////////////////////

            // login call is available in the authentication api 
            AuthenticationApi authApi = new AuthenticationApi();
            LoginInformation loginInfo = authApi.Login();

            // parse the first account ID that is returned (user might belong to multiple accounts)
            accountId = loginInfo.LoginAccounts[0].AccountId;

            // Update ApiClient with the new base url from login call
            string[] separatingStrings = { "/v2" };
            apiClient = new ApiClient(loginInfo.LoginAccounts[0].BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]);

            EnvelopeDefinition envDef = new EnvelopeDefinition();
            envDef.Documents = new List<Document>();

            foreach (DSDocumentIN docIN in documents)
            {

                // Add a document to the envelope
                Document doc = new Document();
                doc.Name = docIN.Name;
                doc.DocumentBase64 = docIN.FileBase64;
                doc.DocumentId = docIN.DocID;

                envDef.Documents.Add(doc);
            }

            int iCounter = 1;

            List<Signer> signerList = new List<Signer>();

            List<DSSigner> fullSignerList = new List<DSSigner>();
            fullSignerList = GetDSSigners(existingEnvelopeId);

            foreach (DSSigner newSigner in signers)
            {
                fullSignerList.Add(newSigner);
            }

            foreach (DSSigner s in fullSignerList)
            {
                Signer docSigner = new Signer();
                docSigner.Email = s.Email;
                docSigner.Name = s.FirstName + " " + s.LastName;
                docSigner.RoleName = s.Role;
                if (string.IsNullOrEmpty(s.RecipientId))
                    docSigner.RecipientId = Guid.NewGuid().ToString();
                else
                    docSigner.RecipientId = s.RecipientId;
                if (string.IsNullOrEmpty(s.RoutingOrder))
                    docSigner.RoutingOrder = iCounter.ToString();
                else
                    docSigner.RoutingOrder = s.RoutingOrder;
                if (string.IsNullOrEmpty(s.State))
                    docSigner.Status = "Created";
                else
                    docSigner.Status = s.State;


                docSigner.Tabs = AllTabs(docSigner, documents);

                signerList.Add(docSigner);
                iCounter++;
            }

            envDef.Recipients = new Recipients();
            envDef.Recipients.Signers = new List<Signer>();
            envDef.Recipients.Signers = signerList;



            EnvelopesApi.UpdateDocumentsOptions UpdateDocOptions = new EnvelopesApi.UpdateDocumentsOptions();
            UpdateDocOptions.applyDocumentFields = "True";  // string | When true, Document fields can be added or modified while adding or modifying envelope documents. (optional)  

            // Adds one or more documents to an existing envelope 
            EnvelopeDocumentsResult result = apiInstance.UpdateDocuments(accountId, existingEnvelopeId, envDef, UpdateDocOptions);

            if (string.IsNullOrEmpty(result.EnvelopeId))
                throw new DocuSignAPIException("No EnvelopeID returned.");
            else
                retEnvelopeID = result.EnvelopeId;

            //Adds recipients to envelope (but won't create tabs)
            RecipientsUpdateSummary recipientsUpdateSummary = apiInstance.UpdateRecipients(accountId, existingEnvelopeId, envDef.Recipients);



            foreach (DSSigner newSigner in signers)
            {
                foreach (Signer s in envDef.Recipients.Signers)
                {
                    if (newSigner.RecipientId.Equals(s.RecipientId, StringComparison.InvariantCultureIgnoreCase))
                    {
                        //Adds the tabs for the recipients for the new doc
                        apiInstance.CreateTabs(accountId, existingEnvelopeId, s.RecipientId, s.Tabs);
                        break;
                    }
                }
            }

推荐阅读