/// <summary> /// This retrieves the definition of the specified template. /// </summary> /// <returns></returns> public byte[] GetTemplatePreview(string templateId) { RequestBuilder builder = new RequestBuilder(); RequestInfo req = new RequestInfo(); List <RequestBody> requestBodies = new List <RequestBody>(); req.RequestContentType = "application/json"; req.AcceptContentType = "application/json"; req.HttpMethod = "GET"; 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}/templates/{1}/documents/{2}/pages/1/page_image", this.Login.BaseUrl, templateId, GetDocIds(templateId)[0]); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); } return(response.ResponseBytes); }
/// <summary> /// Returns a list of templates for this user's account /// </summary> /// <returns></returns> public List <TemplateInfo> GetTemplates() { RequestBuilder builder = new RequestBuilder(); RequestInfo req = new RequestInfo(); List <RequestBody> requestBodies = new List <RequestBody>(); req.RequestContentType = "application/json"; req.AcceptContentType = "application/json"; req.HttpMethod = "GET"; 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}/templates?order=desc&order_by=used", this.Login.BaseUrl); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); var templates = new List <TemplateInfo>(); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); } else { JObject json = JObject.Parse(response.ResponseText); // For the case of no templates in an account, the JSON doesn't even contain envelopeTemplates property if (json["envelopeTemplates"] != null) { foreach (var template in json["envelopeTemplates"]) { templates.Add(new TemplateInfo { Id = (string)template["templateId"], Name = (string)template["name"], // removing end of lines from description as it's breaking the UI Description = ((string)template["description"]).Replace('\n', ' ').Replace('\r', ' ') }); } } } return(templates); }
/// <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; } }
/// <summary> /// Updates an envelope status /// </summary> /// <param name="envelopeId">The envelopeId for this envelope</param> /// <returns>Date/Time when the status was set</returns> public DateTime GetStatus(string envelopeId) { 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 = "GET"; 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, envelopeId); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); return DateTime.MinValue; } JObject json = JObject.Parse(response.ResponseText); this.Status = (string)json["status"]; this.EmailSubject = (string)json["emailSubject"]; this.EmailBlurb = (string)json["emailBlurb"]; this.Created = DateTime.Parse((string)json["createdDateTime"]); return (DateTime)json["statusChangedDateTime"]; } 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 DateTime.MinValue; } throw; } }
/// <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; } }
/// <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; } }
/// <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; } }
/// <summary> /// Get the list of Templates Matched with the envelope /// </summary> /// <exception cref="ArgumentNullException">If we find a null or empty envelopeId</exception> /// <returns>object with information about the envelope's documents</returns> public EnvelopeTemplates GetEnvelopeMatchingTemplates() { 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 = "GET"; 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?include=matching%2Capplied", this.Login.BaseUrl, this.EnvelopeId); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); return null; } else { return EnvelopeTemplates.FromJson(response.ResponseText); } } 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 null; } throw; } }
/// <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; } }
/// <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; } }
/// <summary> /// Logs in to the account based on the credentials provided. /// </summary> /// <returns>true if successful, false otherwise</returns> public bool GetUserConsoleView() { try { RequestInfo req = new RequestInfo(); RequestBuilder utils = new RequestBuilder(); 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; req.Uri = string.Format("{0}/views/console", this.BaseUrl); if (string.IsNullOrWhiteSpace(this.SOBOUserId) == false) { req.SOBOUserId = this.SOBOUserId; utils.AuthorizationFormat = RequestBuilder.AuthFormat.Json; } utils.Request = req; utils.Proxy = this.Proxy; ResponseInfo response = utils.MakeRESTRequest(); this.Trace(utils, response); if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created) { this.ParseConsoleResponse(response); } else { this.ParseErrorResponse(response); } return (response.StatusCode == HttpStatusCode.OK || 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> /// 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; } }
/// <summary> /// Logs in to the account based on the credentials provided. /// </summary> /// <param name="planId">Plan ID</param> /// <returns>Plan object if successful, null otherwise</returns> public Plan BillingPlan(string planId) { try { RequestInfo req = new RequestInfo(); RequestBuilder builder = new RequestBuilder(); req.RequestContentType = "application/json"; req.AcceptContentType = "application/json"; req.HttpMethod = "GET"; 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; req.Uri = string.Format("{0}{1}", RestSettings.Instance.WebServiceUrl, string.Format("/billing_plans/{0}", planId)); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); } else { return Plan.FromJson(response.ResponseText); } } catch { } return null; }
/// <summary> /// Retreive information about the account /// <returns>Collection of objects</returns> /// </summary> public JObject GetAccountInfo() { RequestInfo req = new RequestInfo(); RequestBuilder utils = new RequestBuilder(); req.RequestContentType = "application/json"; req.AcceptContentType = "application/json"; req.HttpMethod = "GET"; req.LoginEmail = this.Email; req.LoginPassword = string.IsNullOrEmpty(this.ApiPassword) == false ? this.ApiPassword : this.Password; req.IntegratorKey = RestSettings.Instance.IntegratorKey; req.Uri = this.BaseUrl; utils.Request = req; utils.Proxy = this.Proxy; ResponseInfo response = utils.MakeRESTRequest(); this.Trace(utils, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); } JObject json = JObject.Parse(response.ResponseText); return json; }
/// <summary> /// Account provisioning /// </summary> /// <returns>true if successful, false otherwise</returns> public bool Provisioning() { try { RequestInfo req = new RequestInfo(); RequestBuilder builder = new RequestBuilder(); req.RequestContentType = "application/json"; req.AcceptContentType = "application/json"; req.HttpMethod = "GET"; 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; req.Uri = string.Format("{0}{1}", RestSettings.Instance.WebServiceUrl, "/provisioning.json"); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); } else { this.ParseLoginResponse(response); } return response.StatusCode == HttpStatusCode.OK; } catch { return false; } }
/// <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; } }
/// <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); } }
/// <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; } }
/// <summary> /// Returns a list of names of documents used to create this envelope /// </summary> /// <returns></returns> public List<EnvelopeDocument> GetDocuments() { 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 = "GET"; 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}/documents", this.Login.BaseUrl, EnvelopeId); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); return null; } JObject json = JObject.Parse(response.ResponseText); var docs = json["envelopeDocuments"]; var res = new List<EnvelopeDocument>(); if (docs != null) foreach (var jsonDoc in docs) if ((string)jsonDoc["type"] == "content") res.Add(new EnvelopeDocument { documentId = (string)jsonDoc["documentId"], name = (string)jsonDoc["name"] }); return res; } 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 null; } 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> /// 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; } }
/// <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; } }
/// <summary> /// Returns a list of names of the recipients /// </summary> /// <returns></returns> public IEnumerable<string> GetRecipientNames() { RequestBuilder builder = new RequestBuilder(); RequestInfo req = new RequestInfo(); List<RequestBody> requestBodies = new List<RequestBody>(); req.RequestContentType = "application/json"; req.AcceptContentType = "application/json"; req.HttpMethod = "GET"; 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}/recipients", this.Login.BaseUrl, EnvelopeId); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); return null; } JObject json = JObject.Parse(response.ResponseText); var names = new List<string>(); var signers = json["signers"]; foreach (var signer in signers) names.Add((string)signer["name"]); var ccs = json["carbonCopies"]; foreach (var cc in ccs) names.Add((string)cc["name"]); var certifiedDeliveries = json["certifiedDeliveries"]; foreach (var cd in certifiedDeliveries) names.Add((string)cd["name"]); return names; }
/// <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; } }
/// <summary> /// Returns all recipients that have lowest routing value (meaning they need to sign first) /// </summary> /// <returns></returns> public IEnumerable<JToken> GetFirstRecipients() { 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 = "GET"; 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}/recipients", this.Login.BaseUrl, EnvelopeId); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); return new List<JToken>(); } JObject json = JObject.Parse(response.ResponseText); var signers = json["signers"]; // return the first signer if (signers.Count() > 0) { int minRoute = signers.Min(s => (int)s["routingOrder"]); return signers.Where(s => (int)s["routingOrder"] == minRoute); } else { return signers; } } 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 null; } throw; } }
/// <summary> /// Get the custom fields loaded into this envelope object /// </summary> /// <returns>true if successful, false otherwise</returns> public bool GetCustomFields() { 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 = "GET"; req.LoginEmail = Login.Email; req.LoginPassword = Login.Password; req.ApiPassword = Login.ApiPassword; req.DistributorCode = RestSettings.Instance.DistributorCode; req.DistributorPassword = RestSettings.Instance.DistributorPassword; req.IntegratorKey = RestSettings.Instance.IntegratorKey; req.Uri = string.Format("{0}/envelopes/{1}/custom_fields.json", this.Login.BaseUrl, this.EnvelopeId); 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; } this.CustomFields = JsonConvert.DeserializeObject<CustomFields>(response.ResponseText); 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; } }
/// <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; } }
/// <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; } }
/// <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; }
/// <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; }
/// <summary> /// Gets the signed pdf when its completed from service /// </summary> /// <param name="envelopeId">The envelopeId for this envelope</param> /// <param name="includeCertificate">true to include a certificate of completion</param> /// <exception cref="ArgumentNullException">If we find a null or empty envelopeId</exception> /// <returns>Array of bytes for the signed document</returns> public byte[] GetCompletedDocument(string envelopeId, bool includeCertificate) { if (string.IsNullOrEmpty(envelopeId) == true) { throw new ArgumentNullException("envelopeId"); } 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 = "GET"; 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}/documents/combined?certificate={2}", this.Login.BaseUrl, envelopeId, includeCertificate.ToString().ToLower()); builder.Request = req; builder.Proxy = this.Proxy; ResponseInfo response = builder.MakeRESTRequest(); return response.ResponseBytes; } 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 null; } throw; } }
/// <summary> /// Gets the recipients in the envelope /// </summary> /// <param name="includeTabs"></param> /// <param name="includeExtended"></param> /// <returns>true if successful, false otherwise</returns> public bool GetRecipients(bool includeTabs, bool includeExtended) { try { var includeTabsUrlParam = (includeTabs) ? "true" : "false"; var includeExtendedUrlParam = (includeExtended) ? "true" : "false"; 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}/recipients?include_tabs={1}&include_extended={2}", EnvelopeId, includeTabsUrlParam, includeExtendedUrlParam); req.HttpMethod = "GET"; req.IntegratorKey = RestSettings.Instance.IntegratorKey; RequestBuilder builder = new RequestBuilder(); builder.Proxy = Proxy; builder.Request = req; List<RequestBody> requestBodies = new List<RequestBody>(); ResponseInfo response = builder.MakeRESTRequest(); this.Trace(builder, response); if (response.StatusCode != HttpStatusCode.OK) { this.ParseErrorResponse(response); return false; } Recipients = JsonConvert.DeserializeObject<Recipients>(response.ResponseText); 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; } }
/// <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; } }