Geofencing webhooks

Overview

Pulsetracker’s Geofencing feature allows you to monitor when a device enters or exits a predefined geographic area. You can configure geofences via the dashboard or the HTTP API and receive real-time webhook notifications when events occur.


1. Setting Up Webhook tokens

To validate incoming webhook requests, you need to generate a Webhook token:

  1. Go to DashboardTokens & Webhooks.

  2. Create a new Webhook token.

  3. Copy the generated token and store it securely.

  4. Use this token to verify requests from Pulsetracker.


2. Creating a Geofence

Option 1: Using the Dashboard

  1. Navigate to DashboardGeofencing.

  2. Click Add New Geofence.

  3. Provide a Name for the geofence.

  4. Draw the Polygon on the interactive map.

  5. (Optional) Set a Webhook URL to receive event notifications.

  6. Select an App that this geofence applies to.

  7. Save the geofence.

Option 2: Using the HTTP API

You can also create geofences programmatically via Pulsetracker’s API. Refer to the API documentation for request details.


3. Webhook Events

When a device enters or exits a geofence, Pulsetracker sends a POST request to your webhook URL with the following payload:

Request Body:

{
    "event": "inside" | "outside",
    "point": { "type": "Point", "coordinates": [longitude, latitude] },
    "device_id": 12345,
    "geofence_id": 67890,
    "location_received_at": 1710000000,
    "event_sent_at": 171000003
}

Headers:

p-signature: {signature_string}

4. Validating Webhook Signatures

To ensure the webhook request is from PulsesTracker, you must validate the

p-signature header. The signature is calculated as follows:

Signature Calculation (Server-Side Example in PHP):

function calculateSignature(string $webhookUrl, array $payload, string $secret): string {
    $payloadJson = json_encode($payload);
    return hash_hmac('sha256', $payloadJson, $secret);
}
  • $secret is the Webhook Signature you generated from the dashboard.

  • Webhooks will not be sent if a signature is not created.

  • Always compare the received p-signature with your locally calculated signature before processing the request.

Updated on