---
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/pl/api-reference/templates/routes/run-commands

Szablony: Trasy

# Run Commands

Jedyny punkt wejścia do szablonów. Wyślij od 1 do 10 poleceń w jednym żądaniu i dostań jeden wynik na polecenie.

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

Ta sama koperta co w Domains, Senders i Contacts. Strony poniżej opisują każde polecenie.

Błędy są raportowane dla każdego polecenia. Nieudane polecenie nie zatrzymuje pozostałych, a status HTTP pozostaje `200`.

## Parametry body

- `commands` object[] wymagane
Od 1 do 10 poleceń, wykonywanych po kolei. Całe body może mieć do 1 MB.
- `commands[].command` string wymagane
`list_templates`, `get_template`, `render_template`, `create_template`, `update_template`, `delete_template`, `list_template_versions` lub `restore_template_version`.
- `commands[].args` object opcjonalne
Argumenty polecenia. Każda wartość może być `$ref` do wyniku wcześniejszego polecenia.
- `commands[].id` string opcjonalne
Twój identyfikator wyniku. Domyślnie indeks (`"0"`, `"1"`…). Wymagany, jeśli chcesz używać `$ref`.

## Szybki start

```
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);
}
```

## Odpowiedź

```
{
  "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": []
      }
    }
  ]
}
```

### Pola odpowiedzi

- `type`
Zawsze `SUCCESS`, gdy samo zapytanie zostało przyjęte.
- `results[].command`
Polecenie, które dało ten wynik.
- `results[].id`
Wysłane przez Ciebie `id` lub indeks polecenia.
- `results[].type`
`SUCCESS` lub `ERROR`.
- `results[].took_ms`
Czas wykonania polecenia na serwerze.
- `results[].data`
Wynik polecenia. Obecny tylko, gdy `type` to `SUCCESS`.
- `results[].code / message`
Błąd. Obecny tylko, gdy `type` to `ERROR`.

## Uwierzytelnianie

Użyj API key utworzonego w panelu, w Developers → API Keys, z zakresami wymaganymi przez polecenia.

- `Authorization`
Wysyłaj `Authorization: <api key>` lub `Authorization: Bearer <api key>`.
- `template:read`
`list_templates`, `get_template`, `render_template` i `list_template_versions`.
- `template:create`
`create_template`.
- `template:update`
`update_template` i `restore_template_version`.
- `template:delete`
`delete_template`.
- `Tokeny skrzynek`
Token webmaila tu nie działa. Jest odrzucany z `WRONG_CREDENTIAL_TYPE`.
- `Dozwolone IP`
Jeśli klucz ma listę dozwolonych IP, zapytania z innych IP dostają `403 IP_NOT_ALLOWED`.

## Łączenie przez $ref

Utwórz szablon i wyrenderuj go w tym samym żądaniu, aby sprawdzić wynik.

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"
        }
      }
    }
  ]
}
```

## Limity zapytań i cache

- `15 zapytań / sekundę`
Na IP + API key. Powyżej HTTP 429 z nagłówkiem `Retry-After`.
- `15 jednocześnie`
Najwyżej 15 zapytań przetwarzanych jednocześnie, na IP + API key.
- `Na polecenie, na konto`
`create_template` 30/min · `update_template` 60/min · `restore_template_version` 20/min · `delete_template` 30/min. Powyżej to polecenie odpowiada `RATE_LIMITED`.
- `Cache odczytu: 1,5 s`
Ten sam odczyt w ciągu 1,5 sekundy zwraca ten sam wynik. Każdy zapis na tej trasie go czyści.

## Błędy

Błędy na poziomie HTTP zwracają `type`, `code` i `message`. Błędy oznaczone CMD wracają w wyniku polecenia, z HTTP 200.

- 400`INVALID_JSON`
Body nie jest {"commands":[...]} lub przekracza 1 MB.
- 400`INVALID_ARGS`
Żądanie nie ma poleceń lub ma ich ponad 10.
- 401`MISSING_AUTH_HEADER`
Nie wysłano nagłówka Authorization.
- 401`INVALID_API_KEY`
API key nie istnieje, został unieważniony lub wyłączony w panelu.
- 401`API_KEY_EXPIRED`
API key przekroczył datę wygaśnięcia ustawioną w panelu.
- 401`WRONG_CREDENTIAL_TYPE`
Wysłano token skrzynki. Templates API wymaga API key z dashboardu.
- 403`IP_NOT_ALLOWED`
Zapytanie przyszło z IP spoza dozwolonych IP klucza.
- 403`ACCOUNT_BLOCKED`
Konto jest zablokowane.
- 403`MISSING_SCOPE`
Klucz nie ma żadnego scope `template:*`, więc żadne polecenie nie może się wykonać.
- 429`RATE_LIMITED`
Ponad 15 zapytań/s lub 15 jednocześnie dla tego samego IP + API key. Odczekaj liczbę sekund z Retry-After.
- 503`AUTH_UNAVAILABLE`
Uwierzytelnianie jest chwilowo niedostępne. Spróbuj ponownie.
- CMD`UNKNOWN_COMMAND`
Nazwa polecenia nie istnieje.
- CMD`INTERNAL`
Błąd serwera. Szczegóły trafiają tylko do logu serwera.
