<!-- Webhooks and the Reservations API. Canonical: https://parksby.io/developers/webhooks · Last updated 2026-11-21 · OpenAPI: https://parksby.io/openapi.json -->

# Parksby Outbound Webhook API

**Version:** 1.2  
**Direction:** Parksby -> Your server  
**Protocol:** HTTPS / REST  
**Authentication:** HMAC-SHA256 signature header

---

## Overview

Parksby webhooks tell your backend when something happens to a booking at one of your car parks: it is requested, confirmed or paid, the car arrives or leaves, the booking is extended, runs late, ends or is cancelled.

Add endpoints in Spaces (spaces.parksby.io) under **Developers → Webhooks**. Each endpoint belongs to one car park and receives only that car park's events, for the event types you tick.

---

## Endpoint (Your Server)

You provide an HTTPS URL, for example:

```text
https://api.yourcompany.com/webhooks/parksby
```

Parksby sends `POST` requests to it.

---

## Headers Sent By Parksby

| Header | Description |
|---|---|
| `Content-Type` | `application/json` |
| `X-Parksby-Timestamp` | When the request was sent, ISO 8601 UTC (e.g. `2026-11-21T10:00:00.000Z`) |
| `X-Parksby-Signature` | HMAC-SHA256 of the raw body, a dot and the timestamp, hex |
| `X-Parksby-Event-ID` | The event's UUID (same as `event_id` in the body) |

---

## Event types

| `event_type` | In Spaces | When |
|---|---|---|
| `booking.activated` | Booking confirmed | A booking is confirmed and active |
| `payment.confirmed` | Payment confirmed | A driver's payment for a booking is confirmed |
| `booking.checked_in` | Car arrived | The booked car arrived (checked in by the driver or by staff) |
| `booking.checked_out` | Car left | The booked car left |
| `booking.extended` | Booking extended | The driver extended their booking |
| `booking.expiring_soon` | Booking ending soon | A booking is about to end |
| `booking.overdue` | Booking overdue | The booking has ended but the car has not left |
| `booking.completed` | Booking completed | The booking is finished |
| `booking.cancelled` | Booking cancelled | The booking was cancelled |
| `booking.requested` | Reservation waiting | A reservation waits for you to accept or decline it (car parks that approve each one) |
| `booking.no_show` | No-show | You recorded that the driver did not come |
| `booking.marked_paid` | Marked paid | You marked a reservation paid (it was paid to you, not through Parksby) |

An endpoint with no event types ticked receives all of them.

---

## Payload Shape

```json
{
  "event_id": "4c16c6dd-b2ca-4208-91d2-26eb2b4834f3",
  "event_type": "booking.completed",
  "occurred_at": "2026-03-20T13:00:00.000Z",
  "data": {
    "booking_id": "...",
    "parking_id": "...",
    "tenant_id": "..."
  }
}
```

Field notes:

- `event_id`: globally unique event identifier. Use it for idempotency.
- `event_type`: one of the event types above.
- `occurred_at`: ISO timestamp when the event occurred.
- `data`: event-specific fields. Every booking event carries `booking_id` and `parking_id`; most also carry `tenant_id` (the driver), and some add times, the plate or status. Ignore fields you do not use — more may be added.

---

## Reservations

A reservation is a booking that is not paid in the Parksby app: the driver pays you at the car park, on your own payment page, or not at all. It sends the same webhooks as any booking, and every booking event says who takes the money in `data.payment_channel`:

| `payment_channel` | Who takes the money |
|---|---|
| `in_app` | Parksby, in the app |
| `on_site` | You, at the car park |
| `operator_link` | You, on your payment page (`data.payment_link`) |
| `free` | Nobody |

A reservation's events also carry `start_at`, `end_at`, `vehicle_plate`, `total_price` (your posted price, `0` when free), `currency`, `confirmed_at` (empty while it waits for you) and `marked_paid_at`.

The flow:

1. The driver reserves. If you approve each one, you get `booking.requested`; otherwise `booking.activated` (confirmed) straight away.
2. You accept or decline in Spaces (**Reservations**) or from your own system (below). Accepting sends `booking.activated`; declining sends `booking.cancelled` with `data.reason = "declined"`.
3. The car arrives (`booking.checked_in`) and leaves (`booking.completed`). If it never comes, record a no-show after the grace period (`booking.no_show`).
4. When the driver has paid you, mark it paid (`booking.marked_paid`). Parksby cannot see payments made to you, so this is the only payment confirmation.

### Reservations API

`POST https://api.parksby.io/v1/reservations`, signed with the car park's Reservations API credentials from Spaces (**Developers → Reservations API**: `X-Parksby-Integration-Id`, `X-Parksby-Timestamp` in ISO 8601 UTC, `X-Parksby-Signature` = hex HMAC-SHA256 of `body + "." + timestamp`). The body is one of:

```json
{ "action": "list", "from": "2026-11-21", "to": "2026-11-28" }
{ "action": "accept", "booking_id": "..." }
```

`list` returns the next 7 days by default (at most 31), each with a `state`: `pending`, `confirmed`, `lapsed`, `arrived`, `no_show`, `completed` or `cancelled`. The other actions are `accept`, `decline`, `cancel`, `no_show` and `mark_paid`; each returns the updated reservation. A wrong signature gets `401`.

---

## Signature Verification

Parksby signs the **raw JSON body**, a dot and the **timestamp header** with your endpoint's signing secret (shown in Spaces when you create the endpoint, and on its secret view). It is the same rule you use to call the Reservations API, so one function signs and verifies both.

```text
signature = hex( HMAC-SHA256(webhook_secret, raw_body + "." + X-Parksby-Timestamp) )
```

Important:

- Use the raw body bytes exactly as received, before any JSON parsing.
- The timestamp is part of the signature, so it cannot be changed. Drop deliveries older than 5 minutes, and rely on `event_id` to ignore replays.
- Before 2026-11-21 the signature covered the body only and the timestamp was Unix seconds.

### Node.js Example

```js
import crypto from "crypto";

function verifyParksbyWebhook(rawBody, timestampHeader, signatureHeader, secret) {
  const ts = String(timestampHeader ?? "");
  const age = Math.abs(Date.now() - Date.parse(ts));
  if (!(age <= 5 * 60 * 1000)) return false; // missing, malformed or stale
  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${rawBody}.${ts}`)
    .digest("hex");
  const received = String(signatureHeader ?? "");

  // timingSafeEqual throws when lengths differ, so check first.
  if (received.length !== expected.length) return false;
  return crypto.timingSafeEqual(Buffer.from(expected, "utf8"), Buffer.from(received, "utf8"));
}
```

### Python Example

```python
import hmac
import hashlib
from datetime import datetime, timezone


def verify_parksby_webhook(raw_body: bytes, timestamp_header: str, signature_header: str, secret: str) -> bool:
    try:
        sent = datetime.fromisoformat(timestamp_header.replace("Z", "+00:00"))
    except (AttributeError, ValueError):
        return False
    if abs((datetime.now(timezone.utc) - sent).total_seconds()) > 300:
        return False
    expected = hmac.new(
        secret.encode("utf-8"),
        raw_body + b"." + timestamp_header.encode("utf-8"),
        hashlib.sha256,
    ).hexdigest()
    return hmac.compare_digest(expected, signature_header or "")
```

---

## Delivery Semantics

- Delivery is successful when your endpoint returns **2xx**.
- `4xx` (except `429`) is treated as a permanent failure (no retries).
- `429`, `5xx`, and network failures are retried with backoff.
- Maximum attempts: **5**.
- Events can arrive out of order (a `booking.completed` before its `booking.requested`, or a retry after newer events). Order them by `occurred_at`, and treat each event as the latest news only if it is newer than what you have.

Retry backoff after each failed attempt:

- after attempt 1: 2 minutes
- after attempt 2: 4 minutes
- after attempt 3: 8 minutes
- after attempt 4: 16 minutes
- attempt 5 is the last

Delivery status and the last response code are shown per endpoint in Spaces → Webhooks.

---

## Idempotency Requirements

Your webhook consumer must be idempotent: a retry can deliver the same event twice.

Recommended approach:

1. Read `event_id` from the payload (or `X-Parksby-Event-ID`).
2. If already processed, return `200` immediately.
3. Otherwise process it and store `event_id` in your dedupe store.

---

## Recommended Receiver Behavior

1. Capture the raw body bytes.
2. Verify the HMAC signature.
3. Check the timestamp is recent.
4. Parse JSON only after the signature passes.
5. Check `event_id` for idempotency.
6. Process the event.
7. Return `200` quickly (do slow work after responding).

---

## Security Checklist

- Keep the signing secret in a server-side secret manager or environment variable.
- Never log secrets.
- Use HTTPS only.
- Verify the signature on every request.
- Drop stale timestamps and already-seen `event_id`s.

---

## Troubleshooting

- Signature mismatch:
  - Verify against the raw body bytes, not re-serialized JSON.
  - Check you use the endpoint's current secret (after rotating it in Spaces, update your backend too).
- Nothing arrives:
  - Check the endpoint is active (not paused) and belongs to the right car park.
  - Check the event types you ticked.
- High retry counts:
  - Check your endpoint's latency and non-2xx responses.
  - Make sure the endpoint is publicly reachable with a valid TLS certificate.
- Duplicate deliveries:
  - Expected under retries; enforce idempotency with `event_id`.
