Transforming Webhooks
HookFlow allows you to transform webhook payloads before they're delivered to your destinations. This guide explains how to use transformation rules to modify, enrich, or simplify webhook data.
Why Transform Webhooks?
There are several reasons you might want to transform webhook payloads:
- Format Compatibility: Convert webhook data to match the format expected by your application
- Data Simplification: Remove unnecessary fields to reduce payload size
- Data Enrichment: Add additional information or context to the payload
- Field Renaming: Rename fields to match your application's naming conventions
- Data Normalization: Standardize data formats across different webhook providers
How Transformations Work
Transformations in HookFlow are applied on a per-destination basis. This means:
- Each destination can have its own set of transformation rules
- Rules are applied in the order they are defined
- Transformations occur after filtering but before delivery
- The original webhook payload is preserved in logs for reference
Original Webhook Payload
Filter Rules Applied
Transform Rules Applied
Delivered to Destination
Types of Transformations
HookFlow supports several types of transformation operations:
Add Field
Add a new field to the webhook payload with a specified value.
Example:
Add field "processed_by" with value "hookflow"
Remove Field
Remove a field from the webhook payload.
Example:
Remove field "sensitive_data"
Rename Field
Change the name of a field while preserving its value.
Example:
Rename field "evt_type" to "event_type"
Modify Value
Change the value of an existing field.
Example:
Set field "status" to value "processed"
Copy Value
Copy a value from one field to another.
Example:
Copy value from "data.id" to "id"
Format Value
Format a field's value (e.g., date formatting, string operations).
Example:
Format "created_at" as ISO date string
Configuring Transformations
You can configure transformation rules when creating or editing a destination:
- Navigate to the source that contains the destination
- Click on the destination to expand its settings
- Scroll to the "Transform Rules" section
- Click "Add Transform Rule" to create a new rule
- Configure the rule with the following settings:
- Operation: The type of transformation to perform
- Path: The JSON path to the field you want to transform
- Value: The new value or target path (depending on the operation)
- Add additional rules as needed (they will be applied in order)
- Save your changes
Note: Transformation rules are applied in the order they are defined. If you have multiple rules that affect the same field, the later rules will operate on the result of the earlier rules.
JSON Path Syntax
HookFlow uses JSON path syntax to specify which fields to transform. Here's a quick reference:
Syntax | Description | Example |
---|---|---|
field | Top-level field | id, type, created_at |
parent.child | Nested field | data.customer.email |
array[0] | Array element by index | items[0].price |
field\.with\.dots | Field name with dots | metadata.user\.id |
Example Transformations
Here are some common transformation scenarios and how to implement them:
Flattening Nested Data
Move nested fields to the top level for easier access.
Original Payload:
{ "event": "payment.succeeded", "data": { "payment": { "id": "pay_123", "amount": 1000, "currency": "usd" } } }
Transform Rules:
- Copy value from "data.payment.id" to "payment_id"
- Copy value from "data.payment.amount" to "amount"
- Copy value from "data.payment.currency" to "currency"
Result:
{ "event": "payment.succeeded", "data": { "payment": { "id": "pay_123", "amount": 1000, "currency": "usd" } }, "payment_id": "pay_123", "amount": 1000, "currency": "usd" }
Removing Sensitive Data
Remove sensitive information before forwarding webhooks.
Original Payload:
{ "customer": { "id": "cus_123", "email": "user@example.com", "payment_method": { "card": { "last4": "4242", "exp_month": 12, "exp_year": 2025 } } } }
Transform Rules:
- Remove field "customer.email"
- Remove field "customer.payment_method.card"
Result:
{ "customer": { "id": "cus_123", "payment_method": {} } }
Normalizing Data Formats
Standardize data formats across different webhook providers.
Original Payload (Stripe):
{ "type": "charge.succeeded", "created": 1647532800, "data": { "object": { "id": "ch_123", "amount": 2000 } } }
Transform Rules:
- Add field "provider" with value "stripe"
- Rename field "type" to "event_type"
- Format "created" as ISO date string
- Copy value from "data.object.id" to "transaction_id"
- Copy value from "data.object.amount" to "amount_cents"
- Add field "amount_dollars" with value from "amount_cents" divided by 100
Result:
{ "provider": "stripe", "event_type": "charge.succeeded", "created": "2022-03-17T12:00:00Z", "data": { "object": { "id": "ch_123", "amount": 2000 } }, "transaction_id": "ch_123", "amount_cents": 2000, "amount_dollars": 20 }
Best Practices
Follow these best practices when configuring transformations:
- Keep it simple: Use the minimum number of transformations needed
- Test thoroughly: Verify transformations with sample webhooks before deploying
- Be careful with removals: Don't remove fields that might be needed later
- Consider performance: Complex transformations on large payloads may impact delivery time
- Use descriptive names: When adding or renaming fields, use clear and consistent naming
Next Steps
Now that you understand how to transform webhooks, explore these related topics:
- Filtering Webhooks - Learn how to conditionally forward webhooks based on their content
- Configuring Destinations - Set up where your webhooks are forwarded
- Retry Configuration - Configure how failed webhook deliveries are retried