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.
How it works
Section titled “How it works”- An event is routed to an endpoint with a transformation configured
- Mittr executes the JavaScript transformation with the event payload as input
- The transformed result replaces the original delivery parameters
- Mittr delivers the modified request
Transformations run in a sandboxed environment with a 1-second timeout and 128MB memory limit.
Configure a transformation
Section titled “Configure a transformation”Set the transformation field when creating or updating an endpoint:
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\" } }" }'Transformation API
Section titled “Transformation API”Your transformation code receives these variables and must return an object:
Input variables
Section titled “Input variables”| Variable | Type | Description |
|---|---|---|
payload | object | The event payload |
eventType | string | The event type (e.g., order.created) |
headers | object | The current delivery headers |
Return object
Section titled “Return object”| Field | Type | Description |
|---|---|---|
payload | object | Modified payload (replaces original) |
method | string | HTTP method override (default: POST) |
url | string | URL override (replaces endpoint URL for this delivery) |
headers | object | Additional headers to merge |
cancel | boolean | Set to true to skip this delivery entirely |
All fields are optional. Omitted fields keep their original values.
Examples
Section titled “Examples”Reshape a payload
Section titled “Reshape a payload”// Extract only the fields the destination needsreturn { payload: { id: payload.orderId, customer: payload.customerEmail, items: payload.lineItems.map(i => ({ sku: i.sku, qty: i.quantity })), total: payload.totalCents / 100 }}Add custom headers
Section titled “Add custom headers”// Add authorization and routing headersreturn { headers: { "Authorization": "Bearer " + payload.apiToken, "X-Tenant-ID": payload.tenantId }}Change HTTP method
Section titled “Change HTTP method”// Use PUT instead of POST for update eventsif (eventType === "order.updated") { return { method: "PUT", url: "https://api.example.com/orders/" + payload.orderId }}return {}Conditionally cancel delivery
Section titled “Conditionally cancel delivery”// Only deliver high-value ordersif (payload.amount < 10000) { return { cancel: true }}return { payload: { ...payload, priority: "high" }}Route to different URLs by event type
Section titled “Route to different URLs by event type”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"}Limits
Section titled “Limits”| Limit | Value |
|---|---|
| Execution timeout | 1 second |
| Memory limit | 128 MB |
Transformations that exceed these limits are terminated and the delivery proceeds with the original payload.