Template: Modifica

Update Template

Cambia nome, html, testo o oggetto di un template html. Ogni modifica salva una versione, così puoi tornare indietro: vengono conservate le ultime 10.

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

Richiede lo scope template:update sulla tua API key.

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

Invia solo ciò che cambia. text o subject come null o "" lo svuota.

I template Unlayer e Custom rispondono TEMPLATE_READ_ONLY: modificali nella dashboard.

Argomenti

  • template_idstringobbligatorio

    Un template html.

    es. "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93"

  • namestringfacoltativo

    Fino a 255 caratteri, senza HTML.

    es. "Welcome email v2"

  • htmlstringfacoltativo

    Il nuovo html, fino a 512 KB. Controllato come in Create Template.

  • textstring | nullfacoltativo

    La nuova versione in testo semplice.

  • subjectstring | nullfacoltativo

    Il nuovo oggetto predefinito.

    es. "Welcome aboard, {{first_name}}"

Avvio rapido

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/template',
  {
    commands: [
      {
        command: "update_template",
        args: {
          template_id: "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
          subject: "Welcome aboard, {{first_name}}"
        }
      }
    ]
  },
  { 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": "update_template",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 8,
      "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:31:08.447Z",
        "subject": "Welcome aboard, {{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.

Tenere i template nel tuo repo

  • Un'unica fonte di verità

    Tieni l'html nel tuo codice e chiama Update Template dal tuo deploy. Il team rivede i template come qualsiasi altra modifica.

  • Rollback sicuri

    Se un deploy rompe un template, Restore Template Version riporta l'ultimo buono con una sola chiamata.

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…

  • CMDTEMPLATE_NOT_FOUND

    Il template non è nel tuo account.

  • CMDTEMPLATE_READ_ONLY

    Un template Unlayer o Custom: modificalo nell'editor della dashboard. Tramite l'API cambiano solo i template html.

  • 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.