Templates from Markdown or HTML by API
Beta
This feature is in beta. For now it is available only to some users. We will release it gradually to more accounts once testing ends. If you want to use it, ask your JAAK contact for access.
Description
A text with tags can become a signature template. There are two routes:
| Route | Purpose |
|---|---|
POST /api/v1/templates/document-jobs | Document engine. Turns the text into a PDF and returns the area of each field. It does not create a template. Use it to check the result before you save it. |
POST /api/v1/templates/source | Create template. Saves the text as a tagged template. Returns the template ID. |
Both routes accept the same kind of text:
source_type | Text format |
|---|---|
markdown | Markdown. |
editor | HTML. This is the format of the platform editor. |
The request body cannot be larger than 6 MiB. The content field cannot be larger than 5 MB.
For the tags ({{key}}, {{key|fecha}} and {{firma:ROLE}}), see Templates with tags (mail merge).
Use the company token in the Authorization: Bearer <token> header.
A. Document engine
The engine works in two steps: it receives a job and then you read the job result.
1. Send a job
POST /api/v1/templates/document-jobs
| Field | Required | Description |
|---|---|---|
name | Yes | Job name. It cannot be empty. |
source_type | Yes | markdown or editor. |
content | Yes | The source text. It cannot be empty. |
curl -X POST https://<host-api>/api/v1/templates/document-jobs \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Demo contract",
"source_type": "markdown",
"content": "# Demo contract\n\nClient: {{cliente.nombre}}\n\n{{firma:EL CLIENTE}}"
}'
202 response:
{ "job_id": "job_demo_001" }
2. Read the job
GET /api/v1/templates/document-jobs/{job_id}
curl https://<host-api>/api/v1/templates/document-jobs/job_demo_001 \
-H "Authorization: Bearer $TOKEN"
200 response:
| Field | Description |
|---|---|
job_id | Job ID. |
status | queued, running, done or failed. |
reason | Only in failed. Text in Spanish that explains the failure. |
reason_code | Only in failed. Stable code. Example: marker_not_found. |
fields | Only in done. One entry per key, in the order of first appearance. |
warnings | Non-fatal notices in Spanish. Example: the text has no tags. |
pdf | Only in done. The rendered PDF, in base64. |
Each fields entry has key and areas. Each area is a rectangle:
{
"job_id": "job_demo_001",
"status": "done",
"fields": [
{
"key": "cliente.nombre",
"areas": [{ "x": 72.0, "y": 180.0, "w": 240.0, "h": 18.0, "page": 1 }]
}
],
"warnings": [],
"pdf": "JVBERi0xLjQK..."
}
- The coordinates are in PDF points.
- The origin (0, 0) is at the top-left corner.
pagestarts at 1.
Read the job until status is done or failed. A failed job has no pdf.
B. Create a template from the text
POST /api/v1/templates/source
The body is JSON. The content field is the plain Markdown or HTML text. Do not encode it in base64.
| Field | Required | Description |
|---|---|---|
name | Yes | Template name. |
source_type | Yes | markdown or editor. |
content | Yes | The source text with tags. |
folder_name | No | Folder where the template is stored. |
external_id | No | Identifier from your system. |
signature_type | No | Signature type of the template. See Signature types. |
role_signature_types | No | Map from role to signature type. Each value is a fixed type, at_send or empty. See Signature type per signer. |
data_keys | No | Changes to the label, type or required flag of the keys. |
initials | No | Initials rule: enabled, roles and skip_pages. |
Each data_keys item has:
| Field | Values |
|---|---|
key | A key that exists in the text. |
label | Visible label. |
type | text, multiline or date. |
required | true or false. |
data_keys entries whose key is not in the text are rejected.
curl -X POST https://<host-api>/api/v1/templates/source \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Demo service contract",
"source_type": "markdown",
"content": "# Service contract\n\nBetween {{empresa.razon_social}} and {{cliente.nombre}}.\n\n{{firma:EL PRESTADOR}}\n\n{{firma:EL CLIENTE}}",
"folder_name": "Demo contracts",
"signature_type": "simple",
"role_signature_types": {
"EL PRESTADOR": "efirma_sat",
"EL CLIENTE": "at_send"
},
"data_keys": [
{ "key": "empresa.razon_social", "label": "Company name", "type": "text", "required": true }
]
}'
201 response: the template object, with id, slug and name. Save the id to send the template.
Errors
| Response | Route | Cause |
|---|---|---|
400 name es obligatorio | Job | name is missing. |
400 source_type debe ser markdown o editor | Job | source_type has another value. |
400 content es obligatorio | Job | content is empty. |
400 solicitud inválida | Job | The engine rejects the request. |
400 cuerpo de la solicitud inválido | Template | The JSON body is not valid. |
404 trabajo no encontrado | Job | The job_id does not exist. |
413 | Both | The body is larger than 6 MiB, or the content is larger than 5 MB. |
503 servicio de generación de documentos no disponible | Job | The engine does not respond. Retry. |
500 error interno del servidor | Job | Unexpected error. Contact JAAK. |
Other template creation failures return the HTTP code of the template service error, with its text.
The error messages in the table come from the API and are in Spanish.