---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://docs.sendcorex.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.sendcorex.com/llms.txt"
---

Source: https://docs.sendcorex.com/it/api-reference/templates/routes/run-commands

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.

POST `https://g.sendcorex.com/v1/template`

Stessa 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

- `commands` object[] obbligatorio
Da 1 a 10 comandi, eseguiti in ordine. L'intero body può arrivare fino a 1 MB.
- `commands[].command` string obbligatorio
`list_templates`, `get_template`, `render_template`, `create_template`, `update_template`, `delete_template`, `list_template_versions` o `restore_template_version`.
- `commands[].args` object facoltativo
Gli argomenti del comando. Qualsiasi valore può essere un `$ref` al risultato di un comando precedente.
- `commands[].id` string facoltativo
Il 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

- `type`
Sempre `SUCCESS` quando la richiesta stessa è stata accettata.
- `results[].command`
Il comando che ha prodotto questo risultato.
- `results[].id`
L'`id` che hai inviato, o l'indice del comando.
- `results[].type`
`SUCCESS` o `ERROR`.
- `results[].took_ms`
Tempo impiegato dal comando nel server.
- `results[].data`
L'output del comando. Presente solo quando `type` è `SUCCESS`.
- `results[].code / message`
L'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.

- `Authorization`
Invia `Authorization: <api key>` o `Authorization: Bearer <api key>`.
- `template:read`
`list_templates`, `get_template`, `render_template` e `list_template_versions`.
- `template:create`
`create_template`.
- `template:update`
`update_template` e `restore_template_version`.
- `template:delete`
`delete_template`.
- `Token delle caselle`
Il token della webmail qui non funziona. Viene rifiutato con `WRONG_CREDENTIAL_TYPE`.
- `IP consentiti`
Se 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 / secondo`
Per IP + API key. Oltre, HTTP 429 con un header `Retry-After`.
- `15 in corso`
Al massimo 15 richieste elaborate contemporaneamente, per IP + API key.
- `Per comando, per account`
`create_template` 30/min · `update_template` 60/min · `restore_template_version` 20/min · `delete_template` 30/min. Oltre, quel comando risponde `RATE_LIMITED`.
- `Cache di lettura: 1,5 s`
La 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_JSON`
Il body non è {"commands":[...]} o supera 1 MB.
- 400`INVALID_ARGS`
La richiesta non ha comandi o ne ha più di 10.
- 401`MISSING_AUTH_HEADER`
Non è stato inviato nessun header Authorization.
- 401`INVALID_API_KEY`
La API key non esiste, è stata revocata o disattivata nella dashboard.
- 401`API_KEY_EXPIRED`
La 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_ALLOWED`
La richiesta proviene da un IP che non è tra gli IP consentiti della chiave.
- 403`ACCOUNT_BLOCKED`
L'account è bloccato.
- 403`MISSING_SCOPE`
La chiave non ha scope `template:*`, quindi nessun comando può essere eseguito.
- 429`RATE_LIMITED`
Più di 15 richieste/s o 15 in corso per la stessa IP + API key. Attendi i secondi indicati in Retry-After.
- 503`AUTH_UNAVAILABLE`
L'autenticazione è temporaneamente non disponibile. Riprova.
- CMD`UNKNOWN_COMMAND`
Il nome del comando non esiste.
- CMD`INTERNAL`
Errore del server. Il dettaglio viene scritto solo nel log del server.
