Skip to content

Webhooks

TheYOSH edited this page Jan 30, 2020 · 4 revisions

It is possible to enable 'simple' webhooks. At the notification settings you can specify an url where the data will be posted to in JSON when a notification has triggered.

The webhook url can contain variables like %name% and %state% to translate to a special webhook url.

Use the API urls to see what variables you can use.

The data is posted as JSON. And can be read out like this in PHP:

<?php
$raw_json_data = file_get_contents('php://input');
$php_object = json_decode($raw_json_data,true);
?>

Then you will get a PHP object like this:

Array
(
    [resolution_width] => 640
    [motiondeltathreshold] => 25
    [image] => webcam/00588aa675ad27e91e6e2af0263f0631/00588aa675ad27e91e6e2af0263f0631_raw.jpg
    [max_zoom] => 2
    [motionboxes] => 1
    [id] => 00588aa675ad27e91e6e2af0263f0631
    [archivelight] => on
    [archive] => motion
    [archivedoor] => ignore
    [last_update] => Thu Jan 30 12:17:31 2020
    [state] => online
    [location] => http://yoshieaxis.theyosh.lan/jpg/1/image.jpg
    [preview] => webcam/00588aa675ad27e91e6e2af0263f0631_tile_0_0_0.jpg
    [archive_images] => 
    [rotation] => 0
    [now] => Thu Jan 30 12:17:31 2020
    [motionminarea] => 500
    [name] => Extern
    [resolution_height] => 480
    [motioncompareframe] => last
    [is_live] => 0
    [files] => Array
    (
        [0] => Array
            (
                [data] => [BASE64_DATA]
                [name] => 00588aa675ad27e91e6e2af0263f0631_archive_1580383050.jpg
            )

    )
)

If there are files attached (webcam) then you will get an array of files. Depending on the amount that are send. The files will be available in the variable 'files'. The structure is:

Array
(
    [0] => Array
        (
            [data] => [BASE64_DATA]
            [name] => 00588aa675ad27e91e6e2af0263f0631_archive_1580383050.jpg
        )

)

When you save the file to disk, make sure you decode it from base64 to binary!

There is an example script on the contrib folder which has a fully working PHP example. https://github.com/theyosh/TerrariumPI/blob/master/contrib/receiving_webhook.php

Clone this wiki locally