DocumentationFundamentals

URL Encoded Form

Parse and convert URL encoded form data into JSON or any other format

Webhook Relay detects application/x-www-form-urlencoded requests and automatically parses them so your function can use it. Parsed form data can be accessed through r.RequestFormData / r.formData variable.

Using decoded values

For example if the payload looks like this:

name=john&lastname=wick

Then you can access the form elements and use them to create a new payload:

const encodedPayload = JSON.stringify({
  name: r.formData.name[0],
  lastname: r.formData.lastname[0]
})

r.setHeader("Content-Type", "application/json")
r.setBody(encodedPayload)
local json = require("json")

local encoded_payload = {
  name= r.RequestFormData.name[1],
  lastname=r.RequestFormData.lastname[1]
}
local encoded_payload, err = json.encode(encoded_payload)
if err then error(err) end

r:SetRequestHeader("Content-Type", "application/json")
r:SetRequestBody(encoded_payload)

This would transform the webhook into:

{
  "name": "john",
  "lastname": "wick"
}

Nested forms

If your form contains nested fields such as &campaign%5Bid%5D=98 you can access them directly as well:

r.setBody(r.formData["campaign[id]"][0])
r:SetRequestBody(r.RequestFormData["campaign[id]"][1])

Prerequisites

For the decoding to work, Webhook Relay expects a header Content-Type that includes application/x-www-form-urlencoded and the boundary.

Did this page help you?