Skip to content

Headless API

The Headless API gives you full programmatic access to templates, media, rendering, and all Cloud features — without the visual editor. Build custom workflows, batch operations, CI/CD pipelines, and integrations.

Authentication

Use direct authentication for server-side access:

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

WARNING

Direct authentication should only be used in server-side code. Never expose credentials in the browser.

Templates

Create

js
const template = await api.createTemplate({
  settings: { width: 600 },
  sections: [],
});

Read

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

Update

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

Delete

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

Export

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

With custom fonts:

js
const { html } = await api.exportTemplate('template-id', {
  fonts: { 'Inter': 'https://fonts.googleapis.com/css2?family=Inter' },
});

Snapshots

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

// Create a snapshot
await api.createSnapshot('template-id', content);

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

Comments

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

// Add a comment
const comment = await api.createComment('template-id', {
  body: 'This section needs a stronger CTA',
  block_id: 'block-uuid',
});

// Resolve a comment
await api.resolveComment('template-id', 'comment-id');

Saved Modules

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

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

// Delete a module
await api.deleteModule('module-id');

Test Emails

js
await api.sendTestEmail('template-id', {
  recipient: 'test@example.com',
});

Plan Configuration

js
const config = await api.fetchConfig();
console.log(config.features); // Available features for this plan

API Routes Reference

All routes are scoped to a project and tenant:

RouteMethodDescription
templatesPOSTCreate template
templates/{id}GETGet template
templates/{id}PUTUpdate template
templates/{id}DELETEDelete template
templates/{id}/exportPOSTExport to HTML/MJML
templates/{id}/send-test-emailPOSTSend test email
templates/{id}/snapshotsGETList snapshots
templates/{id}/snapshotsPOSTCreate snapshot
templates/{id}/snapshots/{id}/restorePOSTRestore snapshot
templates/{id}/commentsGETList comments
templates/{id}/commentsPOSTCreate comment
templates/{id}/comments/{id}PUTUpdate comment
templates/{id}/comments/{id}DELETEDelete comment
templates/{id}/comments/{id}/resolvePOSTResolve comment
saved-modulesGETList modules
saved-modulesPOSTCreate module
saved-modules/{id}PUTUpdate module
saved-modules/{id}DELETEDelete module
media/browseGETBrowse media
media/uploadPOSTUpload media
media/deletePOSTDelete media
media/{id}PUTUpdate media metadata