简体   繁体   中英

Docusign: UNKNOWN_ENVELOPE_RECIPIENT error

I'm just getting started coding with Docusign. I'm running the following code from an ASPX web form:

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

The code is from the Docusign developer site. I actually get an email with a document attached that I can sign and return back. But, I get an exception. The exception occurs in the envelopesAPI.cs file, method public ApiResponse< ViewUrl > CreateRecipientViewWithHttpInfo (string accountId, string envelopeId, RecipientViewRequest recipientViewRequest = null). The exception message is in the title of my question. Why do I get this exception, and, how do I avoid it but still get everything to work?

If you are trying to do embedded signing, then you need to add clientUserId in Signer details. You can check the example at Embedded Signing .

You will call below method only if you have an embedded signer and wants to generate URL for an embedded signer. But since you have not added clientUserId in the Signer object so you cannot call below method and it will not find any embedded signer in the envelope, hence the error.

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

I think by mistake you have added (a typo) signer.UserId = "1234"; instead of signer.ClientUserId = "1234";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM