Last active
June 24, 2021 21:15
-
-
Save codingdawg/736280cc43e91752eb64a0221db80896 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using DocuSign.eSign.Api; | |
using DocuSign.eSign.Client; | |
using DocuSign.eSign.Model; | |
using Newtonsoft.Json; | |
namespace DocusignApiTest | |
{ | |
public class TemplateTest : DocuSignApiBase | |
{ | |
public void CreateEnvelopeUsingCompositeTemplate() | |
{ | |
string accountId = Init(); | |
var envDef = new EnvelopeDefinition() | |
{ | |
EmailSubject = "Envelope with multiple recipient roles", | |
Status = "sent", | |
CompositeTemplates = new List<CompositeTemplate>() | |
{ | |
new CompositeTemplate() | |
{ | |
ServerTemplates = new List<ServerTemplate>() | |
{ | |
new ServerTemplate() | |
{ | |
TemplateId = "e844065f-e033-413f-816f-1dea5b956f44", //CreateTemplate() | |
Sequence = "1" | |
} | |
}, | |
InlineTemplates = new List<InlineTemplate>() | |
{ | |
new InlineTemplate() | |
{ | |
Sequence = "1", | |
Recipients = new Recipients() | |
{ | |
Signers = new List<Signer>() | |
{ | |
new Signer() | |
{ | |
Email = "Janedoe@acme.com", | |
Name = "Jane Doe", | |
RecipientId = "1", | |
RoleName = "Signer1", | |
}, | |
new Signer() | |
{ | |
Email = "Bobdoe@acme.com", | |
Name = "Bob Doe", | |
RecipientId = "2", | |
RoleName = "Signer2", | |
}, | |
new Signer() | |
{ | |
Email = "DanDoe@acme.com", | |
Name = "Dan Doe", | |
RecipientId = "3", | |
RoleName = "Signer3", | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}; | |
EnvelopesApi envelopesApi = new EnvelopesApi(); | |
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); | |
Console.WriteLine(envelopeSummary); | |
} | |
public string CreateTemplate() | |
{ | |
byte[] fileBytes = System.IO.File.ReadAllBytes(@"C:\Users\praveen.reddy\Box Sync\AnchorTagsOutOfBounds.pdf"); | |
string accountId = Init(); | |
var templateDef = new EnvelopeTemplate() | |
{ | |
EmailSubject = "Template " + DateTime.Now.ToString(), | |
EnvelopeTemplateDefinition = new EnvelopeTemplateDefinition() | |
{ | |
Name = "Template Name " + DateTime.Now.ToString(), | |
}, | |
Documents = new List<Document>() | |
{ | |
new Document() | |
{ | |
DocumentBase64 = System.Convert.ToBase64String(fileBytes), | |
Name = "TestFile.pdf", | |
DocumentId = "1" | |
} | |
}, | |
Recipients = new Recipients() | |
{ | |
Signers = new List<Signer>() | |
{ | |
new Signer() | |
{ | |
RoleName = "Signer1", | |
RecipientId = "1", | |
RoutingOrder = "1", | |
Tabs = new Tabs() | |
{ | |
SignHereTabs = new List<SignHere>() | |
{ | |
new SignHere() | |
{ | |
DocumentId = "1", | |
PageNumber = "1", | |
XPosition = "100", | |
YPosition = "100" | |
} | |
} | |
} | |
}, | |
new Signer() | |
{ | |
RoleName = "Signer2", | |
RecipientId = "2", | |
RoutingOrder = "2", | |
Tabs = new Tabs() | |
{ | |
SignHereTabs = new List<SignHere>() | |
{ | |
new SignHere() | |
{ | |
DocumentId = "1", | |
PageNumber = "1", | |
XPosition = "200", | |
YPosition = "100" | |
} | |
} | |
} | |
}, | |
new Signer() | |
{ | |
RoleName = "Signer3", | |
RecipientId = "3", | |
RoutingOrder = "2", | |
Tabs = new Tabs() | |
{ | |
SignHereTabs = new List<SignHere>() | |
{ | |
new SignHere() | |
{ | |
DocumentId = "1", | |
PageNumber = "1", | |
XPosition = "300", | |
YPosition = "100" | |
} | |
} | |
} | |
} | |
} | |
} | |
}; | |
TemplatesApi templatesApi = new TemplatesApi(); | |
TemplateSummary templateSummary = templatesApi.CreateTemplate(accountId, templateDef); | |
Console.WriteLine(templateSummary); | |
return templateSummary.TemplateId; | |
} | |
public void CreateEnvelopeSeparateEmailNotificationForRecipients() | |
{ | |
string accountID = Init(); | |
byte[] fileBytes = System.IO.File.ReadAllBytes(@"C:\temp\Test.pdf"); | |
var envDef = new EnvelopeDefinition() | |
{ | |
EmailSubject = "My Envelope Subject", | |
Status = "sent", | |
Documents = new List<Document>() | |
{ | |
new Document() | |
{ | |
DocumentBase64 = System.Convert.ToBase64String(fileBytes), | |
Name = "Contract", | |
DocumentId = "1" | |
} | |
}, | |
Recipients = new Recipients() | |
{ | |
Signers = new List<Signer>() | |
{ | |
new Signer() | |
{ | |
Email = "janedoe@acme.com", | |
Name = "Jane Doe", | |
RecipientId = "1", | |
RoutingOrder = "1", | |
EmailNotification = new RecipientEmailNotification() | |
{ | |
EmailSubject = "This is subject for Jane Doe", | |
EmailBody = "This is email body for Jane Doe" | |
}, | |
Tabs = new Tabs() | |
{ | |
SignHereTabs = new List<SignHere>() | |
{ | |
new SignHere() | |
{ | |
DocumentId = "1", | |
XPosition = "100", | |
YPosition = "300", | |
PageNumber = "1" | |
} | |
} | |
} | |
}, | |
new Signer() | |
{ | |
Email = "johnsmith@acme.com", | |
Name = "john smith", | |
RecipientId = "2", | |
RoutingOrder = "2", | |
EmailNotification = new RecipientEmailNotification() | |
{ | |
EmailSubject = "This is subject for john smith", | |
EmailBody = "This is email body for john smith" | |
}, | |
Tabs = new Tabs() | |
{ | |
SignHereTabs = new List<SignHere>() | |
{ | |
new SignHere() | |
{ | |
DocumentId = "1", | |
XPosition = "100", | |
YPosition = "200", | |
PageNumber = "1" | |
} | |
} | |
} | |
} | |
} | |
} | |
}; | |
EnvelopesApi envelopesApi = new EnvelopesApi(); | |
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef); | |
} | |
} | |
public class DocuSignApiBase | |
{ | |
protected const string _username = ""; | |
protected const string _integratorKey = ""; | |
protected const string _password = ""; | |
protected const string _baseUri = "https://demo.docusign.net/restapi"; | |
protected string _authHeader; | |
public DocuSignApiBase() | |
{ | |
// configure 'X-DocuSign-Authentication' header | |
_authHeader = "{\"Username\":\"" + _username + "\", \"Password\":\"" + _password + "\", \"IntegratorKey\":\"" + _integratorKey + "\"}"; | |
} | |
public string Init() | |
{ | |
// initialize client for desired environment (for production change to www) | |
ApiClient apiClient = new ApiClient(_baseUri); | |
Configuration.Default.ApiClient = apiClient; | |
Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", _authHeader); | |
// we will retrieve this from the login API call | |
string accountId = null; | |
///////////////////////////////////////////////////////////////// | |
// STEP 1: LOGIN API | |
///////////////////////////////////////////////////////////////// | |
// login call is available in the authentication api | |
AuthenticationApi authApi = new AuthenticationApi(); | |
LoginInformation loginInfo = authApi.Login(); | |
// parse the first account ID that is returned (user might belong to multiple accounts) | |
accountId = loginInfo.LoginAccounts[0].AccountId; | |
// Update ApiClient with the new base url from login call | |
apiClient = new ApiClient(loginInfo.LoginAccounts[0].BaseUrl); | |
return accountId; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment