I’m trying to generate a document with parameterized where i’m creating a template when it doesn’t already exist, generate the envelope, and update the fields.
The fields in the document are being set as {{FieldName}} as suggested by documentation, but the GetEnvelopeDocGenFormFields() for the envelope is returning no fields and any attempt to use the update throws an error.
i’ve added a simple version of my code bellow.
How is the sender field parameterization supposed work?
public async Task TestCode()
{
var fileName = "test_document";
string docBase64;
using (FileStream fs = new FileStream($"E:\\{fileName}.docx", FileMode.Open, FileAccess.Read))
{
using (var ms = new MemoryStream())
{
fs.CopyTo(ms);
var bytes = ms.ToArray();
docBase64 = Convert.ToBase64String(bytes);
}
}
// Add Template
var template = await templatesApi.CreateTemplateAsync(accountId, new EnvelopeTemplate()
{
Name = "Test Template",
Description = "Test Template Description",
Shared = "false",
Recipients = new() { Signers = [new() { RoleName = "signer", RecipientId = "1" }] },
Status = "created",
Documents = [
new Document()
{
DocumentBase64 = docBase64,
Name = fileName,
FileExtension = "docx",
DocumentId = $"1",
DocGenFormFields = [
new() { Name = "FieldOne", Label = "FieldOne", Value = "ABC" },
new() { Name = "FieldTwo", Label = "FieldTwo", Value = "123" },
new() { Name = "FieldThree", Label = "FieldThree", Value = "Xyz" }]
}
]
});
// Create Envelople
var envelope = await envelopesApi.CreateEnvelopeAsync(accountId, new EnvelopeDefinition()
{
TemplateId = template.TemplateId,
Status = "created",
TemplateRoles = [new() { RoleName = "signer", Name = "Name", Email = "my.email@server.com", ClientUserId = "client1" }],
EmailSubject = "Test Envelope"
});
// Get Fields - fieldResponse.DocGenFormFields is NULL
var fieldResponse = await envelopesApi.GetEnvelopeDocGenFormFieldsAsync(accountId, envelope.EnvelopeId);
// Set Fields - Throws Exception {"errorCode":"INVALID_REQUEST_PARAMETER","message":"The request contained at least one invalid parameter. Value for 'documentId' is invalid."}
var fieldUpdateResponse = await envelopesApi.UpdateEnvelopeDocGenFormFieldsAsync(accountId, envelope.EnvelopeId, new DocGenFormFieldRequest()
{
DocGenFormFields = [
new DocGenFormFields()
{
DocumentId = "1",
DocGenFormFieldList = [
new() { Name = "FieldOne", Value = "DEF" },
new() { Name = "FieldTwo", Value = "456" },
new() { Name = "FieldThree", Value = "Xyz" }
]
}]
});
var updateSummary = await envelopesApi.UpdateAsync(accountId, envelope.EnvelopeId, new Envelope() { Status = "sent" });
}