Created
June 6, 2017 17:29
-
-
Save codingdawg/9510268855eb5705ba79ea38fb9081a7 to your computer and use it in GitHub Desktop.
Create an envelope using Composite template.
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 DocuSignRecipe | |
{ | |
public class TestCompositeTemplates : DocuSignApiBase | |
{ | |
public void CreateEnvelopeFromCompositeTemplate() | |
{ | |
string accountId = Init(); | |
var envDef = new EnvelopeDefinition() | |
{ | |
EmailSubject = "Envelope with multiple documents", | |
Status = "sent", | |
CompositeTemplates = new List<CompositeTemplate>() | |
}; | |
string serverTemplateId = "";//Add your Server TemplateId here. | |
for (int docNumber = 1; docNumber <= 3; docNumber++) | |
{ | |
envDef.CompositeTemplates.Add(new CompositeTemplate() | |
{ | |
ServerTemplates = new List<ServerTemplate>() | |
{ | |
new ServerTemplate() | |
{ | |
TemplateId = serverTemplateId, | |
Sequence = docNumber.ToString() | |
} | |
}, | |
InlineTemplates = new List<InlineTemplate>() | |
{ | |
new InlineTemplate() | |
{ | |
Sequence = docNumber.ToString(), | |
Recipients = new Recipients() | |
{ | |
Signers = new List<Signer>() | |
{ | |
new Signer() | |
{ | |
Email = "Janedoe@acme.com", | |
Name = "Jane Doe", | |
RecipientId = "1", | |
RoleName = "Signer1", | |
Tabs = new Tabs() | |
{ | |
TextTabs = new List<Text>() | |
{ | |
new Text() | |
{ | |
DocumentId = docNumber.ToString(), | |
PageNumber = "1", | |
XPosition = "100", | |
YPosition = "100", | |
Width = 120, | |
Value = "Some Tab Value " + docNumber.ToString() | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}); | |
} | |
EnvelopesApi envelopesApi = new EnvelopesApi(); | |
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef); | |
Console.WriteLine(envelopeSummary); | |
} | |
} | |
public class DocuSignApiBase | |
{ | |
protected const string _username = "";//Add your UserName here | |
protected const string _integratorKey = ""; //Add your integrator key here. | |
protected const string _password = ""; //Add your account password here. | |
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