Docusign:UNKNOWN_ENVELOPE_RECIPIENT错误

时间:2018-01-19 23:13:22

标签: c# webforms docusignapi

我刚刚开始用Docusign编码。我正在从ASPX Web表单运行以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DocuSign.eSign.Api;
using DocuSign.eSign.Model;
using DocuSign.eSign.Client;
using System.Collections;
using System.Configuration;
using Newtonsoft.Json;
using System.IO;

namespace TestDocusign
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

    }

    protected void btnDemoCode2_Click(object sender, EventArgs e)
    {
        // Enter your DocuSign credentials
        string Username = ConfigurationManager.AppSettings["accountEmailAddress"];
        string Password = ConfigurationManager.AppSettings["accountPassword"];
        string IntegratorKey = ConfigurationManager.AppSettings["integratorKey"];

        // specify the document (file) we want signed
        string SignTest1File = Server.MapPath("TEST.PDF");

        // Enter recipient (signer) name and email address
        string recipientName = "me";
        string recipientEmail = "andrew_werber@tritonmsllc.com";

        // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi)
        string basePath = ConfigurationManager.AppSettings["host"];

        // instantiate a new api client
        ApiClient apiClient = new ApiClient(basePath);

        // set client in global config so we don't need to pass it to each API object
        DocuSign.eSign.Client.Configuration.Default.ApiClient = apiClient;

        string authHeader = "{\"Username\":\"" + Username + "\", \"Password\":\"" + Password + "\", \"IntegratorKey\":\"" + IntegratorKey + "\"}";
        DocuSign.eSign.Client.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

        // we will retrieve this from the login() results
        string accountId = null;

        // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
        AuthenticationApi authApi = new AuthenticationApi();
        LoginInformation loginInfo = authApi.Login();

        // user might be a member of multiple accounts
        accountId = loginInfo.LoginAccounts[0].AccountId;

        Console.WriteLine("LoginInformation: {0}", loginInfo.ToJson());

        // Read a file from disk to use as a document
        byte[] fileBytes = File.ReadAllBytes(SignTest1File);

        EnvelopeDefinition envDef = new EnvelopeDefinition();
        envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";

        // Add a document to the envelope
        Document doc = new Document();
        doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
        doc.Name = "TestFile.pdf";
        doc.DocumentId = "1";

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

        // Add a recipient to sign the documeent
        Signer signer = new Signer();
        signer.Name = recipientName;
        signer.Email = recipientEmail;
        signer.RecipientId = "1";

        signer.UserId = "1234";

        // Create a |SignHere| tab somewhere on the document for the recipient to sign
        signer.Tabs = new Tabs();
        signer.Tabs.SignHereTabs = new List<SignHere>();
        SignHere signHere = new SignHere();
        signHere.DocumentId = "1";
        signHere.PageNumber = "1";
        signHere.RecipientId = "1";
        signHere.XPosition = "100";
        signHere.YPosition = "150";
        signer.Tabs.SignHereTabs.Add(signHere);

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

        // set envelope status to "sent" to immediately send the signature request
        envDef.Status = "sent";

        // Use the EnvelopesApi to send the signature request!
        EnvelopesApi envelopesApi = new EnvelopesApi();
        EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);

        // print the JSON response
        Console.WriteLine("EnvelopeSummary:\n{0}", JsonConvert.SerializeObject(envelopeSummary));

        RecipientViewRequest viewOptions = new RecipientViewRequest()
        {
            ReturnUrl = "https://www.docusign.com/devcenter", ////////////////////////////////// should be read in from CONFIG
            ClientUserId = signer.UserId,  // must match clientUserId set in step #2!
            AuthenticationMethod = "email",
            UserName = signer.Name,
            Email = signer.Email
        };

        // create the recipient view (aka signing URL)
        ViewUrl recipientView = envelopesApi.CreateRecipientView(accountId, envelopeSummary.EnvelopeId, viewOptions);

        // print the JSON response
        //Console.WriteLine("ViewUrl:\n{0}", JsonConvert.SerializeObject(recipientView));
        // Start the embedded signing session
        System.Diagnostics.Process.Start(recipientView.Url);
        }
    }
}

代码来自Docusign开发者网站。我实际收到一封附有文件的电子邮件,我可以签名并返回。但是,我得到了一个例外。在envelopesAPI.cs文件中发生异常,方法public ApiResponse&lt; ViewUrl&gt; CreateRecipientViewWithHttpInfo(string accountId,string envelopeId,RecipientViewRequest recipientViewRequest = null)。异常消息在我的问题的标题中。为什么我会得到这个例外,并且,我如何避免它,但仍然可以使一切工作?

1 个答案:

答案 0 :(得分:0)

如果您尝试进行嵌入式签名,则需要在Signer详细信息中添加clientUserId。您可以在Embedded Signing查看示例。

只有拥有嵌入式签名者且想要为嵌入式签名者生成URL时,才会调用以下方法。但是因为你没有在Signer对象中添加clientUserId所以你不能调用下面的方法,它不会在信封中找到任何嵌入的签名者,因此错误。

ViewUrl recipientView = envelopesApi.CreateRecipientView(accountId, envelopeSummary.EnvelopeId, viewOptions);

我认为你错误地添加了(错字)signer.UserId = "1234";而不是signer.ClientUserId = "1234";