Webhook Transformations & Transformation Templates

  • Updated

Transformations are a powerful Outgoing Webhook feature that allows the modification of certain webhook properties in flight. The feature enables you to write Javascript code on any webhook endpoint that can change a webhook's HTTP method, target URL, and body payload.

How to Write a Transformation

Act-On expects a Transformation to declare a function named handler. It will pass a WebhookObject to this function as its only argument and expects the function to always return a WebhookObject.

WebhookObject is a JSON object containing the following properties:

  • method, a string representing the HTTP method the webhook will be sent with. It is always "POST" by default, and its only valid values are "POST" or "PUT"
  • url, a string representing the endpoint's URL. It can be changed to any valid URL.
  • payload, which contains the webhook's payload as a JSON object. It can be changed as needed.
  • cancel, a Boolean which controls whether or not to cancel the dispatch of a webhook. This value defaults to false. Note that canceled messages appear as successful dispatches.

The Transformation will only work if the handler function returns the modified WebhookObject.

An Example Transformation​

Suppose that depending on certain criteria, you want to redirect webhooks to a custom URL instead of the endpoint's defined URL. You can do so only if this redirect to a custom URL is present in the webhook payload. You can write a transformation like this:

function handler(webhook) {
if (webhook.payload.customUrl) {
webhook.url = webhook.payload.customUrl;
}
return webhook;
}

This would be a solution for a use case such as sending a notification to the appropriate Sales Owner's Teams channel when a lead is qualified. 

Transformation Templates​

Transformation templates are pre-made integrations that connect Act-On webhooks to other services. They are accessible in a separate tab when creating an endpoint. Templates will be optimized for the format that the other service expects and they are unique per webhook event. For example, there are two separate templates for Slack notifications. One is for webhooks triggered for Forms and the other is for those triggered by Automated Programs when using the Outgoing Webhook step:

Was this article helpful?

Have more questions? Submit a request