The Webhook action pushes form submission data to any URL endpoint using POST, GET, PUT, PATCH, or DELETE. It can also write data returned by the endpoint into your form fields.
Demo
Example Use Cases
- Make a request to an API for data and use the returned data to populate form fields.
- Pre-load a form with statistical data from an endpoint.
- Create a vehicle VIN lookup using an API endpoint.
- Push a form submission to a custom endpoint.
- Push a form submission to a third party that WS Form does not natively integrate with.
Creating a Webhook Action
To create a Webhook action:
- When editing your form, click the Actions icon at the top of the page. The Actions sidebar will open on the right-hand side of the page.
- Click the Add icon to add a new action.
- Select Webhook from the Action pulldown. A series of settings will appear.
As with all sidebars in WS Form, click the Save button at the bottom to save your changes, or click Cancel to disregard your changes.
Testing Webhooks
A useful way of testing your webhook request is to use the website Webhook.site. Put the unique URL provided in the URL of Endpoint setting (see below), submit your form and you will see the request on the Webhook.site.
Configuring the Webhook Action
Note: We are unable to provide support for endpoints used with this action.
The action settings are split across three tabs: Request, Payload, and Response.
When Should This Action Run?
Choose when the webhook runs. The options are:
- Form Saved
- Form Submitted
Form Submitted is checked by default. If you are running the webhook action using conditional logic, uncheck both options.
Request
URL of Endpoint
Enter the URL of the endpoint to send data to, for example https://mysite.com/my_endpoint.php. The field defaults to https://.
WS Form variables can change the path or query string only. They cannot change the scheme, host, or port.
Method
Select the HTTP request method. The available options are:
- POST (default)
- GET
- PUT
- DELETE
- PATCH
Content Type
Select the content type. The available options are:
- JSON (application/json) (default)
- URL Encoded (application/x-www-form-urlencoded)
Authentication
Select the type of authentication. The available options are:
- None (default)
- Basic
If you select Basic, the Username and Password settings appear. WS Form variables are supported in both.
HTTP Header Name/Values
Add HTTP header names and values to the request. WS Form variables are supported.
To add a header:
- Click the Add icon at the bottom right of the HTTP Header Name/Values section.
- In the Name column, enter the header name.
- In the Value column, enter the header value.
- Repeat this process for each header you want to send.
- Click the Save button at the bottom of the sidebar to save your changes.
Timeout
How long the connection should stay open, in seconds. Leave this blank to use 15 seconds. WS Form only waits for a response when Process Response is checked.
SSL Verify
Whether to verify SSL for the request. This is checked by default. We recommend leaving it checked.
Cookie Passthrough
If checked, cookies from the form submission are passed through to the API request. This only applies when the request is to the same hostname. This is unchecked by default.
Payload
Field Mapping
Map WS Form fields to endpoint keys. Each row has three columns: Form Field, Key, and Type.
To map a field:
- Click the Add icon at the bottom right of the Field Mapping section.
- In the Form Field column, select your form field.
- In the Key column, enter a key name. You can enter a simple key name, for example
first_name, or use dot notation, for exampleperson[0].name.first. - In the Type column, choose how the value is sent. Source sends the field value as-is. String, Integer, Float, and Boolean cast the value to that type.
- Repeat this process for each field you want to send.
- Click the Save button at the bottom of the sidebar to save your changes.
Custom Mapping
Map custom values to endpoint keys. Each row has three columns: Key, Value, and Type. WS Form variables are supported.
To add a custom mapping:
- Click the Add icon at the bottom right of the Custom Mapping section.
- In the Key column, enter a key name. You can enter a simple key name, for example
source, or use dot notation, for examplemeta.campaign. - In the Value column, enter the value to send.
- In the Type column, choose Source, String, Integer, Float, or Boolean.
- Repeat this process for each custom value you want to send.
- Click the Save button at the bottom of the sidebar to save your changes.
Repeaters to Arrays
If checked, repeaters are turned into arrays instead of being comma separated. This applies to field mappings only. This is unchecked by default.
File Format
Choose how file fields are sent. This includes file, signature, and media capture fields. The available options are:
- Base64: files are sent as Base64. Multiple files are an array.
- File Objects: files are sent as file objects.
- URLs (default): files are sent as URLs. Multiple URLs are comma separated.
Convert Arrays to Delimited Text
If checked, fields that have multiple values (for example checkboxes) are converted to delimited text. This is checked by default. The delimiter is set in Array Delimiter.
Array Delimiter
The character used when an array is converted to delimited text. This setting is shown when Convert Arrays to Delimited Text is checked. The default is a comma (,).
Deduplicate Arrays
If checked, multiple mappings to the same key are deduplicated. This is unchecked by default.
Ignore Empty Values
If checked, keys with an empty value are not included in the request. This is unchecked by default.
Response
Process Response
If checked, WS Form processes response code mapping and response field mapping. This is checked by default.
If this is not checked, WS Form does not wait for a response and errors are ignored. Response Code Mapping and Response Field Mapping are hidden.
Response Code Mapping
Add handlers for specific HTTP status codes. This setting is shown when Process Response is checked. Each row has two columns: Code and Handler.
A new webhook includes these mappings:
| Code | Handler |
|---|---|
| 200 (OK) | Process Response Field Mapping |
| 201 (Created) | Process Response Field Mapping |
| 204 (No Content) | Ignore |
| 304 (Not Modified) | Ignore |
| 400 (Bad Request) | Throw error |
| 401 (Unauthorized) | Throw error |
| 403 (Forbidden) | Throw error |
| 404 (Not Found) | Throw error |
| 406 (Not Acceptable) | Throw error |
| 408 (Request Timeout) | Throw error |
| 409 (Conflict) | Throw error |
| 500 (Internal Server Error) | Throw error |
| 501 (Not Implemented) | Throw error |
| 502 (Bad Gateway) | Throw error |
| 503 (Service Unavailable) | Throw error |
| 504 (Gateway Timeout) | Throw error |
A status code that is not mapped is ignored.
To add a mapping:
- Click the Add icon at the bottom right of the Response Code Mapping section.
- In the Code column, choose the HTTP status code.
- In the Handler column, choose how to handle that code.
- Repeat this process for each HTTP status code you want to map.
- Click the Save button at the bottom of the sidebar to save your changes.
The handlers are:
| Handler | Description |
|---|---|
| Ignore | The HTTP status code is ignored and actions continue. |
| Process Response Field Mapping | Response field mapping is processed. See Response Field Mapping below. |
| Throw error | An error is shown on the form and action processing stops. |
| Halt | Action processing stops. No error is shown on the form. |
If you use Throw error, you can turn on Form Submission Error Email in WS Form settings to have the error details emailed to you.
Response Field Mapping
Map values in the endpoint response to WS Form fields. The response must be JSON. This setting is shown when Process Response is checked. Mapping runs only for status codes whose handler is Process Response Field Mapping.
Each row has two columns: Key and Form Field.
To add a mapping:
- Click the Add icon at the bottom right of the Response Field Mapping section.
- In the Key column, enter the key from the JSON response. You can enter a simple key name, for example
first_name, or use dot notation, for exampleperson[0].name.first. - In the Form Field column, choose the form field to populate.
- Repeat this process for each value you want to map.
- Click the Save button at the bottom of the sidebar to save your changes.
Debug
You can use the debug console log to view information about the request and response for a webhook request.