|
| 1 | +// <copyright file="SetConnectedFields.cs" company="DocuSign"> |
| 2 | +// Copyright (c) DocuSign. All rights reserved. |
| 3 | +// </copyright> |
| 4 | + |
| 5 | +namespace DocuSign.CodeExamples.Examples |
| 6 | +{ |
| 7 | + using System; |
| 8 | + using System.Collections.Generic; |
| 9 | + using System.Linq; |
| 10 | + using System.Net.Http; |
| 11 | + using System.Net.Http.Headers; |
| 12 | + using System.Text; |
| 13 | + using System.Text.Json; |
| 14 | + using System.Threading.Tasks; |
| 15 | + using DocuSign.CodeExamples.ConnectedFields.Models; |
| 16 | + using DocuSign.eSign.Api; |
| 17 | + using DocuSign.eSign.Client; |
| 18 | + using DocuSign.eSign.Model; |
| 19 | + using static System.Net.Mime.MediaTypeNames; |
| 20 | + |
| 21 | + public static class SetConnectedFields |
| 22 | + { |
| 23 | + private static readonly HttpClient Client = new HttpClient(); |
| 24 | + |
| 25 | + public static async Task<ExtensionApps> GetConnectedFieldsAsync(string accessToken, string accountId) |
| 26 | + { |
| 27 | + string baseUrl = "https://api-d.docusign.com/v1"; |
| 28 | + string requestUrl = $"{baseUrl}/accounts/{accountId}/connected-fields/tab-groups"; |
| 29 | + |
| 30 | + using (var request = new HttpRequestMessage(HttpMethod.Get, requestUrl)) |
| 31 | + { |
| 32 | + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); |
| 33 | + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); |
| 34 | + request.Headers.Add("Content-Type", "application/json"); |
| 35 | + |
| 36 | + HttpResponseMessage response = await Client.SendAsync(request); |
| 37 | + string responseBody = await response.Content.ReadAsStringAsync(); |
| 38 | + |
| 39 | + return JsonSerializer.Deserialize<ExtensionApps>(responseBody); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + public static string SendEnvelopeViaEmail(string signerEmail, string signerName, ExtensionApp extension, string basePath, string accessToken, string accountId, string docPdf) |
| 44 | + { |
| 45 | + EnvelopeDefinition env = MakeEnvelope(signerEmail, signerName, extension, docPdf); |
| 46 | + var docuSignClient = new DocuSignClient(basePath); |
| 47 | + docuSignClient.Configuration.DefaultHeader.Add("Authorization", "Bearer " + accessToken); |
| 48 | + |
| 49 | + EnvelopesApi envelopesApi = new EnvelopesApi(docuSignClient); |
| 50 | + EnvelopeSummary results = envelopesApi.CreateEnvelope(accountId, env); |
| 51 | + return results.EnvelopeId; |
| 52 | + } |
| 53 | + |
| 54 | + public static EnvelopeDefinition MakeEnvelope(string signerEmail, string signerName, ExtensionApp extension, string docPdf) |
| 55 | + { |
| 56 | + EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition(); |
| 57 | + envelopeDefinition.EmailSubject = "Please sign this document set"; |
| 58 | + envelopeDefinition.Status = "sent"; |
| 59 | + |
| 60 | + string docPdfBytes = Convert.ToBase64String(System.IO.File.ReadAllBytes(docPdf)); |
| 61 | + |
| 62 | + Document document = new Document |
| 63 | + { |
| 64 | + DocumentBase64 = docPdfBytes, |
| 65 | + Name = "Lorem Ipsum", |
| 66 | + FileExtension = "pdf", |
| 67 | + DocumentId = "1", |
| 68 | + }; |
| 69 | + |
| 70 | + envelopeDefinition.Documents = new List<Document> { document }; |
| 71 | + |
| 72 | + Signer signer = new Signer |
| 73 | + { |
| 74 | + Email = signerEmail, |
| 75 | + Name = signerName, |
| 76 | + RecipientId = "1", |
| 77 | + RoutingOrder = "1", |
| 78 | + Tabs = new eSign.Model.Tabs |
| 79 | + { |
| 80 | + SignHereTabs = new List<SignHere> |
| 81 | + { |
| 82 | + new SignHere |
| 83 | + { |
| 84 | + AnchorString = "/sn1/", |
| 85 | + AnchorUnits = "pixels", |
| 86 | + AnchorYOffset = "10", |
| 87 | + AnchorXOffset = "20", |
| 88 | + }, |
| 89 | + }, |
| 90 | + TextTabs = new List<eSign.Model.Text> |
| 91 | + { |
| 92 | + new eSign.Model.Text |
| 93 | + { |
| 94 | + RequireInitialOnSharedChange = "false", |
| 95 | + RequireAll = "false", |
| 96 | + Name = extension.Tabs.First().ExtensionData.ApplicationName, |
| 97 | + Required = "false", |
| 98 | + Locked = "false", |
| 99 | + DisableAutoSize = "false", |
| 100 | + MaxLength = "4000", |
| 101 | + TabLabel = extension.Tabs.First().TabLabel, |
| 102 | + Font = "lucidaconsole", |
| 103 | + FontColor = "black", |
| 104 | + FontSize = "size9", |
| 105 | + DocumentId = "1", |
| 106 | + RecipientId = "1", |
| 107 | + PageNumber = "1", |
| 108 | + XPosition = "273", |
| 109 | + YPosition = "191", |
| 110 | + Width = "84", |
| 111 | + Height = "22", |
| 112 | + TemplateRequired = "false", |
| 113 | + TabType = "text", |
| 114 | + //add extension code here |
| 115 | + }, |
| 116 | + }, |
| 117 | + }, |
| 118 | + }; |
| 119 | + |
| 120 | + return envelopeDefinition; |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments