Friday, November 24, 2017

Using C#.Net DocuSign REST API to generate Recipient Signing URL

In my previous example i elaborated how to retrieve AccountID for all Login in DocuSign. Taking to the next level i had another requirement, In my Web App client wanted me to show the clickable link for my Envelopes which will take them to documents to Sign.

I thought this might be a straight forward solution to generate the Link. Unfortunately you can not create static formatted link. There is no property which can be used for this purpose.

By default, DocuSign transactions and workflows are initiated through email. The recipients - known as a remote recipients in this case - use system-generated email links to complete their documents through the simple and intuitive DocuSign Website. So when we required our web app/console app to generate these links using embedded recipients. You can let users sign or send documents directly through our UI, avoiding the context-switch to email.

To generate the recipient signing URL call the EnvelopeViews: createRecipient method, using the same identifying recipient information - including the clientUserId - that was sent with envelope



// we set the api client in global config when we configured the client
ApiClient client = new ApiClient(basePath: "https://demo.docusign.net/restapi");
Configuration cfg = new Configuration(client);
//ApiClient apiClient = Configuration.Default.ApiClient;
string authHeader = "{\"Username\":\"" + usr + "\", \"Password\":\"" + pwd + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
            //Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
cfg.AddDefaultHeader("X-DocuSign-Authentication", authHeader);


RecipientViewRequest viewOptions = new RecipientViewRequest()
            {
                ReturnUrl = "https://www.docusign.com/",
                ClientUserId = clientUserId, //"1001",  // must match clientUserId of the embedded recipient
                AuthenticationMethod = "email",
                UserName = userId , //"{USER_NAME}",
                Email = email//"{USER_EMAIL}"
            };


// instantiate an envelopesApi object
EnvelopesApi envelopesApi = new EnvelopesApi();
envelopesApi.Configuration = cfg;
// create the recipient view (aka signing URL)
ViewUrl recipientView = envelopesApi.CreateRecipientView(accountId, envelopeId, viewOptions);

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

            // Start the embedded signing session
            return recipientView.Url;

No comments: