public void TemplateEndToEndTest() { Assert.IsTrue(string.IsNullOrEmpty(RestSettings.Instance.EmailSubject) == false, "Set the email subject for the envelope"); var template = new Template { Login = _account }; byte[] doc1 = { 36, 45, 34, 67, 121, 87, 99, 32, 32, 32, 54, 54, 55, 56, 32 }; var names = new List<string>(); var docs = new List<byte[]>(); names.Add("test1.doc"); docs.Add(doc1); // add recipients var signers = new List<Signer>(); signers.Add(new Signer { email = "*****@*****.**", name = "test test", recipientId = "1", roleName = "signer1", routingOrder = "1" }); signers.Add(new Signer { recipientId = "2", roleName = "signer2", routingOrder = "1" }); var recipients = new Recipients { signers = signers.ToArray() }; template.Recipients = recipients; Assert.IsTrue(template.CreateTemplate(docs, names, "DocuSign.NET Client Unit Test Template")); Assert.IsNull(template.RestError); // Note that EnvelopeId for a template is the TemplateId... // start a new envelope var templateId = template.EnvelopeId; var envelope = new Envelope { Login = _account }; Assert.IsTrue(envelope.Create()); // add the template var templates = new List<string>(); templates.Add(template.EnvelopeId); Assert.IsTrue(envelope.AddTemplates(templates)); Assert.IsNull(template.RestError); // update recipients recipients.signers[1].name = "test test2"; recipients.signers[1].email = "*****@*****.**"; Assert.IsTrue(envelope.UpdateRecipients(recipients, false)); Assert.IsNull(template.RestError); // send envelope envelope.Status = "sent"; Assert.IsTrue(envelope.UpdateStatus()); Assert.IsNull(template.RestError); }
/// <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; } }