Automatically transform webhook payloads

By Karolis Rusenas · Nov 13, 2024

In Webhook Relay you can automatically transform webhook payloads using functions that is basically a Lua code snippet to manipulate the payload. While powerful, it requires you to write the code yourself. Now, we are introducing a new feature that allows you to automatically transform webhook payloads using AI.

How it works

You will need to provide two examples:

  • Input payload (that you want to transform)
  • Output payload (that you want to receive)

We will use this to automatically generate the transformation function that will run on every webhook.

How to use it

Go to the magic transform page.

magic transform

Now, you will need to provide input and output payload samples. For this example we will use a simple JSON to demonstrate how it works. You can view more complex examples within the dashboard as well.

Do’s and Don’ts

The key thing to remember is that the input and output payload values should match.

Input sample:

{
  "name": "John",
  "surname": "Doe",
  "age": 30,
  "city": "London"
}

Output sample (good):

{ 
  "data_type": "person",
  "person": {
    "name": "John",
    "surname": "Doe",
    "age": 30,
    "city": "London"
  }
}

Output sample (bad):

{
  "name": "Larry",
  "surname": "Sheet"
}

Try it out

Let’s add the samples and click “generate function”:

viewing generated function

Once generated, we can click continue and enter the destination URL. Feel free to grab a new testing endpoint from https://bin.webhookrelay.com/.

You can either click “send a test request” or use curl to ping the endpoint

send test request

On the receiving end, you should see the transformed payload:

received webhook

It means we have successfully transformed the payload from our initial payload to the new format.

Troubleshooting

If the function generation is failing, try to check the following:

  • Input and output payloads should have matching values (names, types, etc.)
  • Input and output payloads should be valid JSON. We will introduce support for XML, form-data, and other formats in the future. If you have a use case for it, let us know. You can still use the function editor for that.
  • Try different examples if one doesn’t work. You can also remove any irrelevant values from JSON structures.