Skip to main content
Solved

I am getting the error "errorCode":"TEMPLATE_NOT_PROVIDED","message":"Template was not provided."}"


Forum|alt.badge.img+1

I'm working with a template and I want to add an attachment to it, but this error is returned. Here's the code:

  let document1;

 

  try {

    let response = await fetch(anexoFuncionario);

 

    if (!response.ok) throw new Error('Erro ao baixar o arquivo');

    let contentType = response.headers.get('content-type');

    let fileExtension = 'pdf';

 

    if (contentType.includes('image/png')) fileExtension = 'png';

    else if (contentType.includes('image/jpeg')) fileExtension = 'jpg';

 

    let arrayBuffer = await response.arrayBuffer();

    let base64FileContent = Buffer.from(arrayBuffer).toString('base64');

 

    document1 = new docusign.Document();

    document1.documentBase64 = base64FileContent;

    document1.name = 'Anexo do Funcionário';

    document1.fileExtension = fileExtension;

    document1.documentId = '2';

 

  } catch (error) {

    console.error('Erro ao processar o anexo:', error);

    return res.status(500).send('Erro ao processar o anexo');

  }

 

  let signerFunc1 = docusign.TemplateRole.constructFromObject({

    email: emailFuncionario,

    name: nameFuncionario,

    clientUserId: process.env.CLIENT_USER_ID_FUNCIONARIO,

    roleName: 'funcionario',

    tabs: {

      textTabs: [

        { documentId: '1', pageNumber: '1', tabLabel: 'Nome', value: nameFuncionario },

        { documentId: '1', pageNumber: '1', tabLabel: 'setor', value: setor },

     ],

    },

  });

 

  signerFunc1.recipientId = '1';

  let compositeTemplate1 = new docusign.CompositeTemplate();

 

  compositeTemplate1.compositeTemplateId = "1";

 

  let serverTemplate = new docusign.ServerTemplate();

  serverTemplate.sequence = "1";

  serverTemplate.templateId = process.env.TEMPLATE_ID;

 

  compositeTemplate1.serverTemplates = [serverTemplate];

 

  let inlineTemplate = new docusign.InlineTemplate();

  inlineTemplate.sequence = "1";

 

  let recipients = new docusign.Recipients();

  recipients.signers = [signerFunc1];

  inlineTemplate.recipients = recipients;

 

  compositeTemplate1.inlineTemplates = [inlineTemplate];

 

  let compositeTemplate2 = new docusign.CompositeTemplate();

  compositeTemplate2.compositeTemplateId = "2";

  compositeTemplate2.document = document1;

 

  let compositeTemplates = [compositeTemplate1, compositeTemplate2];

  let env = new docusign.EnvelopeDefinition();

  env.templateId = process.env.TEMPLATE_ID;

  env.status = "sent";

  env.compositeTemplates = compositeTemplates;


try {

let results = await envelopesApi.createEnvelope(process.env.ACCOUNT_ID, { envelopeDefinition: env });

    console.log('Envelope criado:', results.envelopeId);

    res.json({ envelopeId: results.envelopeId });

  } catch (error) {

    if (error.response) {

      console.error('Erro ao criar envelope:', JSON.stringify(error.response.body, null, 2));

    } else {

      console.error('Erro ao criar envelope:', error);

    }

    res.status(500).send('Erro ao criar envelope');

  }

});
 

Note: the template ID is correct.

Best answer by JohnSantos

@ribeiroanamrb 

When using composite templates, you generally do not also set envelopeDefinition.templateId at the top level. In other words, you either use the top-level templateId or you define your templates through compositeTemplates (via ServerTemplate, etc.), but not both.

Use a single template via the top-level templateId and templateRoles, OR
Use multiple templates / inline docs via compositeTemplates (defining ServerTemplate and InlineTemplate objects).


When you mix them, you can get the "TEMPLATE_NOT_PROVIDED" or related errors.

View Original
Is this content helpful?

2 replies

JohnSantos
Valued Contributor
Forum|alt.badge.img+18
  • Valued Contributor
  • 968 replies
  • Answer
  • March 7, 2025

@ribeiroanamrb 

When using composite templates, you generally do not also set envelopeDefinition.templateId at the top level. In other words, you either use the top-level templateId or you define your templates through compositeTemplates (via ServerTemplate, etc.), but not both.

Use a single template via the top-level templateId and templateRoles, OR
Use multiple templates / inline docs via compositeTemplates (defining ServerTemplate and InlineTemplate objects).


When you mix them, you can get the "TEMPLATE_NOT_PROVIDED" or related errors.


Forum|alt.badge.img+1
JohnSantos wrote:

@ribeiroanamrb 

When using composite templates, you generally do not also set envelopeDefinition.templateId at the top level. In other words, you either use the top-level templateId or you define your templates through compositeTemplates (via ServerTemplate, etc.), but not both.

Use a single template via the top-level templateId and templateRoles, OR
Use multiple templates / inline docs via compositeTemplates (defining ServerTemplate and InlineTemplate objects).


When you mix them, you can get the "TEMPLATE_NOT_PROVIDED" or related errors.

Thank you very much, it worked!