public EnvelopeDefinition BuildEnvelope(UserDetails currentUser, UserDetails additionalUser)
        {
            if (currentUser == null)
            {
                throw new ArgumentNullException(nameof(currentUser));
            }

            if (additionalUser == null)
            {
                throw new ArgumentNullException(nameof(additionalUser));
            }

            var roleHr = new TemplateRole
            {
                Email    = currentUser.Email,
                Name     = currentUser.Name,
                RoleName = "HR"
            };

            var roleNewHire = new TemplateRole
            {
                Email    = additionalUser.Email,
                Name     = additionalUser.Name,
                RoleName = "New Hire"
            };

            var env = new EnvelopeDefinition
            {
                TemplateRoles = new List <TemplateRole> {
                    roleHr, roleNewHire
                }, Status = "sent"
            };

            return(env);
        }
        public void JwtRequestSignatureFromTemplateTest()
        {
            EnvelopeDefinition envDef = new EnvelopeDefinition();

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

            // assign recipient to template role by setting name, email, and role name.  Note that the
            // template role name must match the placeholder role name saved in your account template.
            TemplateRole tRole = new TemplateRole();

            tRole.Email    = testConfig.RecipientEmail;
            tRole.Name     = testConfig.RecipientName;
            tRole.RoleName = testConfig.TemplateRoleName;

            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRole
            };

            // add the role to the envelope and assign valid templateId from your account
            envDef.TemplateRoles = rolesList;
            envDef.TemplateId    = testConfig.TemplateId;

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

            // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
            EnvelopesApi    envelopesApi    = new EnvelopesApi(testConfig.ApiClient.Configuration);
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(testConfig.AccountId, envDef);

            Assert.IsNotNull(envelopeSummary);
            Assert.IsNotNull(envelopeSummary.EnvelopeId);

            testConfig.EnvelopeId = envelopeSummary.EnvelopeId;
        }
        public void CreateEnvelope_CorrectInputParametersAndTemplateReference_ReturnEnvelopeSummary()
        {
            var envDef = new EnvelopeDefinition
            {
                EmailSubject = "[DocuSign C# SDK] - Please sign this doc"
            };

            var tRole = new TemplateRole
            {
                Email    = _testConfig.RecipientEmail,
                Name     = _testConfig.RecipientName,
                RoleName = _testConfig.TemplateRoleName
            };

            var rolesList = new List <TemplateRole>()
            {
                tRole
            };

            envDef.TemplateRoles = rolesList;
            envDef.TemplateId    = _testConfig.TemplateId;

            envDef.Status = "sent";

            EnvelopeSummary envelopeSummary = _envelopesApi.CreateEnvelope(_testConfig.AccountId, envDef);

            Assert.IsNotNull(envelopeSummary?.EnvelopeId);

            this._testConfig.EnvelopeId = envelopeSummary.EnvelopeId;
        }
        private EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName,
                                                string ccEmail, string ccName, string templateId)
        {
            // Data for this method
            // signerEmail
            // signerName
            // ccEmail
            // ccName
            // templateId

            EnvelopeDefinition env = new EnvelopeDefinition();

            env.TemplateId = templateId;

            TemplateRole signer1 = new TemplateRole();

            signer1.Email    = signerEmail;
            signer1.Name     = signerName;
            signer1.RoleName = "signer";

            TemplateRole cc1 = new TemplateRole();

            cc1.Email    = ccEmail;
            cc1.Name     = ccName;
            cc1.RoleName = "cc";

            env.TemplateRoles = new List <TemplateRole> {
                signer1, cc1
            };
            env.Status = "sent";
            return(env);
        }
Exemplo n.º 5
0
        public EnvelopeSummary createEnvelopeFromTemplate(string accountId)
        {
            EnvelopeDefinition envDef = new EnvelopeDefinition();

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

            // assign recipient to template role by setting name, email, and role name.  Note that the
            // template role name must match the placeholder role name saved in your account template.
            TemplateRole tRole = new TemplateRole();

            tRole.Email    = "{USER_EMAIL}";
            tRole.Name     = "{USER_NAME}";
            tRole.RoleName = "{ROLE}";

            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRole
            };

            // add the role to the envelope and assign valid templateId from your account
            envDef.TemplateRoles = rolesList;
            envDef.TemplateId    = "{TEMPLATE_ID}";

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

            // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
            EnvelopesApi    envelopesApi    = new EnvelopesApi();
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);

            // print the JSON response
            Console.WriteLine("EnvelopeSummary:\n{0}", JsonConvert.SerializeObject(envelopeSummary));
            Trace.WriteLine("Envelope has been sent to " + tRole.Email);
            return(envelopeSummary);
        }
        public void GetFormData_CorrectInputParameters_ReturnEnvelopeFormData()
        {
            var envDef = new EnvelopeDefinition
            {
                EmailSubject = "[DocuSign C# SDK] - Please sign this doc"
            };

            var tRole = new TemplateRole
            {
                Email    = _testConfig.RecipientEmail,
                Name     = _testConfig.RecipientName,
                RoleName = "Manager"
            };

            var rolesList = new List <TemplateRole>()
            {
                tRole
            };

            envDef.TemplateRoles = rolesList;
            envDef.TemplateId    = _testConfig.TemplateId;

            envDef.Status = "sent";

            EnvelopeSummary envelopeSummary = _envelopesApi.CreateEnvelope(_testConfig.AccountId, envDef);

            Assert.IsNotNull(envelopeSummary?.EnvelopeId);

            EnvelopeFormData envFormData = _envelopesApi.GetFormData(_testConfig.AccountId, envelopeSummary.EnvelopeId);

            Assert.IsNotNull(envFormData?.FormData);
            Assert.IsNotNull(envFormData?.EnvelopeId);
        }
Exemplo n.º 7
0
        } // end requestSignatureTest()

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public EnvelopeSummary requestSignatureFromTemplateTest()
        {
            // Enter recipient (signer) name and email address
            string recipientName  = "[RECIPIENT_NAME]";
            string recipientEmail = "[RECIPIENT_EMAIL]";

            // the document (file) we want signed
            string templateId       = "[TEMPLATE_ID]";
            string templateRoleName = "[TEMPLATE_ROLE_NAME]";

            // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi)
            configureApiClient(BASE_URL);

            //===========================================================
            // Step 1:JWT Login()
            //===========================================================

            // call the JWT Configure and UserInfo API which sets the user's baseUrl and returns their accountId
            string accountId = JWTAuthLogin();

            //===========================================================
            // Step 2: Signature Request from Template
            //===========================================================

            EnvelopeDefinition envDef = new EnvelopeDefinition();

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

            // assign recipient to template role by setting name, email, and role name.  Note that the
            // template role name must match the placeholder role name saved in your account template.
            TemplateRole tRole = new TemplateRole();

            tRole.Email    = recipientEmail;
            tRole.Name     = recipientName;
            tRole.RoleName = templateRoleName;

            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRole
            };

            // add the role to the envelope and assign valid templateId from your account
            envDef.TemplateRoles = rolesList;
            envDef.TemplateId    = templateId;

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

            // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
            EnvelopesApi    envelopesApi    = new EnvelopesApi();
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);

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

            return(envelopeSummary);
        } // end requestSignatureFromTemplateTest()
Exemplo n.º 8
0
        public void RequestSignatureViaTemplateTest()
        {
            try
            {
                // upload template if one doesn't exist
                // FAILED - CANT UPLOAD A TEMPLATE - API-3002 submitted
                // use predefined template
                AuthenticationApiTests authTests = new AuthenticationApiTests();
                authTests.LoginTest();

                // get pre-existing template with Signer1 role
                // since I can't upload a template right now
                TemplatesApi            templatesApi    = new TemplatesApi();
                EnvelopeTemplateResults templateResults = templatesApi.ListTemplates(TestConfig.AccountId);
                Assert.IsNotNull(templateResults);
                Assert.IsNotNull(templateResults.EnvelopeTemplates);
                string templateId = null;
                foreach (EnvelopeTemplateResult et in templateResults.EnvelopeTemplates)
                {
                    if (et.Name == "Test Template")
                    {
                        templateId = et.TemplateId;
                        break;
                    }
                }
                Assert.IsNotNull(templateId);

                EnvelopeDefinition envDef = new EnvelopeDefinition();
                envDef.TemplateId = templateId;

                envDef.TemplateRoles = new List <TemplateRole>();
                TemplateRole templateRole = new TemplateRole();
                templateRole.Email    = TestConfig.DefaultEmail;
                templateRole.Name     = TestConfig.DefaultName;
                templateRole.RoleName = "Signer1";
                envDef.TemplateRoles.Add(templateRole);
                envDef.Status = "sent"; // trigger the envelope to be sent (vs. Draft/Created)


                // send envelope using template roles
                EnvelopesApi    envelopesApi = new EnvelopesApi();
                EnvelopeSummary es           = envelopesApi.CreateEnvelope(TestConfig.AccountId, envDef);
                Assert.IsNotNull(es);
                Assert.IsNotNull(es.EnvelopeId);
                Trace.WriteLine("Envelope: " + es.ToJson());
            }
            catch (DocuSign.eSign.Client.ApiException apiEx)
            {
                Assert.IsNotNull(apiEx.ErrorCode);
                Assert.IsTrue(!string.IsNullOrWhiteSpace(apiEx.Message));
                Assert.IsTrue(false, "Failed with ErrorCode: " + apiEx.ErrorCode + ", Message: " + apiEx.Message);
            }
        }
        public static TemplateRole addPhoneAuthToRecipient(TemplateRole templateRole, string phonenumber)
        {
            var phoneList = new List <string> {
                phonenumber
            };

            var phoneAuth = new RecipientPhoneAuthentication();

            phoneAuth.SenderProvidedNumbers = phoneList;
            phoneAuth.RecipMayProvideNumber = "true";
            phoneAuth.RecordVoicePrint      = "true";

            return(templateRole);
        }
Exemplo n.º 10
0
        private List <TemplateRole> PopulateRoles(SignatureRequest signatureRequest)
        {
            TemplateRole role = new TemplateRole();

            role.Email         = signatureRequest.EmailAddress;
            role.Name          = signatureRequest.Name;
            role.RoleName      = SIGNER_ROLE;
            role.Tabs          = new Tabs();
            role.Tabs.TextTabs = FormatTextTabs(signatureRequest.Fields);

            return(new List <TemplateRole>()
            {
                role
            });
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            string username      = "******";
            string password      = "******";
            string integratorKey = "3b9fa7cc-dd91-468a-925d-056ee392643a";

            ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");

            Configuration.Default.ApiClient = apiClient;

            string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\",\"IntegratorKey\":\"" + integratorKey + "\"}";

            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            string accountid = null;

            AuthenticationApi authApi   = new AuthenticationApi();
            LoginInformation  loginInfo = authApi.Login();

            accountid = loginInfo.LoginAccounts[0].AccountId;

            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.EmailSubject = "[DocuSign C# SDK] - Sample Signature Request";

            envDef.TemplateId = "";

            TemplateRole tRole = new TemplateRole();

            tRole.Email    = "*****@*****.**";
            tRole.Name     = "Chumani";
            tRole.RoleName = "Junior Developer";

            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRole
            };

            envDef.TemplateRoles = rolesList;

            envDef.Status = "sent";

            EnvelopesApi    envelopesApi    = new EnvelopesApi();
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountid, envDef);
        }
        public void JwtListTabsTest()
        {
            EnvelopeDefinition envDef = new EnvelopeDefinition();

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

            // assign recipient to template role by setting name, email, and role name.  Note that the
            // template role name must match the placeholder role name saved in your account template.
            TemplateRole tRole = new TemplateRole();

            tRole.Email    = _testConfig.RecipientEmail;
            tRole.Name     = _testConfig.RecipientName;
            tRole.RoleName = "Manager";

            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRole
            };

            // add the role to the envelope and assign valid templateId from your account
            envDef.TemplateRoles = rolesList;
            envDef.TemplateId    = _testConfig.TemplateId;

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

            // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
            EnvelopesApi    envelopesApi    = new EnvelopesApi(_testConfig.ApiClient);
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(_testConfig.AccountId, envDef);

            Assert.IsNotNull(envelopeSummary);
            Assert.IsNotNull(envelopeSummary.EnvelopeId);

            var recipients = envelopesApi.ListRecipients(_testConfig.AccountId, envelopeSummary.EnvelopeId);
            var tabs       = envelopesApi.ListTabs(_testConfig.AccountId, envelopeSummary.EnvelopeId, recipients.Signers[1].RecipientId);

            Assert.IsNotNull(tabs);
            Assert.IsNotNull(tabs.ListTabs);
            Assert.IsInstanceOfType(tabs.ListTabs.FirstOrDefault(), typeof(DocuSign.eSign.Model.List));
        }
Exemplo n.º 13
0
        public ActionResult Edit(TemplateRolesViewModel viewModel)
        {
            var templateRoles =
                _unitOfWork.TemplateRolesRepository.Get(x => x.TemplateId == viewModel.TemplateId);

            // Delete all existing Roles
            foreach (var templateRole in templateRoles)
            {
                _unitOfWork.TemplateRolesRepository.Delete(templateRole);
            }
            _unitOfWork.Save();
            if (_unitOfWork.HasError())
            {
                ModelState.AddModelError("", _unitOfWork.GetError());
            }


            // Add all Roles that are selected.
            foreach (var role in viewModel.Roles.Where(x => x.IsChecked))
            {
                var newRole = new TemplateRole
                {
                    TemplateId = viewModel.TemplateId,
                    RoleId     = role.RoleId
                };

                _unitOfWork.TemplateRolesRepository.Add(newRole);
            }
            _unitOfWork.Save();
            if (_unitOfWork.HasError())
            {
                ModelState.AddModelError("", _unitOfWork.GetError());
            }



            return(RedirectToAction("Index"));
        }
Exemplo n.º 14
0
        /// <summary>
        /// This method creates the envelope request body
        /// </summary>
        /// <returns></returns>
        private EnvelopeDefinition CreateEvelope()
        {
            EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition
            {
                EmailSubject = "Please sign the order form sent from the C# SDK"
            };

            // Assign recipients to template roles by setting name, email, and role name.  Note that the
            TemplateRole tRoleSigner = new TemplateRole();

            tRoleSigner.Email = DSConfig.Signer1Email;
            tRoleSigner.Name  = DSConfig.Signer1Name;
            // template role name must match the placeholder role name saved in your envelope template.
            tRoleSigner.RoleName = "Signer1";

            TemplateRole tRoleCC = new TemplateRole();

            tRoleCC.Email = DSConfig.Cc1Email;
            tRoleCC.Name  = DSConfig.Cc1Name;
            // template role name must match the placeholder role name saved in your envelope template.
            tRoleCC.RoleName = "CC1";

            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRoleSigner, tRoleCC
            };

            // add the role to the envelope and assign valid templateId from your account
            envelopeDefinition.TemplateRoles = rolesList;
            envelopeDefinition.TemplateId    = DSConfig.TemplateID;

            // Request that the envelope be sent by setting |status| to "sent".
            // To request that the envelope be created as a draft, set to "created"
            envelopeDefinition.Status = "sent";

            return(envelopeDefinition);
        }
Exemplo n.º 15
0
        public JsonResult <ViewUrl> Test()
        {
            string username      = "";
            string password      = "";
            string integratorKey = "";

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

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

            DSC.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 DSC.ApiClient(loginInfo.LoginAccounts[0].BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]);

            /////////////////////////////////////////////////////////////////
            // STEP 2: CREATE ENVELOPE API
            /////////////////////////////////////////////////////////////////

            // create a new envelope which we will use to send the signature request
            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.EmailSubject = "[DocuSign C# SDK] - Sample Signature Request";

            // provide a valid template ID from a template in your account
            // envDef.TemplateId = "7decf5f8-b499-4b51-8c3c-7c3a2702eefa";
            Document doc    = new Document();
            Signer   signer = new Signer();

            Byte[] bytes = File.ReadAllBytes(@"");
            String file  = Convert.ToBase64String(bytes);

            doc.DocumentBase64 = file;
            doc.DocumentId     = "1";
            doc.Name           = "Mutual_NDA.pdf";
            envDef.Documents   = new List <Document>();
            envDef.Documents.Add(doc);
            signer.Email              = username;
            signer.Name               = "Marc";
            signer.RecipientId        = "1";
            signer.ClientUserId       = "123";
            envDef.Recipients         = new Recipients();
            envDef.Recipients.Signers = new List <Signer>();
            envDef.Recipients.Signers.Add(signer);


            // assign recipient to template role by setting name, email, and role name.  Note that the
            // template role name must match the placeholder role name saved in your account template.
            TemplateRole tRole = new TemplateRole();

            tRole.Email    = "";
            tRole.Name     = "Marc";
            tRole.RoleName = "Signer";

            // add the roles list with the our single role to the envelope
            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRole
            };

            envDef.TemplateRoles = rolesList;

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

            // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
            EnvelopesApi    envelopesApi    = new EnvelopesApi();
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
            ViewUrl         url             = GetViewUrl(envelopesApi, envDef, envelopeSummary);

            return(Json(url));
        }
Exemplo n.º 16
0
        public IActionResult Create(string signerEmail, string signerName, string ccEmail, string ccName)
        {
            // Check the token with minimal buffer time
            bool tokenOk = CheckToken(3);

            if (!tokenOk)
            {
                // We could store the parameters of the requested operation so it could be
                // restarted automatically. But since it should be rare to have a token issue
                // here, we'll make the user re-enter the form data after authentication
                RequestItemsService.EgName = EgName;
                return(Redirect("/ds/mustAuthenticate"));
            }

            // The envelope will be sent first to the signer; after it is signed,
            // a copy is sent to the cc person
            //
            // Read files from a local directory
            // The reads could raise an exception if the file is not available!
            var basePath = RequestItemsService.Session.BasePath + "/restapi";

            // Step 1: Obtain your OAuth token
            var accessToken = RequestItemsService.User.AccessToken;  // Represents your {ACCESS_TOKEN}
            var accountId   = RequestItemsService.Session.AccountId; // Represents your {ACCOUNT_ID}

            // Step 2: Construct your API headers
            var apiClient = new ApiClient(basePath);

            apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);

            // Step 3: Create Tabs and CustomFields
            // Set the values for the fields in the template
            // List item
            List colorPicker = new List
            {
                Value      = "green",
                DocumentId = "1",
                PageNumber = "1",
                TabLabel   = "list"
            };

            // Checkboxes
            Checkbox ckAuthorization = new Checkbox
            {
                TabLabel = "ckAuthorization",
                Selected = "true"
            };
            Checkbox ckAgreement = new Checkbox
            {
                TabLabel = "ckAgreement",
                Selected = "true"
            };

            RadioGroup radioGroup = new RadioGroup
            {
                GroupName = "radio1",
                // You only need to provide the readio entry for the entry you're selecting
                Radios = new List <Radio> {
                    new Radio {
                        Value = "white", Selected = "true"
                    }
                }
            };

            Text includedOnTemplate = new Text
            {
                TabLabel = "text",
                Value    = "Jabberywocky!"
            };

            // We can also add a new tab (field) to the ones already in the template
            Text addedField = new Text
            {
                DocumentId = "1",
                PageNumber = "1",
                XPosition  = "280",
                YPosition  = "172",
                Font       = "helvetica",
                FontSize   = "size14",
                TabLabel   = "added text field",
                Height     = "23",
                Width      = "84",
                Required   = "false",
                Bold       = "true",
                Value      = signerName,
                Locked     = "false",
                TabId      = "name"
            };

            // Add the tabs model (including the SignHere tab) to the signer.
            // The Tabs object wants arrays of the different field/tab types
            // Tabs are set per recipient/signer
            Tabs tabs = new Tabs
            {
                CheckboxTabs = new List <Checkbox> {
                    ckAuthorization, ckAgreement
                },
                RadioGroupTabs = new List <RadioGroup> {
                    radioGroup
                },
                TextTabs = new List <Text> {
                    includedOnTemplate, addedField
                },
                ListTabs = new List <List> {
                    colorPicker
                }
            };

            // Create a signer recipient to sign the document, identified by name and email
            // We're setting the parameters via the object creation
            TemplateRole signer = new TemplateRole
            {
                Email        = signerEmail,
                Name         = signerName,
                RoleName     = "signer",
                ClientUserId = signerClientId, // Change the signer to be embedded
                Tabs         = tabs            //Set tab values
            };

            TemplateRole cc = new TemplateRole
            {
                Email    = ccEmail,
                Name     = ccName,
                RoleName = "cc"
            };

            // Create an envelope custom field to save our application's
            // data about the envelope
            TextCustomField customField = new TextCustomField
            {
                Name     = "app metadata item",
                Required = "false",
                Show     = "true", // Yes, include in the CoC
                Value    = "1234567"
            };

            CustomFields cf = new CustomFields
            {
                TextCustomFields = new List <TextCustomField> {
                    customField
                }
            };

            // Step 4: Create the envelope definition
            EnvelopeDefinition envelopeAttributes = new EnvelopeDefinition
            {
                // Uses the template ID received from example 08
                TemplateId = RequestItemsService.TemplateId,
                Status     = "Sent",
                // Add the TemplateRole objects to utilize a pre-defined
                // document and signing/routing order on an envelope.
                // Template role names need to match what is available on
                // the correlated templateID or else an error will occur
                TemplateRoles = new List <TemplateRole> {
                    signer, cc
                },
                CustomFields = cf
            };

            // Step 5: Call the eSignature REST API
            var             envelopesApi = new EnvelopesApi(apiClient);
            EnvelopeSummary results      = envelopesApi.CreateEnvelope(accountId, envelopeAttributes);

            // Step 6: Create the View Request
            RequestItemsService.EnvelopeId = results.EnvelopeId;
            RecipientViewRequest viewRequest = new RecipientViewRequest();

            // Set the URL where you want the recipient to go once they are done signing;
            // this should typically be a callback route somewhere in your app.
            // The query parameter is included as an example of how
            // to save/recover state information during the redirect to
            // the DocuSign signing ceremony. It's usually better to use
            // the session mechanism of your web framework. Query parameters
            // can be changed/spoofed very easily
            viewRequest.ReturnUrl = dsReturnUrl + "?state=123";

            // How has your app authenticated the user? In addition to your app's authentication,
            // you can include authentication steps from DocuSign; e.g., SMS authentication
            viewRequest.AuthenticationMethod = "none";

            // Recipient information must match the embedded recipient info
            // that we used to create the envelope
            viewRequest.Email        = signerEmail;
            viewRequest.UserName     = signerName;
            viewRequest.ClientUserId = signerClientId;

            // DocuSign recommends that you redirect to DocuSign for the
            // signing ceremony. There are multiple ways to save state.
            // To maintain your application's session, use the PingUrl
            // parameter. It causes the DocuSign Signing Ceremony web page
            // (not the DocuSign server) to send pings via AJAX to your app
            viewRequest.PingFrequency = "600"; // seconds
                                               // NOTE: The pings will only be sent if the pingUrl is an HTTPS address
            viewRequest.PingUrl = dsPingUrl;   // Optional setting

            ViewUrl results1 = envelopesApi.CreateRecipientView(accountId, results.EnvelopeId, viewRequest);
            //***********
            // Don't use an iframe with embedded signing requests!
            //***********
            // State can be stored/recovered using the framework's session or a
            // query parameter on the return URL (see the makeRecipientViewRequest method)
            string redirectUrl = results1.Url;

            return(Redirect(redirectUrl));
        }
        public void RequestSignatureViaTemplateTest()
        {
            try
            {
                // upload template if one doesn't exist
                // FAILED - CANT UPLOAD A TEMPLATE - API-3002 submitted
                // use predefined template
                AuthenticationApiTests authTests = new AuthenticationApiTests();
                authTests.LoginTest();

                // get pre-existing template with Signer1 role
                // since I can't upload a template right now
                TemplatesApi templatesApi = new TemplatesApi();
                EnvelopeTemplateResults templateResults = templatesApi.ListTemplates(TestConfig.AccountId);
                Assert.IsNotNull(templateResults);
                Assert.IsNotNull(templateResults.EnvelopeTemplates);
                string templateId = null;
                foreach (EnvelopeTemplateResult et in templateResults.EnvelopeTemplates)
                {
                    if (et.Name == "Test Template")
                    {
                        templateId = et.TemplateId;
                        break;
                    }
                }
                Assert.IsNotNull(templateId);

                EnvelopeDefinition envDef = new EnvelopeDefinition();
                envDef.TemplateId = templateId;

                envDef.TemplateRoles = new List<TemplateRole>();
                TemplateRole templateRole = new TemplateRole();
                templateRole.Email = TestConfig.DefaultEmail;
                templateRole.Name = TestConfig.DefaultName;
                templateRole.RoleName = "Signer1";
                envDef.TemplateRoles.Add(templateRole);
                envDef.Status = "sent"; // trigger the envelope to be sent (vs. Draft/Created)

                // send envelope using template roles
                EnvelopesApi envelopesApi = new EnvelopesApi();
                EnvelopeSummary es = envelopesApi.CreateEnvelope(TestConfig.AccountId, envDef);
                Assert.IsNotNull(es);
                Assert.IsNotNull(es.EnvelopeId);
                Trace.WriteLine("Envelope: " + es.ToJson());

            }
            catch (DocuSign.eSign.Client.ApiException apiEx)
            {
                Assert.IsNotNull(apiEx.ErrorCode);
                Assert.IsTrue(!string.IsNullOrWhiteSpace(apiEx.Message));
                Assert.IsTrue(false, "Failed with ErrorCode: " + apiEx.ErrorCode + ", Message: " + apiEx.Message);
            }
        }
Exemplo n.º 18
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string serverpath     = Server.MapPath(".");
            string signerClientId = "1000";

            StreamReader sr = new StreamReader(serverpath + @"\privatekey2.txt");

            DS_PRIVATE_KEY = sr.ReadToEnd();
            sr.Close();

            ApiClient APClient = new ApiClient();

            OAuth.OAuthToken authToken = APClient.RequestJWTUserToken(DS_CLIENT_ID,
                                                                      DS_IMPERSONATED_USER_GUID,
                                                                      DS_AUTH_SERVER,
                                                                      Encoding.UTF8.GetBytes(DS_PRIVATE_KEY),
                                                                      1);

            AccessToken = authToken.access_token;

            APClient.SetOAuthBasePath(DS_AUTH_SERVER);
            OAuth.UserInfo UserInfoGet = APClient.GetUserInfo(authToken.access_token);

            AccountIDVar = UserInfoGet.Accounts[0].AccountId;
            APClient     = new ApiClient(UserInfoGet.Accounts[0].BaseUri + "/restapi");
            APClient.Configuration.AccessToken = AccessToken;

            TemplatesApi tempAPI  = new TemplatesApi(APClient.Configuration);
            var          template = tempAPI.ListTemplates(AccountIDVar).EnvelopeTemplates.First(x => x.Name == "Steady Property");

            Text LblTxtName = new Text
            {
                TabLabel = "TxtName",
                Value    = TxtName.Text
            };

            Text LblTxtEmail = new Text
            {
                TabLabel = "TxtEmail",
                Value    = TxtEmail.Text
            };

            Text LblTxtDOB = new Text
            {
                TabLabel = "TxtDOB",
                Value    = TxtDOB.Text
            };

            string GenderValue = "";

            GenderValue = RbMale.Checked ? "Male" : "Female";

            Text LblTxtGender = new Text
            {
                TabLabel = "TxtGender",
                Value    = GenderValue
            };

            Text LblTxtPhone = new Text
            {
                TabLabel = "TxtPhone",
                Value    = TxtPhone.Text
            };

            Text LblTxtAddress = new Text
            {
                TabLabel = "TxtAddress",
                Value    = TxtAddress.Text
            };

            Text LblTxtMember = new Text
            {
                TabLabel = "TxtMember",
                Value    = DropMember.Text
            };

            Tabs tabs = new Tabs
            {
                TextTabs = new List <Text> {
                    LblTxtName, LblTxtEmail, LblTxtDOB, LblTxtGender, LblTxtPhone, LblTxtAddress, LblTxtMember
                }
            };

            TemplateRole signer = new TemplateRole
            {
                Email             = TxtEmail.Text,
                Name              = TxtName.Text,
                RoleName          = "Signer1",
                ClientUserId      = signerClientId,
                EmailNotification = new RecipientEmailNotification
                {
                    EmailSubject = "Please sign the membership form",
                    EmailBody    = "Dear " + TxtName.Text + @", <br><br>Please sign the membership form and we will process your application form." +
                                   @"<br>You will recieve email confirmation within 48 hours<br><br>Thank you <br>Steady Property"
                },
                Tabs = tabs                 //Set tab values
            };

            TemplateRole cc = new TemplateRole
            {
                Email             = TxtEmail.Text,
                Name              = TxtName.Text,
                EmailNotification = new RecipientEmailNotification
                {
                    EmailSubject = "Membership registation completed",
                    EmailBody    = "Dear " + TxtName.Text + @", <br><br>We will process your application form." +
                                   @"<br>You will recieve email confirmation within 48 hours<br><br>Thank you <br>Steady Property"
                },
                RoleName = "cc"
            };

            TemplateRole radmin = new TemplateRole
            {
                Email             = "*****@*****.**",
                Name              = "Harry Tim",
                EmailNotification = new RecipientEmailNotification
                {
                    EmailSubject = "New member registraion notification",
                    EmailBody    = "Dear Admin, <br><br>New membership registration for : " + TxtName.Text +
                                   @"<br>Please process it within 48 hours<br><br>Thank you <br>Steady Property"
                },
                RoleName = "admin"
            };

            EnvelopeDefinition envelopeAttributes = new EnvelopeDefinition
            {
                TemplateId    = "5aa70f7a-7a21-496b-9f24-ada8431cf93b",
                Status        = "Sent",
                TemplateRoles = new List <TemplateRole> {
                    signer, cc, radmin
                }
            };

            EnvelopesApi    envelopesApi = new EnvelopesApi(APClient.Configuration);
            EnvelopeSummary results      = envelopesApi.CreateEnvelope(AccountIDVar, envelopeAttributes);

            RecipientViewRequest viewRequest = new RecipientViewRequest();

            viewRequest.ReturnUrl = "https://localhost:44387/Confirm.aspx" + "?envelopeid=" + results.EnvelopeId;

            viewRequest.AuthenticationMethod = "none";

            viewRequest.Email        = TxtEmail.Text;
            viewRequest.UserName     = TxtName.Text;
            viewRequest.ClientUserId = signerClientId;

            viewRequest.PingFrequency = "600";             // seconds
            // NOTE: The pings will only be sent if the pingUrl is an HTTPS address
            viewRequest.PingUrl = "https://localhost";     // Optional setting

            ViewUrl results1 = envelopesApi.CreateRecipientView(AccountIDVar, results.EnvelopeId, viewRequest);

            Response.Redirect(results1.Url);
        }
        public static object CreateEnvelope_AutoLoan(object[] reqArray, string accountId)
        {
            try
            {
                //Get Config settings from App.config
                DocuSignConfig configSettings = new DocuSignConfig();

                //list to store all objects that will be returned to Node.js
                List <object> rtn = new List <object>();

                object nodeReqBody     = reqArray[0];            //extract req.body from array passed in
                object nodeReqSession  = reqArray[1];            //extract req.session from array passed in
                string nodeCurrentPath = reqArray[2].ToString(); //extract current path from array passed in

                //create dictionary from Node object and extract object values from request body
                var bodyDictionary = (IDictionary <string, object>)nodeReqBody;
                var body           = new Body()
                {
                    inputSigningLocation = (string)bodyDictionary["inputSigningLocation"],
                    inputEmail           = (string)bodyDictionary["inputEmail"],
                    inputFirstName       = (string)bodyDictionary["inputFirstName"],
                    inputLastName        = (string)bodyDictionary["inputLastName"],
                    inputPhone           = (string)bodyDictionary["inputPhone"],

                    //the fields below may not exist (depending on the UI options selected, so test to see if they are in the dictionary first
                    inputLoanAmount              = bodyDictionary.ContainsKey("inputLoanAmount") ? (string)bodyDictionary["inputLoanAmount"] : "",
                    inputLoanLength              = bodyDictionary.ContainsKey("inputLoanLength") ? (string)bodyDictionary["inputLoanLength"] : "",
                    inputAccessCode              = bodyDictionary.ContainsKey("inputAccessCode") ? (string)bodyDictionary["inputAccessCode"] : "",
                    inputAuthentication          = bodyDictionary.ContainsKey("inputAuthentication") ? (string)bodyDictionary["inputAuthentication"] : "",
                    inputCosignerCheckbox        = bodyDictionary.ContainsKey("inputCosignerCheckbox") ? (string)bodyDictionary["inputCosignerCheckbox"] : "",
                    inputCosignerFirstName       = bodyDictionary.ContainsKey("inputCosignerFirstName") ? (string)bodyDictionary["inputCosignerFirstName"] : "",
                    inputCosignerLastName        = bodyDictionary.ContainsKey("inputCosignerLastName") ? (string)bodyDictionary["inputCosignerLastName"] : "",
                    inputCosignerEmail           = bodyDictionary.ContainsKey("inputCosignerEmail") ? (string)bodyDictionary["inputCosignerEmail"] : "",
                    inputSigningLocationCosigner = bodyDictionary.ContainsKey("inputSigningLocationCosigner") ? (string)bodyDictionary["inputSigningLocationCosigner"] : "",
                    inputAccessCodeCosigner      = bodyDictionary.ContainsKey("inputAccessCodeCosigner") ? (string)bodyDictionary["inputAccessCodeCosigner"] : "",
                    inputAuthenticationCosigner  = bodyDictionary.ContainsKey("inputAuthenticationCosigner") ? (string)bodyDictionary["inputAuthenticationCosigner"] : "",
                    inputCosignerPhone           = bodyDictionary.ContainsKey("inputCosignerPhone") ? (string)bodyDictionary["inputCosignerPhone"] : "",
                };

                // create a new envelope which we will use to send the signature request
                EnvelopeDefinition envDef = new EnvelopeDefinition();
                envDef.EmailSubject = "Auto Loan Application";
                envDef.EmailBlurb   = "Please sign the Loan application to start the application process.";
                envDef.TemplateId   = configSettings.AUTOLOAN_TEMPLATEID;

                // create a template role with a valid templateId and roleName and assign signer info
                var tRoleApplicant = new TemplateRole();
                tRoleApplicant.RoleName = "applicant";
                tRoleApplicant.Name     = body.inputFirstName + " " + body.inputLastName;
                tRoleApplicant.Email    = body.inputEmail;
                if (body.inputSigningLocation == "embedded")
                {
                    tRoleApplicant.ClientUserId = "1001";
                }
                if (body.inputAccessCode != "" && body.inputAccessCode.Length > 0)
                {
                    tRoleApplicant.AccessCode = body.inputAccessCode;
                }
                if (body.inputAuthentication == "phone")
                {
                    Helper.addPhoneAuthToRecipient(tRoleApplicant, body.inputPhone);
                }

                tRoleApplicant.Tabs = new Tabs();

                // Phone
                tRoleApplicant.Tabs.TextTabs = new List <Text>();
                Text text1Applicant = new Text();
                text1Applicant.TabLabel = "Phone";
                text1Applicant.Value    = body.inputPhone;
                tRoleApplicant.Tabs.TextTabs.Add(text1Applicant);

                // Amount
                tRoleApplicant.Tabs.NumberTabs = new List <Number>();
                Number number1Applicant = new Number();
                number1Applicant.TabLabel = "Amount";
                number1Applicant.Value    = body.inputLoanAmount;
                tRoleApplicant.Tabs.NumberTabs.Add(number1Applicant);

                // Payment payback period (months)
                //                signer.Tabs.NumberTabs = new List<Number>();
                Number number2Applicant = new Number();
                number2Applicant.TabLabel = "PaymentDuration";
                number2Applicant.Value    = body.inputLoanLength;
                tRoleApplicant.Tabs.NumberTabs.Add(number2Applicant);


                var tRoleCosigner = new TemplateRole();
                tRoleCosigner.RoleName = "cosigner";
                tRoleCosigner.Name     = body.inputCosignerFirstName + " " + body.inputCosignerLastName;
                tRoleCosigner.Email    = body.inputCosignerEmail;
                if (body.inputSigningLocationCosigner == "embedded")
                {
                    tRoleCosigner.ClientUserId = "2002";
                }
                if (body.inputAccessCodeCosigner != "" && body.inputAccessCodeCosigner.Length > 0)
                {
                    tRoleCosigner.AccessCode = body.inputAccessCodeCosigner;
                }
                if (body.inputAuthenticationCosigner == "phone")
                {
                    Helper.addPhoneAuthToRecipient(tRoleCosigner, body.inputCosignerPhone);
                }

                tRoleCosigner.Tabs = new Tabs();

                // Phone
                tRoleCosigner.Tabs.TextTabs = new List <Text>();
                Text text1Cosigner = new Text();
                text1Cosigner.TabLabel = "Phone";
                text1Cosigner.Value    = body.inputCosignerPhone;
                tRoleCosigner.Tabs.TextTabs.Add(text1Cosigner);

                var tRoleEmployee = new TemplateRole();
                tRoleEmployee.RoleName = "employee";

                tRoleEmployee.Name  = configSettings.EMPLOYEE_NAME;
                tRoleEmployee.Email = configSettings.EMPLOYEE_EMAIL;

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

                List <TemplateRole> rolesList = new List <TemplateRole>()
                {
                    tRoleApplicant, tRoleEmployee
                };

                //add the cosigner if the checkbox is selected on the web page
                if (body.inputCosignerCheckbox == "on")
                {
                    rolesList.Add(tRoleCosigner);
                }

                envDef.TemplateRoles = rolesList;

                EnvelopesApi    envelopesApi    = new EnvelopesApi();
                EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);

                rtn.Add(envelopeSummary);   //Index 0: add envelopeSummary to the return object
                if (body.inputSigningLocation == "embedded")
                {
                    ViewUrl viewUrl = Helper.getRecipientUrl(envelopesApi, accountId, envDef, envelopeSummary.EnvelopeId.ToString(), tRoleApplicant);
                    rtn.Add(viewUrl);    //Index 1: add viewURL to the return object
                }
                rtn.Add(tRoleApplicant); //Index 2: add tRoleApplicant to the return object
                rtn.Add(tRoleCosigner);  //Index 3: add tRoleCosigner to the return object
                return(rtn);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw ex;
            }
        }
        static string CreateDocuSignEnvelope()
        {
            string userId             = ConfigurationManager.AppSettings["UserId"];
            string oauthBasePath      = ConfigurationManager.AppSettings["OAuthBasePath"];
            string integratorKey      = ConfigurationManager.AppSettings["IntegratorKey"];
            string privateKeyFilename = AppContext.BaseDirectory + "PrivateKey.txt";
            string host           = ConfigurationManager.AppSettings["Host"];
            string templateId     = ConfigurationManager.AppSettings["TemplateID"];
            int    expiresInHours = 1;

            //string accountId = string.Empty;

            ApiClient apiClient = new ApiClient(host);

            apiClient.ConfigureJwtAuthorizationFlow(integratorKey, userId, oauthBasePath, privateKeyFilename, expiresInHours);

            /////////////////////////////////////////////////////////////////
            // STEP 1: LOGIN API
            /////////////////////////////////////////////////////////////////
            AuthenticationApi authApi   = new AuthenticationApi(apiClient.Configuration);
            LoginInformation  loginInfo = authApi.Login();

            // find the default account for this user
            foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true")
                {
                    accountID = loginAcct.AccountId;

                    string[] separatingStrings = { "/v2" };

                    // Update ApiClient with the new base url from login call
                    apiClient = new ApiClient(loginAcct.BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]);
                    break;
                }
            }

            /////////////////////////////////////////////////////////////////
            // STEP 2: CREATE ENVELOPE API
            /////////////////////////////////////////////////////////////////

            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.EmailSubject = "MS Build Demo - Please sign this doc";

            // assign recipient to template role by setting name, email, and role name.  Note that the
            // template role name must match the placeholder role name saved in your account template.
            TemplateRole tRole = new TemplateRole();

            tRole.Email    = ConfigurationManager.AppSettings["RecipientEmail"];
            tRole.Name     = ConfigurationManager.AppSettings["RecipientName"];
            tRole.RoleName = "Signer";
            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRole
            };

            // add the role to the envelope and assign valid templateId from your account
            envDef.TemplateRoles = rolesList;
            envDef.TemplateId    = templateId;

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

            // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
            EnvelopesApi    envelopesApi    = new EnvelopesApi(apiClient.Configuration);
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);

            return(envelopeSummary.EnvelopeId);
        }
        public static ViewUrl getRecipientUrl(EnvelopesApi envelopesApi, string accountId, EnvelopeDefinition envDef, string envelopeId, TemplateRole templateRole)
        {
            // set the url where you want the recipient to go once they are done signing
            // - this can be used by your app to watch the URL and detect when signing has completed (or was canceled)
            var returnUrl = new RecipientViewRequest();

            //Get Config settings from App.config
            DocuSignConfig configSettings = new DocuSignConfig();

            returnUrl.ReturnUrl = configSettings.LOCAL_RETURN_URL + "pop/" + envelopeId;

            returnUrl.AuthenticationMethod = "email";

            // recipient information must match embedded recipient info we provided
            returnUrl.UserName     = templateRole.Name;
            returnUrl.Email        = templateRole.Email;
            returnUrl.ClientUserId = templateRole.ClientUserId;

            RecipientViewRequest recipipentViewRequest = new RecipientViewRequest();
            ViewUrl viewUrl = new ViewUrl();

            viewUrl = envelopesApi.CreateRecipientView(accountId, envelopeId, returnUrl);
            return(viewUrl);
        }
Exemplo n.º 22
0
        public string CreateURL(string signerEmail, string signerName, string ccEmail,
                                string ccName)
        {
            var lingkEnvelopeFilePath = LingkConst.LingkFileSystemPath;
            var envResp = LingkFile.CheckEnvelopeExists(lingkEnvelopeFilePath,
                                                        new LingkEnvelope
            {
                accountId  = accountId,
                templateId = templateId
            });

            if (envResp != null)
            {
                return(envResp.recipientUrl);
            }

            var apiClient = new ApiClient(lingkCredentials.credentialsJson.isSandbox ? LingkConst.DocusignDemoUrl : LingkConst.DocusignProdUrl);

            apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + this.lingkCredentials.docuSignToken.access_token);

            Tabs tabs = GetValidTabs();

            TemplateRole signer = new TemplateRole
            {
                Email        = signerEmail,
                Name         = signerName,
                RoleName     = "signer",
                ClientUserId = signerClientId, // Change the signer to be embedded
                Tabs         = tabs            //Set tab values
            };

            TemplateRole cc = new TemplateRole
            {
                Email    = ccEmail,
                Name     = ccName,
                RoleName = "cc"
            };

            // Step 4: Create the envelope definition
            EnvelopeDefinition envelopeAttributes = new EnvelopeDefinition
            {
                // Uses the template ID received from example 08
                TemplateId = templateId,

                Status        = "Sent",
                TemplateRoles = new List <TemplateRole> {
                    signer, cc
                }
            };

            var             envelopesApi = new EnvelopesApi(apiClient);
            EnvelopeSummary results      = envelopesApi.CreateEnvelope(accountId, envelopeAttributes);

            RecipientViewRequest viewRequest = new RecipientViewRequest();

            viewRequest.ReturnUrl            = selectedEnvelope.DocusignReturnUrl;
            viewRequest.AuthenticationMethod = "none";
            viewRequest.Email        = signerEmail;
            viewRequest.UserName     = signerName;
            viewRequest.ClientUserId = signerClientId;
            var     envelopeId = results.EnvelopeId;
            ViewUrl results1   = envelopesApi.CreateRecipientView(accountId, envelopeId, viewRequest);

            string redirectUrl = results1.Url;

            LingkFile.AddDocusignEnvelope(lingkEnvelopeFilePath,
                                          new LingkEnvelope
            {
                envelopeId   = envelopeId,
                accountId    = accountId,
                recipientUrl = redirectUrl,
                templateId   = templateId
            });
            return(redirectUrl);
        }
Exemplo n.º 23
0
    //static void Main(string[] args)
    protected void SignIt(object sender, EventArgs e)
    {
        string userId         = "aa621eb5-e488-4135-9698-613136bce319"; // use your userId (guid), not email address
        string oauthBasePath  = "account-d.docusign.com";
        string integratorKey  = "ad00790f-c0c8-49d8-a621-904549bc9d88";
        string privateKeyFile = Server.MapPath(@"~/App_Data/DocuSign_PrivateKey.pem");
        string privateKey     = System.IO.File.ReadAllText(privateKeyFile);

        int    expiresInHours = 1;
        string host           = "https://demo.docusign.net/restapi";

        string accountId = string.Empty;

        ApiClient apiClient = new ApiClient(host);

        OAuth.OAuthToken tokenInfo = apiClient.ConfigureJwtAuthorizationFlowByKey(integratorKey, userId, oauthBasePath, privateKey, expiresInHours);

        /////////////////////////////////////////////////////////////////
        // STEP 1: Get User Info
        // now that the API client has an OAuth token, let's use it in all// DocuSign APIs
        /////////////////////////////////////////////////////////////////

        OAuth.UserInfo userInfo = apiClient.GetUserInfo(tokenInfo.access_token);

        foreach (var item in userInfo.GetAccounts())
        {
            if (item.GetIsDefault() == "true")
            {
                accountId = item.AccountId();
                apiClient = new ApiClient(item.GetBaseUri() + "/restapi");
                break;
            }
        }

        /////////////////////////////////////////////////////////////////
        // STEP 2: CREATE ENVELOPE API
        /////////////////////////////////////////////////////////////////

        EnvelopeDefinition envDef = new EnvelopeDefinition();

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

        // assign recipient to template role by setting name, email, and role name.  Note that the
        // template role name must match the placeholder role name saved in your account template.
        TemplateRole tRole = new TemplateRole();

        tRole.Email    = "[SIGNER_EMAIL]";
        tRole.Name     = "[SIGNER_NAME]";
        tRole.RoleName = "[ROLE_NAME]";
        List <TemplateRole> rolesList = new List <TemplateRole>()
        {
            tRole
        };

        // add the role to the envelope and assign valid templateId from your account
        envDef.TemplateRoles = rolesList;
        envDef.TemplateId    = "[TEMPLATE_ID]";

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

        // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
        EnvelopesApi    envelopesApi    = new EnvelopesApi(apiClient.Configuration);
        EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);
    }