DocumentationFundamentals
Multipart form to JSON
Parsing multipart form data inside the Webhook Relay Function
Webhook Relay detects multipart/formdata requests and automatically parses them so your function can use it. Parsed form data can be accessed through r.RequestFormData / r.formData variable. You can use Webhook Relay to receive a form and convert it into any kind of JSON that can be sent to another API.
Using decoded values
For example if the payload fragment looks like this:
...
--------------------------5683f7544dff7b07
Content-Disposition: form-data; name="username"
John
--------------------------5683f7544dff7b07
...
Then to get username value (which is John) you will need to:
// values can be accessed through 'r.formData' object. Since
// there can be multiple values for each key, you also need to
// specify that it's the first element of the list (0-indexed):
const username = r.formData.username[0]
const firstName = r.formData.first_name[0]
// transforming form data into JSON
const jsonPayload = {
username: username,
first_name: firstName
}
const encodedPayload = JSON.stringify(jsonPayload)
r.setBody(encodedPayload)
Prerequisites
For the decoding to work, Webhook Relay expects a header Content-Type that includes multipart/form-data and the boundary.
