Webhook is a technical name to indicate a web-based notification that sends a message to an URL when certain actions happen.
Cloud4Wi allows you to setup a webhook the following types of event:
- Sign-up: the event is triggered after a user is registered to the database (either registration from the Splash Page, Cloud4Wi Dashboard or Kiosk)
- Login: the event is triggered after a guest user signs-in on the guest Wi-Fi
- Presence: the event is triggered after a user's device is detected by the access point
Webhooks can be created in the Cloud4Wi Dashboard of your Cloud4Wi Company Account, from Manage > Notifications.
The page shows a summary of the existing notifications.
- For each webhook, you can check the percentage of notifications that have been delivered successfully and those which originated an error.
- You can specify a list of venues where the webhook is enabled
- You can enable or disable the webhook
- You can test the webhook by clicking on the icon ()
Note: at the moment you can not edit an existing webhook. But you can delete and then re-create it.
Create a webhook
To create a webhook you have to click on the Add button on the top of the page.
On the next page, you can set the following data:
- Name: name of your webhook, for inventory purposes
- Type: type of event, either login or sign-up
- URL: end-point of the HTTP POST request (for example https://yourdomain.com/myapps/webhook.com), The end-point of the HTTP POST request of the webhook can be http and https; if https the server must be correctly configured in order to support the Server Name Indication (SNI) (https://en.wikipedia.org/
- Auth Token: validation code that will be included in the header of each HTTP POST request so that the receiver can validate the source of the POST
- Venues: the venues where the webhook can be triggered
At the moment you can not edit existing a webhook. But you can delete and then re-create it.
The Auth Token is included in the HTTP header of the POST request with the name "Authorization".
Content-Type: application/json Accept-Charset: UTF-8 Cf-Ipcountry: IE Cf-Ray: 3882e1b1980f2969-DUB Accept: application/json Authorization: 1234567890
The HTTPS POST data is a JSON file containing the following dataset:
- The hotspotId parameter is not available on the Sign-Up webhook when users register from a Kiosk or they are manually created from the Cloud4Wi Dashboard.
- The customOptin key contains all the defined custom opt-in clauses. In case no clause is defined on the organization, then the key will not appear.
Listener example in PHP
Here a simple example to catch the webhook message and parse the data:
$headers = getallheaders(); //get headers
$jsonPayload = file_get_contents('php://input
'); //get the json body
$aPayload = json_decode($jsonPayload, true);
$auth = $headers['Authorization'];
$event = $aPayload['event'];
$userId = $aPayload['userId'];
$tenantId = $aPayload['tenantId'];