Skip to content

Headless-API

Die Headless-API bietet Ihnen vollständigen programmatischen Zugriff auf Templates, Medien, Rendering und alle Cloud-Funktionen – ohne den visuellen Editor. Bauen Sie benutzerdefinierte Workflows, Stapelverarbeitungen, CI/CD-Pipelines und Integrationen.

Authentifizierung

Verwenden Sie für serverseitigen Zugriff die direkte Authentifizierung:

js
import { createSdkAuthManager, ApiClient } from '@templatical/core/cloud';

const auth = createSdkAuthManager({
  mode: 'direct',
  clientId: process.env.TEMPLATICAL_CLIENT_ID,
  clientSecret: process.env.TEMPLATICAL_CLIENT_SECRET,
  tenant: 'tenant-slug',
});

await auth.initialize();
const api = new ApiClient(auth);

Wichtig

Direkte Authentifizierung darf ausschließlich in serverseitigem Code verwendet werden. Geben Sie Zugangsdaten niemals im Browser preis.

Templates

Erstellen

js
const template = await api.createTemplate({
  blocks: [],
  settings: { width: 600, backgroundColor: '#ffffff', fontFamily: 'Arial' },
});

Lesen

js
const template = await api.getTemplate('template-id');

Aktualisieren

js
const updated = await api.updateTemplate('template-id', {
  blocks: modifiedBlocks,
  settings: template.content.settings,
});

Löschen

js
await api.deleteTemplate('template-id');

Export

js
const { html, mjml } = await api.exportTemplate('template-id');

Mit benutzerdefinierten Schriftarten:

js
const { html } = await api.exportTemplate('template-id', {
  customFonts: [{ name: 'Inter', url: 'https://fonts.googleapis.com/css2?family=Inter' }],
  defaultFallback: 'Arial, sans-serif',
});

Snapshots

js
// Snapshots auflisten
const snapshots = await api.getSnapshots('template-id');

// Snapshot erstellen
await api.createSnapshot('template-id', content);

// Snapshot wiederherstellen
const restored = await api.restoreSnapshot('template-id', 'snapshot-id');

Kommentare

js
// Kommentare auflisten
const comments = await api.getComments('template-id');

// Kommentar hinzufügen
const comment = await api.createComment('template-id', {
  body: 'This section needs a stronger CTA',
  block_id: 'block-uuid',
  user_id: 'user-123',
  user_name: 'Jane Smith',
  user_signature: 'hmac-signature',
});

// Kommentar auflösen
await api.resolveComment('template-id', 'comment-id', {
  user_id: 'user-123',
  user_name: 'Jane Smith',
  user_signature: 'hmac-signature',
});

Gespeicherte Module

js
// Module auflisten
const modules = await api.listModules();

// Modul erstellen
const module = await api.createModule({
  name: 'Product Card',
  content: sectionContent,
});

// Modul löschen
await api.deleteModule('module-id');

Test-E-Mails

js
await api.sendTestEmail('template-id', {
  recipient: 'test@example.com',
  html: '<html>...</html>',
  allowed_emails: ['test@example.com'],
  signature: 'hmac-signature',
});

Plan-Konfiguration

js
const config = await api.fetchConfig();
console.log(config.features); // Verfügbare Funktionen für diesen Plan

Referenz der API-Routen

Alle Routen sind auf ein Projekt und einen Mandanten bezogen:

RouteMethodeBeschreibung
configGETPlan-Konfiguration abrufen
broadcasting/authPOSTWebSocket-Verbindung authentifizieren
templatesPOSTTemplate erstellen
templates/import/from-beefreePOSTBeeFree-Template importieren
templates/import/from-unlayerPOSTUnlayer-Template importieren
templates/{id}GETTemplate abrufen
templates/{id}PUTTemplate aktualisieren
templates/{id}DELETETemplate löschen
templates/{id}/exportPOSTNach HTML/MJML exportieren
templates/{id}/send-test-emailPOSTTest-E-Mail senden
templates/{id}/snapshotsGETSnapshots auflisten
templates/{id}/snapshotsPOSTSnapshot erstellen
templates/{id}/snapshots/{id}/restorePOSTSnapshot wiederherstellen
templates/{id}/commentsGETKommentare auflisten
templates/{id}/commentsPOSTKommentar erstellen
templates/{id}/comments/{id}PUTKommentar aktualisieren
templates/{id}/comments/{id}DELETEKommentar löschen
templates/{id}/comments/{id}/resolvePOSTKommentar auflösen
templates/{id}/ai/generatePOSTKI-Inhaltsgenerierung
templates/{id}/ai/conversation-messagesGETKI-Gesprächsverlauf
templates/{id}/ai/suggestionsPOSTKI-Prompt-Vorschläge
templates/{id}/ai/rewrite-textPOSTKI-Text-Umschreibung
templates/{id}/ai/scorePOSTTemplate-Qualitätsbewertung
templates/{id}/ai/fix-findingPOSTKI-Behebung eines Bewertungs-Findings
templates/{id}/ai/generate-from-designPOSTUmwandlung von Design zu Template
saved-modulesGETModule auflisten
saved-modulesPOSTModul erstellen
saved-modules/{id}PUTModul aktualisieren
saved-modules/{id}DELETEModul löschen
media/browseGETMedien durchsuchen
media/uploadPOSTMedien hochladen
media/deletePOSTMedien löschen
media/movePOSTMedien in einen Ordner verschieben
media/check-usagePOSTMedien-Nutzung in Templates prüfen
media/frequently-usedGETHäufig verwendete Medien abrufen
media/import-from-urlPOSTMedien von URL importieren
media/{id}PUTMedien-Metadaten aktualisieren
media/{id}/replacePOSTMediendatei ersetzen
media-foldersGETMedienordner auflisten
media-foldersPOSTMedienordner erstellen
media-folders/{id}PUTMedienordner umbenennen
media-folders/{id}DELETEMedienordner löschen