# Parsing of an WebHook

**URL:** <https://community.homey.app/t/parsing-of-an-webhook/123350>\
**Category:** Questions & Help\
**Tags:** homey-pro\
**Created:** [December 9, 2024, 1:11pm UTC](https://community.homey.app/t/parsing-of-an-webhook/123350 "2024-12-09T13:11:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DirkG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkg/32/118897_2.png) [@DirkG](https://community.homey.app/u/DirkG)\
**Post date:** [December 9, 2024, 1:11pm UTC](https://community.homey.app/t/parsing-of-an-webhook/123350/1 "2024-12-09T13:11:15Z")

</div>

I have been using the iPhone [**Geofency**](https://www.geofency.com) app for some time now as a replacement for the Homey Build-In Geofencing feature. For example because…

- it’s possible to adjust the geofencing radius between 50 and 550 meters
- it’s possible to monitor multiple locations
- there is no need for additional Homey apps like the OwnTracks app, because entering and leaving is triggered via WebHooks

…and a lot more features.

Until now, I used only the normal “coming” and “going” features. But the **Geofency** app can also detect if you enter the geofencing area on foot, by bike or by car. This could be used, for example, to automatically open the garage door only when you come home by car.  
The problem now is that the WebHook doesn’t send just an _ **Event** _ and a _ **Tag** _, but a lot more information. These are the WebHook parameters:

```auto
{"id": "{Location identifier)",
"name": "{Name of the location}",
"entry": "{»1« Entry, »O« Exit}",
"date": "{Time stamp (RFC 3339)}",
"latitude": "{Latitude}",
"longitude": "{Longitude}",
"address": "{Address string of the location)",
"radius": "{Monitoring radius)",
"category": "{Frequent, Monitored, iBeacon}"
"device": "{Device identifier}",
"beaconUUID": "{iBeacon UUID}",
"major": "{iBeacon Major No.}",
"minor": "{iBeacon Minor No.}",
"currentLatitude": "{Proximity Latitude}",
"currentLongitude": "{Proximity Longitude}",
"wifiSSID": "{WLAN SSID}",
"wifiBSSID": "{WLAN BSSID}",
"motion": "{Motion type}"}

```

In addition, the app developer of the iOS _ **Geofency** _ App also provides the following sample codes for download:

# geo.php

```auto
<?php
	// This is a sample php script on how to integrate the http POST request interface for the Geofency app on iOS.
	// This is only a short demo and not a productive script.
	// Feel free to modify this script according to your wishes.
    
    // Incoming POST parameters provided by Geofency.
	// Extract parameters from http request (using “_POST” or "_REQUEST").
	// $date is a rfc3339 formatted date in the form: yyyy-MM-ddTHH:mm:ssZ
	$date=$_POST["date"];
	$isEntry=($_POST["entry"] == "1");
	$locationName=$_POST["name"];
	$locationID=$_POST["id"]; 
	$longitude=$_POST["longitude"]; // Center longitude of the location.
	$latitude=$_POST["latitude"]; // Center latitude of the location.
	$radius=$_POST["radius"];
	$address=$_POST["address"];
	$beaconUUID=$_POST["beaconUUID"];
	$major=$_POST["major"];
	$minor=$_POST["minor"];
	$deviceID=$_POST["device"];
	$currentLongitude=$_POST["currentLongitude"]; // Current longitude when entering or leaving the location.
	$currentLatitude=$_POST["currentLatitude"]; // Current latitude when entering or leaving the location.
	$wifiSSID=$_POST["wifiSSID"]; // Connected Wi-Fi SSID. 
	$wifiBSSID=$_POST["wifiBSSID"]; // Connected Wi-Fi BSSID.
	$motion=$_POST["motion"]; // Motion activity.

    if ($isEntry)
        $out = date('Y-m-d H:i:s') . " entryDate: " . $date . ", entered at " . $locationName . "\n";
    else
        $out = date('Y-m-d H:i:s') . " exitDate: " . $date . ", exited at " . $locationName . "\n";

    echo $out;

    $filename = "geofency.log";
    file_put_contents($filename, $out, FILE_APPEND | LOCK_EX);

    // Example condition:
    // Send http request if it's later than 8pm (20:00).
    $hour=substr($date, 8, 2);

    if ($hour > '20' && $isEntry) {
        echo "It’s time to eat <After Eight> and switch on lights.\n";
        // Integrate your e.g. house automation system here ...
        // http_get("http://www.mypage.com/switchOnLights.html”);
    }
?>

```

# geo\_json.php

```auto
<?php
	// This is a sample php script on how to integrate the http POST request interface for the Geofency app on iOS.
	// This is only a short demo and not a productive script.
	// Feel free to modify this script according to your wishes.

    // Extract json encoded parameters from http POST request.
    $data = json_decode(file_get_contents('php://input'));
    
    // Incoming POST parameters provided by Geofency.
    // $date is a rfc3339 formatted date in the form: yyyy-MM-ddTHH:mm:ssZ
    $date=$data->{"date"};
    $isEntry=($data->{"entry"} == "1");
    $locationName=$data->{"name"};
    $locationID=$data->{"id"};
    $latitude=$data->{"latitude"}; // Center latitude of the location.
    $longitude=$data->{"longitude"}; // Center longitude of the location.
    $radius=$data->{"radius"};
    $address=$address->{"address"};
    $beaconUUID=$data->{"beaconUUID"};
    $major=$data->{"major"};
    $minor=$data->{"minor"};
    $deviceID=$data->{"device"};
    $currentLatitude=$data->{"currentLatitude"}; // Current latitude when entering or leaving the location.
    $currentLongitude=$data->{"currentLongitude"}; // Current longitude when entering or leaving the location.
    $wifiSSID=$data->{"wifiSSID"}; // Connected Wi-Fi SSID. 
    $wifiBSSID=$data->{"wifiBSSID"}; // Connected Wi-Fi BSSID.
    $motion=$data->{"motion"}; // Motion activity.

    if ($isEntry)
        $out = date('Y-m-d H:i:s') . " entryDate: " . $date . ", entered at " . $locationName . "\n";
    else
        $out = date('Y-m-d H:i:s') . " exitDate: " . $date . ", exited at " . $locationName . "\n";

    echo $out;

    $filename = "geofency.log";
    file_put_contents($filename, $out, FILE_APPEND | LOCK_EX);

    // Example condition:
    // Send http request if it's later than 8pm (20:00).
    $hour=substr($date, 8, 2);

    if ($hour > '20' && $isEntry) {
        echo "It’s time to eat <After Eight> and switch on lights.\n";
        // Integrate your e.g. house automation system here ...
        // http_get("http://www.mypage.com/switchOnLights.html”);
    }
?>

```

# geo\_get.php

```auto
<?php
	// This is a sample php script on how to integrate the http GET request interface for the Geofency app on iOS.
	// This is only a short demo and not a productive script.
	// Feel free to modify this script according to your wishes.
    
    // Incoming POST parameters provided by Geofency.
	// Extract parameters from http request (using “_POST” or "_REQUEST").
	// $date is a rfc3339 formatted date in the form: yyyy-MM-ddTHH:mm:ssZ
	$date=$_GET["date"];
	$isEntry=($_GET["entry"] == "1");
	$locationName=$_GET["name"];
	$locationID=$_GET["id"];
	$longitude=$_GET["longitude"];
	$latitude=$_GET["latitude"];
	$radius=$_GET["radius"];
	$beaconUUID=$_GET["beaconUUID"];
	$major=$_GET["major"];
	$minor=$_GET["minor"];
	$deviceID=$_GET["device"];
    $wifiSSID=$_GET["wifiSSID"];
    $wifiBSSID=$_GET["wifiBSSID"];
    $motion=$_GET["motion"];

    if ($isEntry)
        $out = date('Y-m-d H:i:s') . " entryDate: " . $date . ", entered at " . $locationName . ", deviceID: " . $deviceID . ", wifiSSID: " . $wifiSSID . ", wifiBSSID: " . $wifiBSSID . ", motion: " . $motion . "\n";
    else
        $out = date('Y-m-d H:i:s') . " exitDate: " . $date . ", exited at " . $locationName . ", deviceID: " . $deviceID . ", wifiSSID: " . $wifiSSID . ", wifiBSSID: " . $wifiBSSID . ", motion: " . $motion . "\n";

    echo $out;

    $filename = "geofency.log";
    file_put_contents($filename, $out, FILE_APPEND | LOCK_EX);

    // Example condition:
    // Send http request if it's later than 8pm (20:00).
    $hour=substr($date, 8, 2);

    if ($hour > '20' && $isEntry) {
        echo "It’s time to eat <After Eight> and switch on lights.\n";
        // Integrate your e.g. house automation system here ...
        // http_get("http://www.mypage.com/switchOnLights.html”);
    }
?>

```

However, I have absolutely no idea what to do with it… 🤔

* * *

After I had already tried a few things with the Build-In Webhook flow cards with no success, I found a tutorial where the Homey App [_ **Webhooks** _](https://homey.app/a/skogsaas.webhooks) was used. So I installed the app and did again some tests.  
After replacing the webhooks in the iOS _ **Geofency** _ app with the Webhook URL from the Homey _ **Webhooks** _ app and creating just a simple flow with a timeline notification card, I received the following infos:

```auto
{"latitude":"52.51608","longitude":"13.37993","device":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","entry":"1","radius":"100","id":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX","address":"Unter den Linden 77\n10117 Berlin\nDeutschland","name":"Webhook-Test","category":"Monitored","date":"2024-11-17T12:07:35Z","motion":"automotive"}

```

(Personal information has been made unreadable or has been replaced)

So I created a simple AF that gives me, just for testing purposes, a timeline notification as to whether I came home on foot or by car, and it works!

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/3/e311466a5fbc68fcf253d5a0a4641978641d8bd1.png)

But I would like to realize it without the _ **Webhooks** _ app and just use internal Flow cards. Is that even possible? If so, can someone show me how?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 9, 2024, 1:20pm UTC](https://community.homey.app/t/parsing-of-an-webhook/123350/2 "2024-12-09T13:20:49Z")

</div>

> [@DirkG](#):
>
> Is that even possible?

No, the Logic webhooks don’t pass the request body in any way, and that’s where all the useful information is ☹

---

<div class="post-metadata">

**Author:** ![DirkG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkg/32/118897_2.png) [@DirkG](https://community.homey.app/u/DirkG)\
**Post date:** [December 9, 2024, 1:44pm UTC](https://community.homey.app/t/parsing-of-an-webhook/123350/3 "2024-12-09T13:44:41Z")

</div>

Also not possible with “The webhook event XYZ has been received” → “Parse (Text) as JSON and…”? Or something with a Homey Script?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 9, 2024, 2:01pm UTC](https://community.homey.app/t/parsing-of-an-webhook/123350/4 "2024-12-09T14:01:29Z")

</div>

I don’t see any way that the body data can be accessed.

---

<div class="post-metadata">

**Author:** ![DirkG](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dirkg/32/118897_2.png) [@DirkG](https://community.homey.app/u/DirkG)\
**Post date:** [December 9, 2024, 2:09pm UTC](https://community.homey.app/t/parsing-of-an-webhook/123350/5 "2024-12-09T14:09:03Z")

</div>

Too bad, but thanks anyway.
