Template: Route
Run Commands
L'unico punto di accesso per i template. Invia da 1 a 10 comandi in una richiesta e ricevi un risultato per comando.
https://g.sendcorex.com/v1/templateStessa busta di Domains, Senders e Contacts. Le pagine sotto questa documentano ogni comando.
Gli errori sono riportati per comando. Un comando che fallisce non blocca gli altri e lo stato HTTP resta 200.
Parametri del body
commandsobject[]obbligatorioDa 1 a 10 comandi, eseguiti in ordine. L'intero body può arrivare fino a 1 MB.
commands[].commandstringobbligatoriolist_templates,get_template,render_template,create_template,update_template,delete_template,list_template_versionsorestore_template_version.commands[].argsobjectfacoltativoGli argomenti del comando. Qualsiasi valore può essere un
$refal risultato di un comando precedente.commands[].idstringfacoltativoIl tuo identificatore per il risultato. Predefinito l'indice (
"0","1"…). Obbligatorio se vuoi usare$ref.
Avvio rapido
import axios from 'axios';
const response = await axios.post(
'https://g.sendcorex.com/v1/template',
{
commands: [
{
command: "list_templates",
id: "all"
},
{
command: "render_template",
id: "preview",
args: {
template_id: "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
variables: {
first_name: "Ana",
plan: "Pro"
}
}
}
]
},
{ headers: { Authorization: process.env.SENDCOREX_API_KEY } },
);
for (const result of response.data.results) {
if (result.type !== 'SUCCESS') console.error(result.id, result.code, result.message);
else console.log(result.id, result.data);
}Risposta
{
"type": "SUCCESS",
"results": [
{
"command": "list_templates",
"id": "all",
"type": "SUCCESS",
"took_ms": 6,
"data": {
"templates": [
{
"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"
},
{
"template_id": "unlayer_1284",
"type": "unlayer",
"name": "October newsletter",
"reference": "B3VN8QK1ZT",
"preview": "https://res.cloudinary.com/dmg04ffuy/image/upload/v1760000000/previews/oct_newsletter.png",
"has_html": true,
"html_size": 48211,
"editable": false,
"created_at": "2026-10-01T09:12:00.000Z",
"updated_at": "2026-10-18T16:40:22.118Z"
}
]
}
},
{
"command": "render_template",
"id": "preview",
"type": "SUCCESS",
"took_ms": 3,
"data": {
"template_id": "html_5f2c8a10-3d4e-4b6f-9a71-2c8e0d4b7a93",
"subject": "Welcome to Acme, Ana",
"html": "<!doctype html><html><body style=\"font-family:Arial,sans-serif\"><h1>Welcome, Ana!</h1><p>Your Pro plan is ready.</p><p><a href=\"https://acme.com/start\">Get started</a></p></body></html>",
"text": "Welcome, Ana! Your Pro plan is ready. Get started: https://acme.com/start",
"missing_variables": []
}
}
]
}Campi della risposta
typeSempre
SUCCESSquando la richiesta stessa è stata accettata.results[].commandIl comando che ha prodotto questo risultato.
results[].idL'
idche hai inviato, o l'indice del comando.results[].typeSUCCESSoERROR.results[].took_msTempo impiegato dal comando nel server.
results[].dataL'output del comando. Presente solo quando
typeèSUCCESS.results[].code / messageL'errore. Presente solo quando
typeèERROR.
Autenticazione
Usa la API key che crei nella dashboard, in Developers → API Keys, con gli scope richiesti dai comandi.
AuthorizationInvia
Authorization: <api key>oAuthorization: Bearer <api key>.template:readlist_templates,get_template,render_templateelist_template_versions.template:createcreate_template.template:updateupdate_templateerestore_template_version.template:deletedelete_template.Token delle caselleIl token della webmail qui non funziona. Viene rifiutato con
WRONG_CREDENTIAL_TYPE.IP consentitiSe la chiave ha una allowlist di IP, le richieste da altri IP ricevono
403 IP_NOT_ALLOWED.
Concatenare con $ref
Crea un template e renderizzalo nella stessa richiesta per controllare il risultato.
create_template → render_template
{
"commands": [
{
"command": "create_template",
"id": "new",
"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>"
}
},
{
"command": "render_template",
"args": {
"template_id": {
"$ref": "new",
"path": "template_id"
},
"variables": {
"first_name": "Ana",
"plan": "Pro"
}
}
}
]
}Rate limit e cache
15 richieste / secondoPer IP + API key. Oltre, HTTP 429 con un header
Retry-After.15 in corsoAl massimo 15 richieste elaborate contemporaneamente, per IP + API key.
Per comando, per accountcreate_template30/min ·update_template60/min ·restore_template_version20/min ·delete_template30/min. Oltre, quel comando rispondeRATE_LIMITED.Cache di lettura: 1,5 sLa stessa lettura entro 1,5 secondi restituisce lo stesso risultato. Qualsiasi scrittura sulla route la azzera.
Errori
Gli errori a livello HTTP restituiscono type, code e message. Gli errori marcati CMD tornano dentro il risultato del comando, con HTTP 200.
- 400
INVALID_JSONIl body non è {"commands":[...]} o supera 1 MB.
- 400
INVALID_ARGSLa richiesta non ha comandi o ne ha più di 10.
- 401
MISSING_AUTH_HEADERNon è stato inviato nessun header Authorization.
- 401
INVALID_API_KEYLa API key non esiste, è stata revocata o disattivata nella dashboard.
- 401
API_KEY_EXPIREDLa API key ha superato la data di scadenza impostata nella dashboard.
- 401
WRONG_CREDENTIAL_TYPEÈ stato inviato un token di casella. La Templates API richiede una API key della dashboard.
- 403
IP_NOT_ALLOWEDLa richiesta proviene da un IP che non è tra gli IP consentiti della chiave.
- 403
ACCOUNT_BLOCKEDL'account è bloccato.
- 403
MISSING_SCOPELa chiave non ha scope `template:*`, quindi nessun comando può essere eseguito.
- 429
RATE_LIMITEDPiù di 15 richieste/s o 15 in corso per la stessa IP + API key. Attendi i secondi indicati in Retry-After.
- 503
AUTH_UNAVAILABLEL'autenticazione è temporaneamente non disponibile. Riprova.
- CMD
UNKNOWN_COMMANDIl nome del comando non esiste.
- CMD
INTERNALErrore del server. Il dettaglio viene scritto solo nel log del server.