Skip to content
mittr

Payload Transformations

Payload transformations let you modify the HTTP method, URL, headers, and body of a webhook before Mittr delivers it. Each endpoint can have its own transformation — written in JavaScript.

  1. An event is routed to an endpoint with a transformation configured
  2. Mittr executes the JavaScript transformation with the event payload as input
  3. The transformed result replaces the original delivery parameters
  4. Mittr delivers the modified request

Transformations run in a sandboxed environment with a 1-second timeout and 128MB memory limit.

Set the transformation field when creating or updating an endpoint:

Terminal window
curl -X POST https://app.mittr.io/api/v1/endpoints \
-H "X-API-Key: mtr_your_key" \
-H "Content-Type: application/json" \
-d '{
"url": "https://api.example.com/orders",
"eventTypes": ["order.*"],
"transformation": "return { payload: { orderId: payload.id, total: payload.amount / 100, currency: \"usd\" } }"
}'

Your transformation code receives these variables and must return an object:

VariableTypeDescription
payloadobjectThe event payload
eventTypestringThe event type (e.g., order.created)
headersobjectThe current delivery headers
FieldTypeDescription
payloadobjectModified payload (replaces original)
methodstringHTTP method override (default: POST)
urlstringURL override (replaces endpoint URL for this delivery)
headersobjectAdditional headers to merge
cancelbooleanSet to true to skip this delivery entirely

All fields are optional. Omitted fields keep their original values.

// Extract only the fields the destination needs
return {
payload: {
id: payload.orderId,
customer: payload.customerEmail,
items: payload.lineItems.map(i => ({ sku: i.sku, qty: i.quantity })),
total: payload.totalCents / 100
}
}
// Add authorization and routing headers
return {
headers: {
"Authorization": "Bearer " + payload.apiToken,
"X-Tenant-ID": payload.tenantId
}
}
// Use PUT instead of POST for update events
if (eventType === "order.updated") {
return {
method: "PUT",
url: "https://api.example.com/orders/" + payload.orderId
}
}
return {}
// Only deliver high-value orders
if (payload.amount < 10000) {
return { cancel: true }
}
return {
payload: {
...payload,
priority: "high"
}
}
const routes = {
"order.created": "https://api.example.com/orders",
"order.updated": "https://api.example.com/orders/" + payload.id,
"customer.created": "https://api.example.com/customers"
}
return {
url: routes[eventType] || "https://api.example.com/webhooks",
method: eventType.includes("updated") ? "PUT" : "POST"
}
LimitValue
Execution timeout1 second
Memory limit128 MB

Transformations that exceed these limits are terminated and the delivery proceeds with the original payload.