createDocFromTemplateAsync

Create document via Template

Overview

Parameters:

Return:

To create this document we will need:

  • set your apiToken;

  • build your signers;

  • build the document;

  • call the method;

How to use:

Save your apiToken:

const apiToken: string = "YOUR TOKEN";

Add your variables to a list of type DeParaTemplate:

const fromToTemplateName: DeParaTemplateBuilder = deParaTemplateBuilder()
        .de("{{FULL NAME}}") // the variable
        .para("Jhon Doe") // the value to replace
        .build();
        
const fromToTemplateSocialSecurty: DeParaTemplateBuilder = deParaTemplateBuilder()
        .de("{{Social Security Number}}")
        .para("9999999999")
        .build();
        
const fromToTemplateAdress: DeParaTemplateBuilder = deParaTemplateBuilder()
        .de("{{Full address}}")
        .para("999 N Main St")
        .build();
        
let fromToTemplates: DeParaTemplatesBuilder[] = [];

fromToTemplates.push(fromToTemplateName, fromToTemplateSocialSecurty, fromToTemplateAdress);

Build your document with DocFromTemplate class:

const docFromTemplate: DocFomTemplateBuilder = new DocFromTemplateBuilder()
        .withSandbox(false)
        .withPrimaryColor("#000000")
        .withSignerName("My Signer for Template")
        .withTemplateId("YOUR TEMPLATE ID")
        .withData(fromToTemplates)
        .build();

Finally, call the createDocFromTemplate method to get the DocAsyncResponse return or an error message:

async function exempleCreateDocFromTemplate() {
        try {
                docResponse: DocResponse = await new DocRequests(apiToken).createDocFromTemplateAsync(docFromTemplate);
                jsonDocResponse: string = new JsonConverter().docAsyncResponseToJson(docResponse);
                console.log(jsonDocResponse);
            } catch(Err) {
                console.log(Err);
            }
}

Example:

import { DeParaTemplateBuilder } from "sdk-node-typescript-zapsign/src/body/doc/builders/DeParaTemplateBuilder";
import DocRequests from "sdk-node-typescript-zapsign/src/docs/DocRequests";
import { JsonConverter } from "sdk-node-typescript-zapsign/src/services/JsonConverter";
import { DocFromTemplate } from "sdk-node-typescript-zapsign/src/body/doc/builders/DocFromTemplate";

const apiToken: string = "YOUR TOKEN";

const fromToTemplateName: DeParaTemplateBuilder = DeParaTemplateBuilder()
        .de("{{Full Name}}")
        .para("Jhon Doe")
        .build();
        
const fromToTemplateCpf: DeParaTemplateBuilder = DeParaTemplateBuilder()
        .de("{{Social Security Number}}")
        .para("9999999999")
        .build();
        
const fromToTemplateEndereco: DeParaTemplateBuilder = DeParaTemplateBuilder()
        .de("{{Full address}}")
        .para("999 N Main St")
        .build();
        
let fromToTemplates: DeParaTemplatesBuilder[] = [];

fromToTemplates.push(fromToTemplateName, fromToTemplateCpf, fromToTemplateEndereco);

const docFromTemplate: DocFomTemplateBuilder = new DocFromTemplateBuilder()
        .withSandbox(false)
        .withPrimaryColor("#000000")
        .withSignerName("My Signer for Template")
        .withTemplateId("YOUR TEMPLATE ID")
        .withData(fromToTemplates)
        .build();

async function exempleCreateDocFromTemplate() {
        try {
                docResponse: DocResponse = await new DocRequests(apiToken).createDocFromTemplate(docFromTemplate);
                jsonDocResponse: string = new JsonConverter().docAsyncResponseToJson(docResponse);
                console.log(jsonDocResponse);
            } catch(Err) {
                console.log(Err);
            }
}

Last updated