/// <summary>
        /// Get envelopes for this user's account
        /// </summary>
        /// <param name="fromDate">start date to find envelopes for this user</param>
        /// <returns>List of envelopes for this account</returns>
        public AccountEnvelopes GetAccountsEnvelopes(DateTime fromDate)
        {
            CheckAPIPreRequisites();
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = "/envelopes?api_password=true&from_date=" + fromDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
                req.HttpMethod = "GET";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = this.Proxy;


                RequestBody rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");

                requestBodies.Add(rb);

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

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

                var envs = AccountEnvelopes.FromJson(response.ResponseText);
                return envs;

            }
            catch
            {
                throw;
            }

        }
示例#2
0
        /// <summary>
        /// Once an envelope has been created, this method obtains the URL to the sender view
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        public bool GetSenderView(string returnUrl)
        {
            try
            {
                RequestInfo req = new RequestInfo();
                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/" + this.EnvelopeId + "/views/sender.json?api_password=true";
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = this.Proxy;
                builder.Request = req;

                if (string.IsNullOrWhiteSpace(this.Login.SOBOUserId) == false)
                {
                    req.SOBOUserId = this.Login.SOBOUserId;
                    builder.AuthorizationFormat = RequestBuilder.AuthFormat.Json;
                }

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                SenderView sv = new SenderView();
                sv.returnUrl = returnUrl;

                rb.Text = sv.Serialize();
                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject json = JObject.Parse(response.ResponseText);

                    this.SenderViewUrl = (string)json["url"];
                }
                else
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.Created;
            }
            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;
            }
        }
示例#3
0
        /// <summary>
        /// Adds tabs to the envelope for the first/default recipient 
        /// </summary>
        /// <param name="tabs">List of tabs to add</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddTabs(TabCollection tabs)
        {
            try
            {
                RequestInfo req = new RequestInfo();
                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 = string.Format("/envelopes/{0}/recipients/{1}/tabs", EnvelopeId, (string)(GetFirstRecipients().First())["recipientIdGuid"]);
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = this.Proxy;
                builder.Request = req;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                foreach (var tab in tabs.textTabs)
                    tab.tabLabel = Guid.NewGuid().ToString();
                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;
                rb.Text = JsonConvert.SerializeObject(tabs, settings);

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return false;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.Created;
            }
            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;
            }
        }
示例#4
0
        /// <summary>
        /// Sends a reminder to recipient(s) that they need to sign
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        public bool SendReminder()
        {
            RequestInfo req = new RequestInfo();
            req.RequestContentType = "application/json";
            req.AcceptContentType = "application/json";
            req.BaseUrl = Login.BaseUrl;
            req.LoginEmail = Login.Email;
            req.LoginPassword = Login.Password;
            req.ApiPassword = Login.ApiPassword;
            req.Uri = String.Format("/envelopes/{0}?resend_envelope=true", EnvelopeId);
            req.HttpMethod = "PUT";
            req.IntegratorKey = RestSettings.Instance.IntegratorKey;

            RequestBuilder builder = new RequestBuilder();
            builder.Proxy = Proxy;
            builder.Request = req;

            List<RequestBody> requestBodies = new List<RequestBody>();
            RequestBody rb = new RequestBody();
            rb.Text = "{}";
            requestBodies.Add(rb);
            req.RequestBody = requestBodies.ToArray();
            builder.Request = req;
            ResponseInfo response = builder.MakeRESTRequest();
            this.Trace(builder, response);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                this.ParseErrorResponse(response);
                return false;
            }

            return true;
        }
示例#5
0
        /// <summary>
        /// Get draft envelopes for this user's account
        /// </summary>
        /// <param name="fromDate">start date to find envelopes for this user</param>
        /// <returns>List of envelopes for this account</returns>
        public AccountEnvelopes GetDraftEnvelopes(DateTime fromDate)
        {
            if (this.Login == null)
            {
                throw new ArgumentNullException("Login");
            }

            if (string.IsNullOrEmpty(this.Login.BaseUrl) == true)
            {
                throw new ArgumentNullException("BaseUrl");
            }

            if (string.IsNullOrEmpty(this.Login.ApiPassword) == true)
            {
                throw new ArgumentNullException("ApiPassword");
            }


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

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = "/search_folders/drafts?api_password=true&from_date=" + fromDate.ToString();
                req.HttpMethod = "GET";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = this.Proxy;


                RequestBody rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");

                requestBodies.Add(rb);

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

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

                var envs = new List<EnvelopeInfo>();
                JObject json = JObject.Parse(response.ResponseText);
                foreach (var item in json["folderItems"])
                {
                    var ei = new EnvelopeInfo();
                    ei.EnvelopeId = (string)item["envelopeId"];
                    ei.StatusChangedDateTime = (string)item["createdDateTime"];
                    ei.Status = "created";
                    envs.Add(ei);
                }
                return new AccountEnvelopes { Envelopes = envs.ToArray() };

            }
            catch
            {
                throw;
            }

        }
示例#6
0
        /// <summary>
        /// Adds a set of templates to the envelope
        /// </summary>
        /// <param name="templates">List of templates with auxiliary info such as documentStartPage etc.</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddTemplates(DocumentTemplates templates)
        {
            if (templates == null || templates.documentTemplates.Length == 0)
            {
                throw new ArgumentException("Empty set of template IDS provided");
            }
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "POST";
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.DistributorCode = RestSettings.Instance.DistributorCode;
                req.DistributorPassword = RestSettings.Instance.DistributorPassword;
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.Uri = string.Format("{0}/envelopes/{1}/templates", this.Login.BaseUrl, this.EnvelopeId);

                builder.Request = req;
                builder.Proxy = this.Proxy;
                
                RequestBody rb = new RequestBody();
                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;
                rb.Text = JsonConvert.SerializeObject(templates, settings);
                requestBodies.Add(rb);
                req.RequestBody = requestBodies.ToArray();

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

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    this.ParseErrorResponse(response);
                    return false;
                }
                else
                {
                    return true;
                }
            }
            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;
            }
        }
示例#7
0
        /// <summary>
        /// Creates a new account based on the account information provided.
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        /// <exception cref="ArgumentNullException">If password or email are missing</exception>
        public bool Create()
        {
            if (string.IsNullOrEmpty(this.Email) == true)
            {
                throw new ArgumentNullException("Email");
            }

            if (string.IsNullOrEmpty(this.AccountName) == true && this.ValidateSocial() == false)
            {
                throw new ArgumentException("Insufficient information to create account");
            }

            // clear out any previous account information
            this.BaseUrl = string.Empty;
            this.ApiPassword = string.Empty;
            this.IsDefault = false;

            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "POST";
                req.LoginEmail = this.Email;
                req.LoginPassword = this.Password;
                req.Uri = string.Format("{0}{1}", RestSettings.Instance.WebServiceUrl, "/accounts?api_password=true&include_account_id_guid=true");
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder utils = new RequestBuilder();
                utils.Proxy = this.Proxy;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                rb.Text = this.ConstructNewAccountJson();

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return false;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                utils.Request = req;
                ResponseInfo response = utils.MakeRESTRequest();

                this.Trace(utils, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    this.ParseCreateResponse(response);
                }
                else
                {
                    this.ParseErrorResponse(response);
                }
                return response.StatusCode == HttpStatusCode.Created;
            }
            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;
            }
        }
示例#8
0
        /// <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;
        }
示例#9
0
        /// <summary>
        /// Add documents to this envelope (must be in draft state)
        /// </summary>
        /// <param name="fileBytes">new file content</param>
        /// <param name="fileName">new file name</param>
        /// <param name="index">Index for the new file</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddDocument(List<byte[]> fileBytesList, List<string> fileNames, int index = 1)
        {
            CheckAPIPreRequisites();
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "multipart/form-data";
                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 = "PUT";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = Guid.NewGuid().ToString();
                builder.Proxy = this.Proxy;

                RequestBody rb = new RequestBody();
                rb.Text = this.CreateJson(fileNames, index);
                rb.Headers.Add("Content-Type", "application/json");
                rb.Headers.Add("Content-Disposition", "form-data");
                requestBodies.Add(rb);

                rb = new RequestBody();

                for (int i = 0; i < fileNames.Count; i++)
                {
                    var fileName = fileNames[i];
                    RequestBody reqFile = new RequestBody();
                    string mime = string.IsNullOrEmpty(this.MimeType) == true ? DefaultMimeType : this.MimeType;
                    reqFile.Headers.Add("Content-Type", mime);
                    reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", fileName, index++));

                    reqFile.FileBytes = fileBytesList[i];
                    reqFile.SubstituteStrings = false;
                    requestBodies.Add(reqFile);
                }

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

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

                if ((response.StatusCode == HttpStatusCode.OK) && (!response.ResponseText.Contains("FORMAT_CONVERSION_ERROR")))
                {
                    this.ParseCreateResponse(response);
                    return true;
                }
                else
                {
                    this.ParseErrorResponse(response);
                    return false;
                }
            }
            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;
            }
        }
示例#10
0
        /// <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;
            }
        }
示例#11
0
        /// <summary>
        /// Once an envelope has been created, this method obtains the URL to the recipient view
        /// </summary>
        /// <param name="returnUrl">URL to take user after signing is completed</param>
        /// <param name="signAndReturn">Optional - should new signing expereince show the "Sign and Return" dialog for self-signed envelopes</param>
        /// <param name="authMethod">Optional - the main authentication method that will be listed in the envelope's certificate of completion</param>        
        /// <returns>true if successful, false otherwise</returns>
        public bool GetRecipientView(string returnUrl, bool signAndReturn = true, string authMethod = "email")
        {
            CheckAPIPreRequisites();
            try
            {
                RequestInfo req = new RequestInfo();
                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}/views/recipient.json?api_password=true", this.EnvelopeId);
                if (!signAndReturn)
                {
                    req.Uri += "&disable_cc_for_selfsign=true";
                }
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = this.Proxy;
                builder.Request = req;

                if (string.IsNullOrWhiteSpace(this.Login.SOBOUserId) == false)
                {
                    req.SOBOUserId = this.Login.SOBOUserId;
                    builder.AuthorizationFormat = RequestBuilder.AuthFormat.Json;
                }

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                RecipientView rv = new RecipientView();
                rv.returnUrl = returnUrl;
                rv.email = this.Login.Email;
                rv.userName = this.Login.AccountName;
                rv.authenticationMethod = authMethod;

                rb.Text = rv.Serialize();
                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject json = JObject.Parse(response.ResponseText);

                    this.SenderViewUrl = (string)json["url"] + "&noDownloadPrint=true&appname=docusignit";
                }
                else
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.Created;
            }
            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;
            }
        }
示例#12
0
        /// <summary>
        /// Creates an envelope for the user.
        /// </summary>
        /// <param name="fileBytesList">Byte arrays of the files' content - in correct order.</param>
        /// <param name="documents">Documents - in correct order</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool Create(List<byte[]> fileBytesList, List<Document> documents)
        {
            CheckAPIPreRequisites();

            if (documents.Count != fileBytesList.Count)
            {
                throw new ArgumentException("Mismatch between number of files names and files' bytes content - they must be the same");
            }
            try
            {
                var builder = new RequestBuilder();
                var req = new RequestInfo();
                var requestBodies = new List<RequestBody>();

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = "/envelopes?api_password=true";
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = Proxy;

                if (string.IsNullOrWhiteSpace(Login.SOBOUserId) == false)
                {
                    req.SOBOUserId = this.Login.SOBOUserId;
                    builder.AuthorizationFormat = RequestBuilder.AuthFormat.Json;
                }

                var rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");
                rb.Headers.Add("Content-Disposition", "form-data");
                rb.Text = CreateJson(documents);
                requestBodies.Add(rb);

                for (var i = 0; i < documents.Count; i++)
                {
                    var reqFile = new RequestBody();
                    var mime = string.IsNullOrEmpty(MimeType) ? DefaultMimeType : MimeType;
                    reqFile.Headers.Add("Content-Type", mime);
                    reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", documents[i].name, i + 1));

                    reqFile.FileBytes = fileBytesList[i];
                    reqFile.SubstituteStrings = false;
                    requestBodies.Add(reqFile);
                }

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

                var response = builder.MakeRESTRequest();
                Trace(builder, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    ParseCreateResponse(response);
                    return GetSenderView(string.Empty);
                }

                ParseErrorResponse(response);

                return response.StatusCode == HttpStatusCode.Created;
            }
            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>
        /// Creates a new template
        /// </summary>
        /// <param name="fileBytes">Byte arrays of the files' content - in correct order.</param>
        /// <param name="fileNames">File names - in correct order</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool CreateTemplate(List<byte[]> fileBytesList, List<string> fileNames, string templateName)
        {
            CheckAPIPreRequisites();
            if (fileNames.Count != fileBytesList.Count)
            {
                throw new ArgumentException("Mismatch between number of files names and files' bytes content - they must be the same");
            }
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                //req.LoginPassword = this.Login.Password;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = "/templates?api_password=true";
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = this.Proxy;

                RequestBody rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");
                rb.Headers.Add("Content-Disposition", "form-data");
                rb.Text = this.CreateJson(fileNames);
                rb.Text += "  \"envelopeTemplateDefinition\": {\"name\": \"" + templateName + "\"}";
                requestBodies.Add(rb);

                for (int i = 0; i < fileNames.Count; i++)
                {
                    var fileName = fileNames[i];
                    RequestBody reqFile = new RequestBody();
                    string mime = string.IsNullOrEmpty(this.MimeType) == true ? DefaultMimeType : this.MimeType;
                    reqFile.Headers.Add("Content-Type", mime);
                    reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", fileName, i + 1));

                    reqFile.FileBytes = fileBytesList[i];
                    reqFile.SubstituteStrings = false;
                    requestBodies.Add(reqFile);
                }

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

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

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject json = JObject.Parse(response.ResponseText);
                    this.EnvelopeId = (string)json["templateId"];
                    return this.GetSenderView(string.Empty);
                }
                else
                {
                    this.ParseErrorResponse(response);
                    return false;
                }
            }
            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;
            }
        }
示例#14
0
        /// <summary>
        /// Add custom fields to this envelope
        /// </summary>
        /// <param name="customFields">Dictionary of custom fields to be added</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddCustomFields(Dictionary<string, object> customFields)
        {
            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.BaseUrl = Login.BaseUrl;
                req.LoginEmail = Login.Email;
                req.LoginPassword = Login.Password;
                req.ApiPassword = Login.ApiPassword;
                req.Uri = String.Format("/envelopes/{0}/custom_fields", EnvelopeId);
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = Proxy;
                builder.Request = req;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                var customFieldsArray = EnvelopeStatus.CustomField.CreateCustomFieldsArray(customFields);
                var textCustomFields = new Dictionary<string, TextCustomField[]>(){
                    {"textCustomFields" , customFieldsArray}
                };

                rb.Text = JsonConvert.SerializeObject(textCustomFields);
                requestBodies.Add(rb);
                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.Created;
            }
            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;
            }
        }
示例#15
0
        /// <summary>
        /// Adds a new user to an existing account
        /// </summary>
        /// <param name="users">Object representing the users to add</param>
        /// <returns>List of created users</returns>
        /// <exception cref="ArgumentNullException">If email, users or accountId are missing</exception>
        public CreatedUsers AddUser(AddUsers users)
        {
            if (users == null)
            {
                throw new ArgumentNullException("NewUser");
            }

            if (string.IsNullOrEmpty(this.Email) == true)
            {
                throw new ArgumentNullException("Email");
            }

            if (string.IsNullOrEmpty(this.AccountId) == true)
            {
                throw new ArgumentNullException("AccountId");
            }

            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "POST";
                req.LoginEmail = this.Email;
                req.LoginPassword = string.IsNullOrEmpty(this.ApiPassword) == false ? this.ApiPassword : this.Password;
                req.DistributorCode = RestSettings.Instance.DistributorCode;
                req.DistributorPassword = RestSettings.Instance.DistributorPassword;
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                string method = string.Format("/accounts/{0}/users?api_password=true", this.AccountId);

                if (String.IsNullOrEmpty(this.BaseUrl))
                {
                    req.Uri = string.Format("{0}{1}", RestSettings.Instance.WebServiceUrl, method);
                }
                else
                {
                    req.Uri = string.Format("{0}{1}", this.BaseUrl, "/users?api_password=true");
                }

                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder utils = new RequestBuilder();
                utils.Proxy = this.Proxy;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                rb.Text = users.Serialize();

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return null;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                utils.Request = req;
                ResponseInfo response = utils.MakeRESTRequest();

                this.Trace(utils, response);

                if (response.StatusCode != HttpStatusCode.Created)
                {
                    this.ParseErrorResponse(response);
                    return null;
                }

                return CreatedUsers.FromJson(response.ResponseText);
            }
            catch
            {
            }

            return null;
        }
示例#16
0
        /// <summary>
        /// Add documents to this envelope (must be in draft state)
        /// </summary>
        /// <param name="fileBytes">new file content</param>
        /// <param name="fileName">new file name</param>
        /// <param name="index">Index for the new file</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddDocument(List<byte[]> fileBytesList, List<string> fileNames, int index = 1)
        {
            RequestBuilder builder = new RequestBuilder();
            RequestInfo req = new RequestInfo();
            List<RequestBody> requestBodies = new List<RequestBody>();

            req.RequestContentType = "multipart/form-data";
            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 = "PUT";
            req.IntegratorKey = RestSettings.Instance.IntegratorKey;
            req.IsMultipart = true;
            req.MultipartBoundary = Guid.NewGuid().ToString();
            builder.Proxy = this.Proxy;

            RequestBody rb = new RequestBody();
            rb.Text = this.CreateJson(fileNames, index);
            rb.Headers.Add("Content-Type", "application/json");
            rb.Headers.Add("Content-Disposition", "form-data");
            requestBodies.Add(rb);

            rb = new RequestBody();

            for (int i = 0; i < fileNames.Count; i++)
            {
                var fileName = fileNames[i];
                RequestBody reqFile = new RequestBody();
                string mime = string.IsNullOrEmpty(this.MimeType) == true ? DefaultMimeType : this.MimeType;
                reqFile.Headers.Add("Content-Type", mime);
                reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", fileName, index++));

                reqFile.FileBytes = fileBytesList[i];
                reqFile.SubstituteStrings = false;
                requestBodies.Add(reqFile);
            }

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

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

            if ((response.StatusCode == HttpStatusCode.OK) && (!response.ResponseText.Contains("FORMAT_CONVERSION_ERROR")))
            {
                this.ParseCreateResponse(response);
                return true;
            }
            else
            {
                this.ParseErrorResponse(response);
                return false;
            }
        }
示例#17
0
        /// <summary>
        /// Adds social credentials to an existing account
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        /// <exception cref="ArgumentException">If insufficient information to associate account</exception>
        public bool AssociateSocialAccount()
        {
            if (this.ValidateSocial() == false)
            {
                throw new ArgumentException("Insufficient information to associate account");
            }

            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "PUT";
                req.ApiPassword = this.ApiPassword;
                req.LoginEmail = this.Email;
                req.Uri = string.Format("{0}/users/{2}/social.json", this.BaseUrl, this.AccountId, this.UserId);
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder utils = new RequestBuilder();
                utils.Proxy = this.Proxy;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                rb.Text = this.ConstructAssociateJson();

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return false;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                utils.Request = req;
                ResponseInfo response = utils.MakeRESTRequest();

                this.Trace(utils, response);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.OK;
            }
            catch
            {
                return false;
            }
        }
示例#18
0
        /// <summary>
        /// Get envelopes for this user's account
        /// </summary>
        /// <param name="fromDate">start date to find envelopes for this user</param>
        /// <returns>List of envelopes for this account</returns>
        public AccountEnvelopes GetAccountsEnvelopes(DateTime fromDate)
        {
            if (this.Login == null)
            {
                throw new ArgumentNullException("Login");
            }

            if (string.IsNullOrEmpty(this.Login.BaseUrl) == true)
            {
                throw new ArgumentNullException("BaseUrl");
            }

            if (string.IsNullOrEmpty(this.Login.ApiPassword) == true)
            {
                throw new ArgumentNullException("ApiPassword");
            }


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

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = "/envelopes?api_password=true&from_date=" + fromDate.ToString();
                req.HttpMethod = "GET";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = this.Proxy;


                RequestBody rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");

                requestBodies.Add(rb);

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

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

                var envs = AccountEnvelopes.FromJson(response.ResponseText);
                return envs;

            }
            catch
            {
                throw;
            }

        }
示例#19
0
        /// <summary>
        /// updates the envelope's status to the one provided
        /// </summary>
        /// <param name="voidedReason">voided reason required when status is being updated to voided</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool UpdateStatus(string voidedReason = null)
        {
            try
            {
                RequestBuilder builder = new RequestBuilder();
                RequestInfo req = new RequestInfo();
                List<RequestBody> requestBodies = new List<RequestBody>();

                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.HttpMethod = "PUT";
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.DistributorCode = RestSettings.Instance.DistributorCode;
                req.DistributorPassword = RestSettings.Instance.DistributorPassword;
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.Uri = string.Format("{0}/envelopes/{1}", this.Login.BaseUrl, this.EnvelopeId);

                RequestBody rb = new RequestBody();

                StringBuilder sb = new StringBuilder();
                sb.Append("{");
                sb.AppendFormat("\"status\":\"{0}\"", this.Status);

                if (this.Status == "voided") {

                    if (String.IsNullOrEmpty(voidedReason))
                        throw new ArgumentException("The voided reason is required to change status to voided.");

                    sb.AppendFormat(", \"voidedReason\":\"{0}\"", voidedReason);
                }
                    
                sb.Append("}");

                rb.Text = sb.ToString();
                requestBodies.Add(rb);

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

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

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    this.ParseErrorResponse(response);
                    return false;
                }


                return true;

            }
            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;
            }

        }
示例#20
0
        /// <summary>
        /// Gets the number of envelopes in the search folder
        /// </summary>
        /// <param name="folderName"></param>
        /// <param name="fromDate"></param>
        /// <returns></returns>
        public int GetSearchFolderCount(string folderName, DateTime fromDate)
        {
            if (this.Login == null)
            {
                throw new ArgumentNullException("Login");
            }

            if (string.IsNullOrEmpty(this.Login.BaseUrl) == true)
            {
                throw new ArgumentNullException("BaseUrl");
            }

            if (string.IsNullOrEmpty(this.Login.ApiPassword) == true)
            {
                throw new ArgumentNullException("ApiPassword");
            }


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

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = string.Format("/search_folders/{0}?from_date={1}", folderName, fromDate);
                req.HttpMethod = "GET";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = this.Proxy;


                RequestBody rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");

                requestBodies.Add(rb);

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

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

                JObject json = JObject.Parse(response.ResponseText);
                return (int)json["totalRows"];

            }
            catch
            {
                throw;
            }
        }
示例#21
0
        /// <summary>
        /// Creates an envelope for the user.
        /// </summary>
        /// <param name="path">String value of the full path to a document.  Not required.  May be null or empty.</param>
        /// <returns>true if successful, false otherwise</returns>
        /// <exception cref="ArgumentNullException">When Login or BaseUrl or ApiPassword or Path are missing</exception>
        public bool Create(string path)
        {
            if (this.Login == null)
            {
                throw new ArgumentNullException("Login");
            }

            if (string.IsNullOrEmpty(this.Login.BaseUrl) == true)
            {
                throw new ArgumentNullException("BaseUrl");
            }

            if (string.IsNullOrEmpty(this.Login.ApiPassword) == true)
            {
                throw new ArgumentNullException("ApiPassword");
            }

            if (string.IsNullOrEmpty(path) == true)
            {
                return this.CreateWithoutDocument();
            }

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

                req.RequestContentType = "multipart/form-data";
                req.BaseUrl = this.Login.BaseUrl;
                req.LoginEmail = this.Login.Email;
                //req.LoginPassword = this.Login.Password;
                req.ApiPassword = this.Login.ApiPassword;
                req.Uri = "/envelopes?api_password=true";
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;
                req.IsMultipart = true;
                req.MultipartBoundary = new Guid().ToString();
                builder.Proxy = this.Proxy;

                RequestBody rb = new RequestBody();
                rb.Headers.Add("Content-Type", "application/json");
                rb.Headers.Add("Content-Disposition", "form-data");

                FileInfo fi = new FileInfo(path);
                var listOfOne = new List<string>();
                listOfOne.Add(fi.Name);
                rb.Text = this.CreateJson(listOfOne);

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return false;
                }

                requestBodies.Add(rb);

                RequestBody reqFile = new RequestBody();
                string mime = string.IsNullOrEmpty(this.MimeType) == true ? DefaultMimeType : this.MimeType;
                reqFile.Headers.Add("Content-Type", mime);
                reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId=1", fi.Name));

                reqFile.FileNameBody = path;
                reqFile.SubstituteStrings = false;
                requestBodies.Add(reqFile);

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

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

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    this.ParseCreateResponse(response);
                    return this.GetSenderView(string.Empty);
                }
                else
                {
                    this.ParseErrorResponse(response);
                }

                return response.StatusCode == HttpStatusCode.Created;
            }
            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;
            }
        }
示例#22
0
        /// <summary>
        /// Creates an envelope for the user without a document.
        /// </summary>
        /// <returns>true if successful, false otherwise</returns>
        private bool CreateWithoutDocument()
        {
            try
            {
                RequestInfo req = new RequestInfo();
                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?api_password=true";
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = this.Proxy;
                builder.Request = req;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                rb.Text = this.CreateJson(new List<string>());

                if (string.IsNullOrEmpty(rb.Text) == true)
                {
                    return false;
                }

                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    this.ParseCreateResponse(response);
                    if (Status == "sent")
                    {
                        GetRecipientView();
                    }
                    else
                    {
                        GetSenderView(string.Empty);
                    }
                }
                else
                {
                    this.ParseErrorResponse(response);
                }
                return response.StatusCode == HttpStatusCode.Created;
            }
            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;
            }
        }
示例#23
0
        /// <summary>
        /// Creates an envelope for the user.
        /// </summary>
        /// <param name="fileBytes">Byte arrays of the files' content - in correct order.</param>
        /// <param name="fileNames">File names - in correct order</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool Create(List<byte[]> fileBytesList, List<string> fileNames)
        {
            if (this.Login == null)
            {
                throw new ArgumentNullException("Login");
            }

            if (string.IsNullOrEmpty(this.Login.BaseUrl) == true)
            {
                throw new ArgumentNullException("BaseUrl");
            }

            if (string.IsNullOrEmpty(this.Login.ApiPassword) == true)
            {
                throw new ArgumentNullException("ApiPassword");
            }
            if (fileNames.Count != fileBytesList.Count)
            {
                throw new ArgumentException("Mismatch between number of files names and files' bytes content - they must be the same");
            }

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

            req.RequestContentType = "multipart/form-data";
            req.BaseUrl = this.Login.BaseUrl;
            req.LoginEmail = this.Login.Email;
            //req.LoginPassword = this.Login.Password;
            req.ApiPassword = this.Login.ApiPassword;
            req.Uri = "/envelopes?api_password=true";
            req.HttpMethod = "POST";
            req.IntegratorKey = RestSettings.Instance.IntegratorKey;
            req.IsMultipart = true;
            req.MultipartBoundary = new Guid().ToString();
            builder.Proxy = this.Proxy;

            if (string.IsNullOrWhiteSpace(this.Login.SOBOUserId) == false)
            {
                req.SOBOUserId = this.Login.SOBOUserId;
                builder.AuthorizationFormat = RequestBuilder.AuthFormat.Json;
            }

            RequestBody rb = new RequestBody();
            rb.Headers.Add("Content-Type", "application/json");
            rb.Headers.Add("Content-Disposition", "form-data");
            rb.Text = this.CreateJson(fileNames);
            requestBodies.Add(rb);

            for (int i = 0; i < fileNames.Count; i++)
            {
                var fileName = fileNames[i];
                RequestBody reqFile = new RequestBody();
                string mime = string.IsNullOrEmpty(this.MimeType) == true ? DefaultMimeType : this.MimeType;
                reqFile.Headers.Add("Content-Type", mime);
                reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", fileName, i + 1));

                reqFile.FileBytes = fileBytesList[i];
                reqFile.SubstituteStrings = false;
                requestBodies.Add(reqFile);
            }

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

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

            if (response.StatusCode == HttpStatusCode.Created)
            {
                this.ParseCreateResponse(response);
                return this.GetSenderView(string.Empty);
            }
            else
            {
                this.ParseErrorResponse(response);
            }

            return response.StatusCode == HttpStatusCode.Created;
        }
示例#24
0
        /// <summary>
        /// Add subject and blurb information for an envelope one is sending
        /// </summary>
        /// <param name="subject">Email subject</param>
        /// <param name="blurb">Email body</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool AddEmailInformation(string subject, string blurb)
        {
            // for now just support adding all email details. We can expand if needed.
            if (String.IsNullOrEmpty(subject) || String.IsNullOrEmpty(blurb))
            {
                return false;
            }

            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.BaseUrl = Login.BaseUrl;
                req.LoginEmail = Login.Email;
                req.LoginPassword = Login.Password;
                req.ApiPassword = Login.ApiPassword;
                req.Uri = String.Format("/envelopes/{0}", EnvelopeId);
                req.HttpMethod = "PUT";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = Proxy;
                builder.Request = req;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                var emailDetails = new Dictionary<string, string>(){
                    {"emailBlurb", blurb},
                    {"emailSubject", subject}
                };

                rb.Text = JsonConvert.SerializeObject(emailDetails);
                requestBodies.Add(rb);
                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    this.ParseErrorResponse(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;
            }
        }
示例#25
0
        /// <summary>
        /// Generates a URL For embedded signing for a specific signer
        /// </summary>
        /// <param name="returnUrl">URL to take user after signing is completed</param>
        /// <param name="signer">Signer information for the person that would be signing</param>
        /// <param name="authMethod">Optional - the main authentication method that will be listed in the envelope's certificate of completion</param>        
        /// <returns>Url for embedded signing</returns>
        public string GetEmbeddedSignerView(string returnUrl, Signer signer, string authMethod = "email")
        {
            try
            {
                RequestInfo req = new RequestInfo();
                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/" + this.EnvelopeId + "/views/recipient";
                req.HttpMethod = "POST";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = this.Proxy;
                builder.Request = req;

                if (string.IsNullOrWhiteSpace(this.Login.SOBOUserId) == false)
                {
                    req.SOBOUserId = this.Login.SOBOUserId;
                    builder.AuthorizationFormat = RequestBuilder.AuthFormat.Json;
                }

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                RecipientView rv = new RecipientView();
                rv.returnUrl = returnUrl;
                rv.email = signer.email;
                rv.userName = signer.name;
                rv.clientUserId = signer.clientUserId;
                rv.authenticationMethod = authMethod;

                rb.Text = rv.Serialize();
                requestBodies.Add(rb);

                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject json = JObject.Parse(response.ResponseText);
                    return (string)json["url"];
                }

                return string.Empty;
            }
            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;
            }
        }
示例#26
0
        /// <summary>
        /// Update recipients in the envelope
        /// </summary>
        /// <param name="recipients"></param>
        /// <param name="resendEnvelope">True or false setting that defaults to false. 
        /// Setting this to true will resend the envelope to the recipient. 
        /// The resend_envelope flag is only used to resend an In Process envelope.</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool UpdateRecipients(Recipients recipients, bool resendEnvelope = false)
        {
            try
            {
                RequestInfo req = new RequestInfo();
                req.RequestContentType = "application/json";
                req.AcceptContentType = "application/json";
                req.BaseUrl = Login.BaseUrl;
                req.LoginEmail = Login.Email;
                req.LoginPassword = Login.Password;
                req.ApiPassword = Login.ApiPassword;
                req.Uri = String.Format(resendEnvelope ? "/envelopes/{0}/recipients?resend_envelope=true" : "/envelopes/{0}/recipients", EnvelopeId);
                req.HttpMethod = "PUT";
                req.IntegratorKey = RestSettings.Instance.IntegratorKey;

                RequestBuilder builder = new RequestBuilder();
                builder.Proxy = Proxy;
                builder.Request = req;

                List<RequestBody> requestBodies = new List<RequestBody>();
                RequestBody rb = new RequestBody();

                rb.Text = JsonConvert.SerializeObject(recipients);
                requestBodies.Add(rb);
                req.RequestBody = requestBodies.ToArray();
                builder.Request = req;
                ResponseInfo response = builder.MakeRESTRequest();
                this.Trace(builder, response);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    this.ParseErrorResponse(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;
            }
        }
示例#27
0
        /// <summary>
        /// Creates a new template
        /// </summary>
        /// <param name="fileBytes">Byte arrays of the files' content - in correct order.</param>
        /// <param name="fileNames">File names - in correct order</param>
        /// <returns>true if successful, false otherwise</returns>
        public bool CreateTemplate(List <byte[]> fileBytesList, List <string> fileNames, string templateName)
        {
            if (this.Login == null)
            {
                throw new ArgumentNullException("Login");
            }

            if (string.IsNullOrEmpty(this.Login.BaseUrl) == true)
            {
                throw new ArgumentNullException("BaseUrl");
            }

            if (string.IsNullOrEmpty(this.Login.ApiPassword) == true)
            {
                throw new ArgumentNullException("ApiPassword");
            }
            if (fileNames.Count != fileBytesList.Count)
            {
                throw new ArgumentException("Mismatch between number of files names and files' bytes content - they must be the same");
            }

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

            req.RequestContentType = "multipart/form-data";
            req.BaseUrl            = this.Login.BaseUrl;
            req.LoginEmail         = this.Login.Email;
            //req.LoginPassword = this.Login.Password;
            req.ApiPassword       = this.Login.ApiPassword;
            req.Uri               = "/templates?api_password=true";
            req.HttpMethod        = "POST";
            req.IntegratorKey     = RestSettings.Instance.IntegratorKey;
            req.IsMultipart       = true;
            req.MultipartBoundary = new Guid().ToString();
            builder.Proxy         = this.Proxy;

            RequestBody rb = new RequestBody();

            rb.Headers.Add("Content-Type", "application/json");
            rb.Headers.Add("Content-Disposition", "form-data");
            rb.Text  = this.CreateJson(fileNames);
            rb.Text += "  \"envelopeTemplateDefinition\": {\"name\": \"" + templateName + "\"}";
            requestBodies.Add(rb);

            for (int i = 0; i < fileNames.Count; i++)
            {
                var         fileName = fileNames[i];
                RequestBody reqFile  = new RequestBody();
                string      mime     = string.IsNullOrEmpty(this.MimeType) == true ? DefaultMimeType : this.MimeType;
                reqFile.Headers.Add("Content-Type", mime);
                reqFile.Headers.Add("Content-Disposition", string.Format("file; filename=\"{0}\"; documentId={1}", fileName, i + 1));

                reqFile.FileBytes         = fileBytesList[i];
                reqFile.SubstituteStrings = false;
                requestBodies.Add(reqFile);
            }

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

            ResponseInfo response = builder.MakeRESTRequest();

            this.Trace(builder, response);

            if (response.StatusCode == HttpStatusCode.Created)
            {
                JObject json = JObject.Parse(response.ResponseText);
                this.EnvelopeId = (string)json["templateId"];
                return(this.GetSenderView(string.Empty));
            }
            else
            {
                this.ParseErrorResponse(response);
                return(false);
            }
        }