Username:
Password:
    Forgot your password?
Member Login

Web Hooks in Sitellite

Notes

Chat Loading chat status
  • Please subscribe to chat.
  • Older messages can be viewed in the chat archive.

Subscribe  |  The Lounge  |  Share Lesson

Chapter 2: Writing a POST Handler

POST Parameters

Each POST request is sent certain parameters or information about the workflow event that occurred in Sitellite. These include:

auth – The authorization key for verifying that the request originated from your website. 

event – The workflow event that occurred. This can be one of: add, edit, delete, pre-delete or error.

summary – A summary message of the event.

action – If the event is 'edit' there is an action that specifies the type of edit. This can be one of: modify, replace, republish or update. Each of these correspond to status changes in Sitellite's internal workflow.

collection – If the event is an add, edit, delete or pre-delete, this will specify the collection name (e.g., sitellite_page).

key – If the event is an add, edit, delete or pre-delete, this will contain the primary key of the item.

changelog – If the event is an add, edit, delete or pre-delete, this may contain a change summary from the site editor.

Verification Code

Create a new PHP script called webhook.php in your website root folder. Add the following code to it (make sure you replace the placeholder for your auth key with the real thing!):

<?php

if ($_POST['auth'] != 'ENTER YOUR AUTH KEY HERE') {
    die ('Auth key verification failed!');
}

?>

Verifying the Remote Server

To verify the remote server and request method, you can add the following code to your webhook.php file. Please note to change the server address to your actual site instead of '127.0.0.1' as in the example.

if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
	die ('Server verification failed!');
}

if ($_SERVER['REQUEST_METHOD'] != 'POST') {
	die ('Request method verification failed!');
}

A Basic Request Handler

If we want to create a basic request handler from here, we can simply add a bit of code such as the following to our webhook.php file.

@mail (
    'me@example.com',
    sprintf ('Workflow event notice [%s]', $_POST['event']),
    'Summary: ' . $_POST['summary'],
    'From: noreply@example.com'
);

This example will simply send an email to me@example.com with the event value in the subject line and the summary in the message body whenever an event is triggered.

As you can see, it's easy to implement external callbacks in Sitellite using web hooks. And with a little security precaution as shown above plus a bit of input validation and SSL for encrypted communication, your website and external applications will suddenly start getting along famously.