Invoice e-mail
Save e-mail template
Creates an integrator e-mail template or overwrites an existing one; validates variables and HTML at save time.
/openapi/v2/emails/templatestoken, timestamp and sign signature headers, see Authentication.Templates belong to the integrator, not to a company: any registered company uses any template. Without templateId it creates; with templateId it replaces the whole template. Subject and body accept {{variables}} filled at send time with the invoice data; the list of names depends on tipoDocumento and is in the enumeration at the bottom of the page. How templates relate to sending is in Invoice e-mail.
Request body
templateId*required to overwrite | string | Template identifier |
tipoDocumento* | string | Document type |
idioma* | string | Template language |
nome* | string | Template name |
assunto* | string | Subject template |
corpoHtml* | string | Body template |
padrao | bool | Default template |
ativo | bool | Enabled |
* Required field
templateId | string | Template identifier |
tipoDocumento | string | Document type |
idioma | string | Template language |
nome | string | Template name |
assunto | string | Subject template |
corpoHtml | string | Body template |
padrao | bool | Default template |
ativo | bool | Enabled |
variaveisDisponiveis | array | Allowed variables |
criadoEm | string | Creation time |
atualizadoEm | string | Last update |
A template belongs to the integrator and applies to every company. There may be several per document type, for example one per language; the one with padrao = true is used when the send omits templateId. Saving already validates: a variable outside the list returns 10021003, HTML outside the list returns 10021004, and the message says which.
Minimal template
NF-e in Portuguese: subject with number and issuer, body with greeting, summary and PDF link. Without padrao and ativo: it is enabled and not the default.
{"tipoDocumento": "NFe","idioma": "pt","nome": "NF-e simples","assunto": "Nota fiscal {{numero}} - {{emitente.nome}}","corpoHtml": "<p>Olá {{cliente.nome}},</p><p>Segue a nota fiscal {{numero}} emitida por {{emitente.nome}} em {{dataEmissao}}, no valor de R$ {{valorTotal}}.</p><p><a href='{{linkPdf}}'>Baixar DANFE (PDF)</a></p>"}
tipoDocumento* | string | Document type |
idioma* | string | Template language |
nome* | string | Template name |
assunto* | string | Subject template |
corpoHtml* | string | Body template |
* Required field
Template with logo and buttons
NFS-e in Portuguese marked as default: header with an https image, a table with the NFS-e-only variables and two buttons pointing to {{linkPdf}} and {{linkXml}}. The image can only be a public https address; there is no upload.
{"tipoDocumento": "NFSe","idioma": "pt","nome": "NFS-e com logotipo","assunto": "Nota Fiscal de Serviço nº {{numero}} - {{emitente.nome}}","corpoHtml": "<div style='background:#f3f4f6;padding:24px 0;font-family:Arial,Helvetica,sans-serif;color:#1f2937'><div style='max-width:640px;margin:0 auto;background:#ffffff;border-radius:12px;overflow:hidden;border:1px solid #e5e7eb'><div style='padding:20px 28px;border-bottom:1px solid #e5e7eb'><img src='https://v2.tffiscal.com/logo.png' alt='TF Fiscal' width='160' style='display:block;height:auto;border:0'></div><div style='padding:24px 28px'><h2 style='margin:0 0 16px;color:#1a56db;font-size:20px'>Nota Fiscal de Serviço nº {{numero}}</h2><p>Olá <strong>{{cliente.nome}}</strong>,</p><p>Segue a nota fiscal de serviço emitida por <strong>{{emitente.nome}}</strong> (CNPJ {{emitente.cnpj}}) em {{dataEmissao}}.</p><table style='border-collapse:collapse;width:100%;font-size:14px'><tbody><tr><td style='padding:8px;border:1px solid #e5e7eb;background:#f9fafb;width:40%'>Número / Série</td><td style='padding:8px;border:1px solid #e5e7eb'>{{numero}} / {{serie}}</td></tr><tr><td style='padding:8px;border:1px solid #e5e7eb;background:#f9fafb'>Serviço</td><td style='padding:8px;border:1px solid #e5e7eb'>{{descricaoServico}}</td></tr><tr><td style='padding:8px;border:1px solid #e5e7eb;background:#f9fafb'>Valor total</td><td style='padding:8px;border:1px solid #e5e7eb'>R$ {{valorTotal}}</td></tr><tr><td style='padding:8px;border:1px solid #e5e7eb;background:#f9fafb'>ISS</td><td style='padding:8px;border:1px solid #e5e7eb'>R$ {{valorIss}}</td></tr><tr><td style='padding:8px;border:1px solid #e5e7eb;background:#f9fafb'>Município</td><td style='padding:8px;border:1px solid #e5e7eb'>{{municipio}}</td></tr><tr><td style='padding:8px;border:1px solid #e5e7eb;background:#f9fafb'>Chave de acesso</td><td style='padding:8px;border:1px solid #e5e7eb;font-family:monospace;font-size:12px'>{{chaveAcesso}}</td></tr></tbody></table><p style='margin-top:20px'><a href='{{linkPdf}}' style='display:inline-block;padding:10px 18px;background:#1a56db;color:#ffffff;text-decoration:none;border-radius:6px;font-weight:bold'>Baixar DANFSe (PDF)</a> <a href='{{linkXml}}' style='display:inline-block;padding:10px 18px;border:1px solid #1a56db;color:#1a56db;text-decoration:none;border-radius:6px;font-weight:bold'>Baixar XML</a></p></div><div style='padding:16px 28px;background:#f9fafb;color:#6b7280;font-size:12px;border-top:1px solid #e5e7eb'>E-mail automático enviado pela plataforma TF Fiscal. Em caso de dúvidas, responda a este e-mail.</div></div></div>","padrao": true}
tipoDocumento* | string | Document type |
idioma* | string | Template language |
nome* | string | Template name |
assunto* | string | Subject template |
corpoHtml* | string | Body template |
padrao | bool | Default template |
* Required field
Type-specific variables
CT-e in English using remetente.nome, destinatario.nome and valorFrete. Those names only exist for CTe; in an NFe template they would be refused with 10021003. With idioma = en, amounts come out as 1,234.56 and dates as yyyy-MM-dd HH:mm.
{"tipoDocumento": "CTe","idioma": "en","nome": "CT-e english","assunto": "Transport document {{numero}} from {{emitente.nome}}","corpoHtml": "<p>Hello {{cliente.nome}},</p><p>Transport document {{numero}} issued by {{emitente.nome}} on {{dataEmissao}}.</p><ul><li>Sender: {{remetente.nome}}</li><li>Recipient: {{destinatario.nome}}</li><li>Freight: R$ {{valorFrete}}</li></ul><p><a href='{{linkPdf}}'>Download DACTE (PDF)</a> | <a href='{{linkXml}}'>Download XML</a></p>"}
tipoDocumento* | string | Document type |
idioma* | string | Template language |
nome* | string | Template name |
assunto* | string | Subject template |
corpoHtml* | string | Body template |
* Required field
Overwrite and disable a template
With templateId, the body replaces the whole template: resend every field. An omitted optional field goes back to its default, so a default template overwritten without padrao = true stops being the default. Here it is also disabled with ativo = false; a disabled template is never the default.
{"templateId": "2103150000000000001","tipoDocumento": "NFe","idioma": "pt","nome": "NF-e simples (antigo)","assunto": "Nota fiscal {{numero}} - {{emitente.nome}}","corpoHtml": "<p>Olá {{cliente.nome}},</p><p>Segue a nota fiscal {{numero}} emitida por {{emitente.nome}} em {{dataEmissao}}, no valor de R$ {{valorTotal}}.</p><p><a href='{{linkPdf}}'>Baixar DANFE (PDF)</a></p>","ativo": false}
templateId* | string | Template identifier |
tipoDocumento* | string | Document type |
idioma* | string | Template language |
nome* | string | Template name |
assunto* | string | Subject template |
corpoHtml* | string | Body template |
ativo | bool | Enabled |
* Required field
Write {{nome}} in the subject or the body; the name starts with a letter and accepts letters, digits, underscore and dot, with optional spaces inside the braces. At save time each name is checked against the list of the document type (enumeration at the bottom of the page); an unknown name is refused with 10021003 instead of becoming empty text in the customer inbox. At send time, amounts and dates follow the template idioma: pt / es use 1.234,56 and dd/MM/yyyy HH:mm; en / zh use 1,234.56 and yyyy-MM-dd HH:mm; the time is São Paulo time. In the body the value is HTML-escaped; in the subject it is not. {{linkPdf}} and {{linkXml}} become platform download links, valid per the integrator setting (7 days by default).
The body is refused, not cleaned: anything outside the list returns 10021004 with its position, so the saved template is exactly what goes out in the e-mail.
- Tags:
p,div,span,br,hr,h1toh6,strong,b,em,i,u,s,ul,ol,li,blockquote,table,thead,tbody,tr,th,td,a,img. - Attributes:
style,href,src,alt,width,height,align,colspan,rowspan. No event attributes (on...). stylemust not containurl(,expression(,position:orbehavior:.hrefonly acceptshttps:,mailto:,{{linkPdf}}or{{linkXml}}.- Image
srconly accepts anhttpsaddress; there is no image upload, host the logo at a public address. - Maximum size 64 KB in UTF-8.
tipoDocumentoDocument type
| Values | Meaning |
|---|---|
| NFe | NF-e, goods invoice |
| NFSe | NFS-e, service invoice |
| CTe | CT-e, transport document |
| DCe | DC-e, content declaration |
idiomaTemplate language
The language sets the format of amounts and dates in the variables; the time is always São Paulo time.
| Values | Meaning |
|---|---|
| pt | Portuguese; amounts 1.234,56, dates dd/MM/yyyy HH:mm |
| en | English; amounts 1,234.56, dates yyyy-MM-dd HH:mm |
| zh | Chinese; amounts 1,234.56, dates yyyy-MM-dd HH:mm |
| es | Spanish; amounts 1.234,56, dates dd/MM/yyyy HH:mm |
corpoHtmlVariables common to the four types
Write {{nome}}; spaces inside the braces are accepted. Without a value the variable becomes empty text. In the body the value is HTML-escaped; in the subject it is not.
| Values | Meaning |
|---|---|
| numero | Document number |
| serie | Series |
| chaveAcesso | Access key, 44 or 50 digits |
| dataEmissao | Issue time, São Paulo time zone, formatted per language |
| valorTotal | Total amount, formatted per language: NF-e total, NFS-e service amount, CT-e total service value, DC-e declared value |
| emitente.nome | Issuer company name |
| emitente.cnpj | Issuer CNPJ |
| cliente.nome | Name of the invoice recipient: NF-e buyer, NFS-e and CT-e service taker, DC-e recipient |
| cliente.documento | Recipient document, CPF or CNPJ |
| linkPdf | PDF download link; validity per the integrator setting, 7 days by default |
| linkXml | Authorized XML download link; empty if the XML is not archived yet |
corpoHtmlNFSe-only variables
In another document type the variable is refused at save with 10021003.
| Values | Meaning |
|---|---|
| codigoVerificacao | NFS-e verification code |
| municipio | Issuer municipality name |
| descricaoServico | Service description |
| valorIss | ISS amount, formatted per language |
corpoHtmlCTe-only variables
In another document type the variable is refused at save with 10021003.
| Values | Meaning |
|---|---|
| remetente.nome | Cargo sender name |
| destinatario.nome | Cargo recipient name |
| valorFrete | Total freight value, formatted per language |
corpoHtmlDCe-only variables
In another document type the variable is refused at save with 10021003.
| Values | Meaning |
|---|---|
| marketplace.site | Marketplace site, from the issuer DC-e profile |
| Code | HTTP | |
|---|---|---|
| 10001001 | 400 | Field validation failed: required field blank, over the length limit, tipoDocumento or idioma outside the accepted values; one entry per field. |
| 10021001 | 404 | E-mail template not found: the templateId does not exist or does not belong to this integrator. |
| 10021003 | 400 | The template uses variables outside the allowed list; the message lists the names. Check tipoDocumento and the variable enumeration. |
| 10021004 | 400 | The template HTML contains forbidden content: tag, attribute, style, href or src outside the list, or body over 64 KB; the message points to each occurrence. |
