Template: Modifica

Create Template

Salva il tuo html come template: da MJML, React Email, il tuo designer o qualsiasi strumento. Compare nella dashboard accanto ai template dell'editor.

POSThttps://g.sendcorex.com/v1/templatecommand: create_template

Richiede lo scope template:create sulla tua API key.

Fino a 30 chiamate al minuto per account. Oltre, il comando risponde RATE_LIMITED.

L'html viene controllato al salvataggio, con le stesse regole dell'invio: lo scopri subito, non quando un'email viene rifiutata.

La prima versione viene salvata insieme. Vedi List Template Versions.

Argomenti

  • namestringobbligatorio

    Fino a 255 caratteri, senza HTML.

    es. "Welcome email"

  • htmlstringobbligatorio

    L'html completo, fino a 512 KB. Usa {{variables}} per ciò che cambia in ogni email.

    es. "<!doctype html><html><body style=\"font-family:Arial,sans-serif\"><h1>Welcome, {{first_name}}!</h1><p>Your {{plan}} plan is ready.</p><p><a href=\"https://acme.com/start\">Get started</a></p></body></html>"

  • textstringfacoltativo

    La versione in testo semplice.

    es. "Welcome, {{first_name}}! Your {{plan}} plan is ready. Get started: https://acme.com/start"

  • subjectstringfacoltativo

    Un oggetto predefinito. Può contenere variabili.

    es. "Welcome to Acme, {{first_name}}"

Avvio rapido

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/template',
  {
    commands: [
      {
        command: "create_template",
        args: {
          name: "Welcome email",
          subject: "Welcome to Acme, {{first_name}}",
          html: "<!doctype html><html><body style=\"font-family:Arial,sans-serif\"><h1>Welcome, {{first_name}}!</h1><p>Your {{plan}} plan is ready.</p><p><a href=\"https://acme.com/start\">Get started</a></p></body></html>",
          text: "Welcome, {{first_name}}! Your {{plan}} plan is ready. Get started: https://acme.com/start"
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_API_KEY } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);

Risposta

{
  "type": "SUCCESS",
  "results": [
    {
      "command": "create_template",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 9,
      "data": {
        "template_id": "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
        "type": "html",
        "name": "Welcome email",
        "reference": "K7Q2M9XR4T",
        "preview": null,
        "has_html": true,
        "html_size": 248,
        "editable": true,
        "created_at": "2026-10-21T04:02:11.310Z",
        "updated_at": "2026-10-21T04:15:40.902Z",
        "subject": "Welcome to Acme, {{first_name}}",
        "html": "<!doctype html><html><body style=\"font-family:Arial,sans-serif\"><h1>Welcome, {{first_name}}!</h1><p>Your {{plan}} plan is ready.</p><p><a href=\"https://acme.com/start\">Get started</a></p></body></html>",
        "text": "Welcome, {{first_name}}! Your {{plan}} plan is ready. Get started: https://acme.com/start"
      }
    }
  ]
}

Campi della risposta

  • template_id

    L'id del template: html_<uuid>, unlayer_<number> o custom_<uuid>. Usalo in tutti gli altri comandi.

  • type

    html (il tuo, inviato tramite l'API), unlayer (creato nell'editor drag-and-drop) o custom (creato nell'editor di Sendcorex).

  • name

    Il nome che gli hai dato.

  • reference

    Un codice breve che identifica il template anche nella dashboard.

  • preview

    Un'immagine del template, per i template dell'editor. null per i template html e per i template dell'editor non ancora salvati.

  • has_html

    false per un template dell'editor creato ma mai salvato. Non può ancora essere renderizzato né inviato.

  • html_size

    Dimensione dell'html, in byte.

  • editable

    true per i template html: qui puoi aggiornarli, ripristinarli ed eliminarli. I template dell'editor sono di sola lettura tramite l'API.

  • created_at / updated_at

    ISO 8601, UTC.

  • subject

    L'oggetto predefinito, o null. Può contenere variabili.

  • html

    L'html. null per un template dell'editor mai salvato.

  • text

    La versione in testo semplice, o null. Inviane una: alcuni client e filtri preferiscono le email che ce l'hanno.

Variabili

  • Sintassi

    Scrivi {{name}} ovunque nel subject, nell'html o nel text. Gli spazi dentro le graffe vanno bene: {{ name }}. I nomi usano lettere, cifre, _, . e -.

  • Nell'html

    I valori vengono codificati per HTML: un valore con < o & non può mai rompere il layout o inserire markup.

  • Nel subject e nel text

    I valori vengono inseriti così come sono.

  • Valori mancanti

    Una variabile che non hai inviato resta {{name}} e viene elencata in missing_variables. Controllala prima di inviare.

Cosa può contenere l'html

  • Consentito

    Tutto ciò che i client email visualizzano: tabelle, stili inline, blocchi <style>, immagini tramite URL, link.

  • Rifiutato

    <script>, <iframe>, <form>, <input>, <button>, <embed>, <object>, <svg> inline, <base>, handler on*= e URL javascript:. Usa un <a> con stile invece di un pulsante.

  • Immagini

    Ospitale e collegale. Le immagini base64 incorporate appesantiscono l'html e spesso vengono tagliate da Gmail oltre ~100 KB.

Errori

Gli errori a livello HTTP restituiscono type, code e message. Gli errori marcati CMD tornano dentro il risultato del comando, con HTTP 200.

  • 401INVALID_API_KEY

    La API key non esiste, è stata revocata o disattivata nella dashboard.

  • 429RATE_LIMITED

    Più di 15 richieste/s o 15 in corso per la stessa IP + API key. Attendi i secondi indicati in Retry-After.

  • CMDMISSING_SCOPE

    La API key non ha lo scope richiesto da questo comando.

  • CMDINVALID_ARGS

    Un argomento non è valido: un `template_id` malformato, `name` o `html` mancante, un nome oltre 255 caratteri, un `version_at` non in RFC 3339…

  • CMDUNSAFE_HTML

    L'html contiene qualcosa che un'email non può contenere: `<script>`, `<iframe>`, form, handler `on*=`, link `javascript:`… Il messaggio dice esattamente cosa rimuovere.

  • CMDTEMPLATE_TOO_LARGE

    L'html supera 512 KB. Ospita le immagini e collegale invece di incorporarle.

  • CMDRATE_LIMITED

    Il tuo account ha chiamato questo comando troppe volte nell'ultimo minuto. Attendi un minuto.

  • CMDINTERNAL

    Errore del server. Il dettaglio viene scritto solo nel log del server.