I am unable to figure out how to send multiple populated DocuSign templates within an envelope using the DocuSign C# SDK. I am able to populate and send a single template within an envelope but am unable to do so with multiple templates.
This is a snippet of the code I use that successfully populates and sends the template:
var rolesList = new List<TemplateRole>();
var tRole = new TemplateRole
{
Tabs = new Tabs(),
RoleName = "rolename"
};
tRole.Name = "joe smith";
tRole.Email = "email-address";
var tabData = new List<Text>();
// Populate the tabData
tRole.Tabs.TextTabs = tabData;
rolesList.Add(tRole);
var envDef = new EnvelopeDefinition
{
EmailSubject = "Pleae sign this",
TemplateRoles = rolesList,
TemplateId = "first template id",
Status = "sent",
};
var envelopesApi = new EnvelopesApi();
await envelopesApi.CreateEnvelopeAsync("accountId", envDef);
For multiple templates, I assume I needed to use a CompositeTemplate so I tried this code:
var envDef = new EnvelopeDefinition
{
EmailSubject = subject,
TemplateRoles = roles,
Status = send? "sent" : "created",
};
var compositeTemplate = new CompositeTemplate()
{
ServerTemplates = new List<ServerTemplate>(),
CompositeTemplateId = Guid.NewGuid().ToString(),
};
envDef.CompositeTemplates = new List<CompositeTemplate>();
envDef.CompositeTemplates.Add(compositeTemplate);
ServerTemplate first = new ServerTemplate()
{
TemplateId = "first template id",
Sequence = "1"
};
ServerTemplate second = new ServerTemplate()
{
TemplateId = "second template id",
Sequence = "2",
};
compositeTemplate.ServerTemplates.Add(first);
compositeTemplate.ServerTemplates.Add(second);
var envelopesApi = new EnvelopesApi();
await envelopesApi.CreateEnvelopeAsync("accountId", envDef);
However, with this code the CreateEnvelopeAsync call throws the following Exception: DocuSign.eSign.Client.ApiException: Error calling CreateEnvelope: { "errorCode": "ENVELOPE_IS_INCOMPLETE", "message": "The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line." }
I'm obviously not configuring the CompositeTemplate correctly (most likely not populating the Documents) but I can't seem to find an example on how to correctly populate it.