Skip to content

Webhook Integration

Webhooks allow you to receive real-time notifications when users save or download templates in your embedded editor. This enables you to track user activity, sync data, and trigger workflows in your application.

How Webhooks Work

When a user performs an action in the embedded editor, Templated sends a POST request to your webhook URL with details about the action.

  1. User performs action (create, save or download) in the embedded editor

  2. Templated processes the action and captures relevant data

  3. HTTP POST request sent to your configured webhook URL

  4. Your server receives and processes the webhook data

  5. Your application responds with appropriate actions or data storage

Webhook Configuration

Set up your webhook URL in the embed configuration:

  1. Go to your Embed Setup page

  2. Expand Advanced Settings

  3. Enter your webhook URL in the Webhook URL field

  4. Save your configuration

Webhook Events

Webhooks are triggered for the following actions:

Create Event

Triggered when a user creates a new template in the embedded editor.

Create Event Payload
{
"event": "create",
"timestamp": "2024-03-20T10:30:00Z",
"templateId": "tpl_456def",
"templateName": "New Design"
}

Save Event

Triggered when a user saves a template in the embedded editor.

Save Event Payload
{
"event": "save",
"timestamp": "2024-03-20T10:30:00Z",
"templateId": "tpl_456def",
"templateName": "Updated Design",
}

Download Event

Triggered when a user downloads a template from the embedded editor.

Download Event Payload
{
"event": "download",
"timestamp": "2024-03-20T10:35:00Z",
"templateId": "tpl_456def",
"templateName": "Final Design",
}

Frontend Event Listening

You can also listen for events directly in the frontend using the postMessage API. This is useful for immediate UI updates or client-side tracking.

Frontend Event Listener
window.addEventListener('message', (event) => {
// Verify origin for security
if (event.origin !== 'https://app.templated.io') {
return;
}
const { action, templateId } = event.data;
switch (action) {
case 'create':
console.log('Template created:', templateId);
// Update UI, show success message, etc.
break;
case 'save':
console.log('Template saved:', templateId);
// Track analytics, update download count, etc.
break;
case 'download':
console.log('Template downloaded:', templateId);
// Handle cleanup, redirect, etc.
break;
}
});

Frontend vs Backend Events

Frontend Events: Immediate UI updates, client-side tracking, user feedback
Backend Webhooks: Data persistence, server-side processing, integrations with other systems

Use both for a complete integration experience.

How to implement a basic webhook handler in your application?

Express Webhook Handler
const express = require('express');
const app = express();
// Middleware to parse JSON
app.use(express.json());
app.post('/api/templated-webhook', (req, res) => {
const { event, timestamp, template, render, user, metadata } = req.body;
console.log(`Received ${event} event from user ${user.embedUserId}`);
switch (event) {
case 'create':
handleCreateEvent(template, user, metadata);
break;
case 'save':
handleSaveEvent(template, user, metadata);
break;
case 'download':
handleDownloadEvent(render, template, user, metadata);
break;
default:
console.log('Unknown event type:', event);
}
// Respond with 200 to acknowledge receipt
res.status(200).json({ received: true });
});
function handleCreateEvent(template, user, metadata) {
// Your create logic here
console.log(`Template ${template.id} created by ${user.embedUserId}`);
}
function handleSaveEvent(template, user, metadata) {
// Update user's project with new template
// Log activity
// Send notifications
console.log(`Template ${template.id} saved by ${user.embedUserId}`);
}
function handleDownloadEvent(render, template, user, metadata) {
// Track download metrics
// Update user quotas
// Trigger follow-up workflows
console.log(`Render ${render.id} downloaded by ${user.embedUserId}`);
}

Troubleshooting common issues

Webhook not receiving data

→ Verify your webhook URL is publicly accessible
→ Check that your server responds with 200 status code
→ If you’re passing metadata, ensure you’re parsing JSON correctly

Missing metadata

→ Verify metadata is being passed in the embed URL in the correct format
→ Check that metadata is properly base64 encoded

Timeout errors

→ Ensure your webhook handler responds quickly (< 10 seconds)
→ Consider processing heavy operations asynchronously