Exemple #1
0
        private (bool createdNewTemplate, string templateId, string resultsTemplateName) DoWork(
            string accessToken, string basePath, string accountId)
        {
            // Data for this method
            // accessToken
            // basePath
            // accountId


            // Step 1. List templates to see if ours exists already
            var config = new Configuration(new ApiClient(basePath));

            config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
            TemplatesApi templatesApi = new TemplatesApi(config);

            TemplatesApi.ListTemplatesOptions options = new TemplatesApi.ListTemplatesOptions();
            //options.searchText = "Example Signer and CC template";
            options.searchText = "CoD"; //Added by DT
            EnvelopeTemplateResults results = templatesApi.ListTemplates(accountId, options);

            string templateId;
            string resultsTemplateName;
            bool   createdNewTemplate;

            // Step 2. Process results
            if (int.Parse(results.ResultSetSize) > 0)
            {
                // Found the template! Record its id
                templateId          = results.EnvelopeTemplates[0].TemplateId;
                resultsTemplateName = results.EnvelopeTemplates[0].Name;
                createdNewTemplate  = false;
            }
            else
            {
                // No template! Create one!
                EnvelopeTemplate templateReqObject = MakeTemplate(templateName);

                TemplateSummary template = templatesApi.CreateTemplate(accountId, templateReqObject);

                // Retrieve the new template Name / TemplateId
                EnvelopeTemplateResults templateResults = templatesApi.ListTemplates(accountId, options);
                templateId          = templateResults.EnvelopeTemplates[0].TemplateId;
                resultsTemplateName = templateResults.EnvelopeTemplates[0].Name;
                createdNewTemplate  = true;
            }

            return(createdNewTemplate : createdNewTemplate,
                   templateId : templateId, resultsTemplateName : resultsTemplateName);
        }
        /// <summary>
        /// Generates a new DocuSign Template based on static information in this class
        /// </summary>
        /// <param name="accessToken">Access Token for API call (OAuth)</param>
        /// <param name="basePath">BasePath for API calls (URI)</param>
        /// <param name="accountId">The DocuSign Account ID (GUID or short version) for which the APIs call would be made</param>
        /// <returns>Template name, templateId and a flag to indicate if this is a new template or it exited prior to calling this method</returns>
        public static (bool createdNewTemplate, string templateId, string resultsTemplateName) CreateTemplate(string accessToken, string basePath, string accountId)
        {
            // Step 1. List templates to see if ours exists already
            var apiClient = new ApiClient(basePath);

            apiClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken);
            TemplatesApi templatesApi = new TemplatesApi(apiClient);

            TemplatesApi.ListTemplatesOptions options = new TemplatesApi.ListTemplatesOptions();
            options.searchText = "Example Signer and CC template";
            EnvelopeTemplateResults results = templatesApi.ListTemplates(accountId, options);

            string templateId;
            string resultsTemplateName;
            bool   createdNewTemplate;

            // Step 2. Process results
            if (int.Parse(results.ResultSetSize) > 0)
            {
                // Found the template! Record its id
                templateId          = results.EnvelopeTemplates[0].TemplateId;
                resultsTemplateName = results.EnvelopeTemplates[0].Name;
                createdNewTemplate  = false;
            }
            else
            {
                // No template! Create one!
                EnvelopeTemplate templateReqObject = MakeTemplate(templateName);

                TemplateSummary template = templatesApi.CreateTemplate(accountId, templateReqObject);

                // Retrieve the new template Name / TemplateId
                EnvelopeTemplateResults templateResults = templatesApi.ListTemplates(accountId, options);
                templateId          = templateResults.EnvelopeTemplates[0].TemplateId;
                resultsTemplateName = templateResults.EnvelopeTemplates[0].Name;
                createdNewTemplate  = true;
            }

            return(createdNewTemplate : createdNewTemplate,
                   templateId : templateId, resultsTemplateName : resultsTemplateName);
        }
        public void CreateTemplateTest()
        {
            try
            {
                AuthenticationApiTests authTests = new AuthenticationApiTests();
                authTests.LoginTest();

                EnvelopeTemplate templateDef = Utils.CreateDefaultTemplate();

                TemplatesApi    templatesApi = new TemplatesApi();
                TemplateSummary tempSummary  = templatesApi.CreateTemplate(TestConfig.AccountId, templateDef);
                Assert.IsNotNull(tempSummary);
                Assert.IsNotNull(tempSummary.TemplateId);
                Trace.WriteLine("TemplateSummary: " + tempSummary.ToJson());
            }
            catch (DocuSign.eSign.Client.ApiException apiEx)
            {
                // FAILS - API-3002 submitted.
                Assert.IsNotNull(apiEx.ErrorCode);
                Assert.IsTrue(!string.IsNullOrWhiteSpace(apiEx.Message));
                Assert.IsTrue(false, "Failed with ErrorCode: " + apiEx.ErrorCode + ", Message: " + apiEx.Message);
            }
        }