Manipulate webhook request body

This example will demonstrate how to modify webhook requests on the fly using Webhook Relay Functions that provide FaaS (Function as a Service) functionality. We will create a Lua function, configure routing and then send a test payload.

1. Create the function.

This function will parse JSON payload and then will construct a new JSON payload. It will also change HTTP method (to PUT) and set a content type header. Save this function to file my_function.lua:

-- my_function.lua
local json = require("json")

local body, err = json.decode(r.RequestBody)
if err then error(err) end

local message = "Webhook received, user:" .. body["data"]["user"]

-- Preparing new payload
local new_payload = {
type= "webhook_event",
message= message}

local result, err = json.encode(new_payload)
if err then error(err) end

-- Set request header to application/json
r:SetRequestHeader("Content-Type", "application/json")
-- Set request method to PUT
-- Set modified request body

Now, add this function to your account:

relay function create my_function.lua

To view your functions:

$ relay function ls
6f65e856-374a-49f8-92a2-e6db2281a177 my_function lua 330 B 3 seconds 3 seconds

2. Create routing configuration

Now, we will need some target where to send webhooks. Normally it would be just your system that is supposed to receive them (your backend application, Zapier, Slack, etc..)

For the sake of this example we will use service. Once you enter the site you should be able to see a generated webhook inbox, copy your endpoint ( and use relay forward command:

relay forward --bucket modify-req-with-func --function my_function --type public


Once the command is executed, you should display

3. Send test payload

Let’s send a test payload:

curl --request POST \
--url \
--data '{
"data": {
"user": "[email protected]"

You can view modified requests in Webhook Relay dashboard and in the Webhook Bin Service:

modified request payload

Where body is now:

"message": "Webhook received, user:[email protected]",
"type": "webhook_event"

and HTTP request method is PUT.