Skip to main content

REST API User Email Templates

Creating and retrieving custom email templates in the REST API

Written by Petr Pech

Through the REST API — just like through the web interface — you can create and read email templates for sending documents and for payroll updates. Templates are stored in the sablona-mail record.

⚠️ This record is available only for the Premium license.


Reading a template

You can retrieve a template with a standard query on the record; you can also use detail levels:

GET https://demo.flexibee.eu/c/demo/sablona-mail/{id}.json?detail=full


Creating a template

To create a template, send XML or JSON to the record's address:

PUT https://demo.flexibee.eu/c/demo/sablona-mail.xml

Property

Required

Meaning

kod

yes

Template code. Must be unique — otherwise the import will fail with the error ciselnikDuplicitniZkratka.

nazev

yes

Template name.

textSablona

yes

The template text itself. Without it, the import will fail with the error validace.notNull.

beanKeys

yes

Usage locations — determines which documents the template is offered for, for example cz.winstrom.vo.dok.DoklFak$$FAV for issued invoices. An empty value will result in the error beanKeyEmpty.

subject

no

Email subject.

defaultFrom

no

Sender.

popis, poznam

no

Description and note.

nazevA, nazevB, nazevC

no

Name in other languages (SK, EN, RO).

ℹ️ To update an existing template, identify it using the <id>code:ZKRATKA</id> element. If you instead send only the kod property again, ABRA Flexi will attempt to create a new record and will encounter a duplicate code.


Attaching a template to a document type

To attach a template to a document type — here specifically to the issued invoice type — send XML like the following to the relevant record. The sablonaMail element specifies the template identifier that you want to assign:

<?xml version="1.0"?>
<winstrom version="1.0">
<typ-faktury-vydane>
<kod>{kod}</kod>
<nazev>FAV se šablonou</nazev>
<modul>FAV</modul>
<radaPrijem>code:FAKTURA-STANDARD</radaPrijem>
<typDoklK>typDokladu.faktura</typDoklK>
<sablonaMail>{identifikátor šablony}</sablonaMail>
<poznam>Šablona pro faktury vydané</poznam>
</typ-faktury-vydane>
</winstrom>


Template example and Freemarker variables

The FreeMarker templating system is used. The following variables can be used in templates:

Variable

Value

${application}

Application name.

${generatedBy}

Localized phrase "Generated by the accounting system".

${user}

The user object, which can be worked with further — for example ${user.mobil}.

${company}

Company settings — for example ${company.dic}.

${uzivatelJmeno}

First name of the logged-in user.

${uzivatelPrijmeni}

Last name of the logged-in user.

${titulJmenoPrijmeni}

Full name including any titles earned.

${nazevFirmy}

Company name.

${object}

Generic access to the passed object.

${doklad}

The document to be sent — for example ${doklad.kod} or ${doklad.sumCelkem}.

To find out which properties a particular document has available, check the property overview of the given record:

GET https://demo.flexibee.eu/c/demo/faktura-vydana/properties.json

💡 When accessing object properties, an exclamation mark is added at the end of the expression — ${doklad.firma!} — as a check for empty values. Without it, the template will fail on unfilled properties.

⚠️ To preserve paragraphs, use the HTML element <p>. Without it, the text will be merged into a single paragraph.


Example of using these variables in a template

Dobrý den, zasílám Vám doklad ${doklad}, jehož interní číslo je ${doklad.kod}. Jmenuji se ${uzivatelJmeno} ${uzivatelPrijmeni}, včetně mého titulu ${titulJmenoPrijmeni}, pracuji pro ${nazevFirmy}. Mé telefonní číslo je ${user.mobil}, DIČ firmy je ${company.dic}.
Dobrý den, uživatel ${user} Vám zasílá ${doklad.nazev}. S pozdravem ${titulJmenoPrijmeni}, zasláno z aplikace ${application}.
Dobrý den, společnost ${nazevFirmy} Vám fakturuje ${doklad.sumCelkem} za své služby. S pozdravem ${titulJmenoPrijmeni}, zasláno z aplikace ${application}.


Validation of the template when saving

Before saving a template, the program checks whether it contains any disallowed expressions — it directly attempts to compile and evaluate the template. A non-compliant template will not be saved, and the error will be returned for the textSablona property:

What the template contains

How ABRA Flexi responds

An unclosed or otherwise incorrect FreeMarker expression

Rejects with the message freemarker.core.ParseException.

A property the object does not have — for example ${object.class}

Rejects with the message No such bean property and a template stack trace.

Creating class instances using the ?new() construct

Rejects with a message stating that the given class is not allowed.


Related

Did this answer your question?