/// <summary>
        /// Serializes the Json objects
        /// </summary>
        /// <param name="docPath">String value of the full path to a document.  Not required.  May be null or empty.</param>
        /// <returns>serialized Json text</returns>
        protected string CreateJson(List<string> docPaths, int startIndex = 1)
        {
            try
            {
                EnvelopeCreate env = new EnvelopeCreate();
                env.emailBlurb = RestSettings.Instance.EmailBlurb;
                env.emailSubject = string.IsNullOrEmpty(this.EmailSubject) ? RestSettings.Instance.EmailSubject : this.EmailSubject;
                if (this.CustomFields != null)
                {
                    env.customFields = this.CustomFields;
                }
                if (!String.IsNullOrEmpty(EmailBlurb))
                {
                    env.emailBlurb = EmailBlurb.Length > MaxBlurbSize
                        ? EmailBlurb.Substring(0, MaxBlurbSize)
                        : EmailBlurb;
                }

                env.recipients = this.Recipients;
                env.templateRoles = this.TemplateRoles;
                env.carbonCopies = this.CarbonCopies;
                env.status = this.Status;
                env.templateId = this.TemplateId;
                env.compositeTemplates = this.CompositeTemplates;

                // documents information...
                var docs = new List<Document>();
                int i = startIndex;
                foreach (var docPath in docPaths)
                {
                    var doc = new Document();

                    doc.documentId = i.ToString();
                    doc.name = docPath;
                    docs.Add(doc);
                    i++;
                }
                env.documents = docs.ToArray();

                env.eventNotification = this.Events;
                string output = JsonConvert.SerializeObject(env, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
                return output;
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return string.Empty;
                }

                throw;
            }
        }
        /// <summary>
        /// Remove documents from this envelop (must be in draft state)
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        public bool RemoveDocument(List<string> docList)
        {
            CheckAPIPreRequisites();
            if (docList == null)
            {
                return false;
            }

            if (docList.Count == 0)
            {
                return true;
            }

            List<Document> docs = new List<Document>();

            foreach (string docId in docList)
            {
                var doc = new Document { documentId = docId };
                docs.Add(doc);
            }
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = string.Format("/envelopes/{0}/documents/", this.EnvelopeId);
                req.HttpMethod = "DELETE";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                builder.Proxy = this.Proxy;

                RequestBody rb = new RequestBody();
                EnvelopeCreate env = new EnvelopeCreate();
                env.documents = docs.ToArray();

                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;
                rb.Text = JsonConvert.SerializeObject(env, settings);
                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;

                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                return response.StatusCode == HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException || ex is ProtocolViolationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return false;
                }

                throw;
            }
        }
        /// <summary>
        /// Remove documents from this envelop (must be in draft state)
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        public bool RemoveDocument(List<string> docList)
        {
            if (docList == null)
            {
                return false;
            }

            if (docList.Count == 0)
            {
                return true;
            }

            List<Document> docs = new List<Document>();

            foreach (string docId in docList)
            {
                var doc = new Document { documentId = docId };
                docs.Add(doc);
            }

            RequestBuilder builder = new RequestBuilder();
            RequestInfo req = new RequestInfo();
            List<RequestBody> requestBodies = new List<RequestBody>();

            req.RequestContentType = "application/json";
            req.AcceptContentType = "application/json";
            req.BaseUrl = this.Login.BaseUrl;
            req.LoginEmail = this.Login.Email;
            //req.LoginPassword = this.Login.Password;
            req.ApiPassword = this.Login.ApiPassword;
            req.Uri = "/envelopes/" + EnvelopeId + "/documents/";
            req.HttpMethod = "DELETE";
            req.IntegratorKey = RestSettings.Instance.IntegratorKey;
            builder.Proxy = this.Proxy;

            RequestBody rb = new RequestBody();
            EnvelopeCreate env = new EnvelopeCreate();
            env.documents = docs.ToArray();

            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.NullValueHandling = NullValueHandling.Ignore;
            rb.Text = JsonConvert.SerializeObject(env, settings);
            requestBodies.Add(rb);

            req.RequestBody = requestBodies.ToArray();
            builder.Request = req;

            ResponseInfo response = builder.MakeRESTRequest();
            this.Trace(builder, response);

            return response.StatusCode == HttpStatusCode.OK;
        }
        /// <summary>
        /// Serializes the Json objects
        /// </summary>
        /// <param name="documents">List of documents to add to the envelope. Not required, may be null or empty.</param>
        /// <returns></returns>
        private string CreateJson(List<Document> documents)
        {
            try
            {
                var env = new EnvelopeCreate
                {
                    emailBlurb = RestSettings.Instance.EmailBlurb,
                    emailSubject =
                        string.IsNullOrEmpty(EmailSubject) ? RestSettings.Instance.EmailSubject : EmailSubject,
                    recipients = Recipients,
                    templateRoles = TemplateRoles,
                    carbonCopies = CarbonCopies,
                    status = Status,
                    templateId = TemplateId,
                    compositeTemplates = CompositeTemplates,
                    notification = Notification,
                    documents = documents.ToArray(),
                    eventNotification = Events
                };

                if (CustomFields != null)
                {
                    env.customFields = CustomFields;
                }
                if (!string.IsNullOrEmpty(EmailBlurb))
                {
                    env.emailBlurb = EmailBlurb.Length > MaxBlurbSize
                        ? EmailBlurb.Substring(0, MaxBlurbSize)
                        : EmailBlurb;
                }
                var output = JsonConvert.SerializeObject(env, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
                return output;
            }
            catch (Exception ex)
            {
                if (ex is WebException || ex is NotSupportedException || ex is InvalidOperationException)
                {
                    // Once we get the debugging logger integrated into this project, we should write a log entry here
                    return string.Empty;
                }

                throw;
            }
        }