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;

Thursday, November 09, 2017

Using C#.Net DocuSign REST API get Account ID in Web App

I was working on integrating DocuSign data into my Web App. The requirement was pretty simple, for a given account just display the documents which are awaiting for signature by others. First step was to get the account id(s) of the Admin account of DocuSign.

I was searching a solution on net and found it very difficult to gather the information and working code.

Here is the code which works well and tested in console application. I am sure you can use this code display in the data in web App also. you can add DocuSign package using NuGet in your solution.




Note: You just need to add DocuSign.eSign dll with strong key if using this code in Web App or SharePoint.

Use Integrator Key and BasePath if you are using Demo account. in my case i used Demo account. For Production purpose you need not have to mentioned this basePath.



        static void Main(string[] args)
        {
            loginApi(userName, password);
        }

        static public string loginApi(string usr, string pwd)
        {
            // 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);

// 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();
            AuthenticationApi authApi = new AuthenticationApi(cfg);
            LoginInformation loginInfo = authApi.Login();

            // find the default account for this user
            foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true")
                {
                    accountId = loginAcct.AccountId;
                    break;
                }
            }
            if (accountId == null)
            { // if no default found set to first account
                accountId = loginInfo.LoginAccounts[0].AccountId;
            }

            return accountId;
        }