# Waymarq webhooks

Webhooks push events out of Waymarq as they happen. When a client accepts a quote, reports a
problem, or a task is finished, we send a signed HTTP request to a URL you control.

They are the outbound half of the platform. The [REST API](/api-docs) is the inbound half — you
call us. Between them you can keep another system in step with Waymarq without polling anything.

Anything that accepts an HTTPS URL works: your own backend, or Zapier, Make, n8n and similar.

---

## Setting one up

**Organisation settings → Integrations → New webhook.** You need to be an owner or admin.

You give it a name, a URL, and the events you care about. We generate a **signing secret** for you
— you don't invent one.

Then press **Send test**. That fires a real delivery down the exact same path production events
use, so if the test arrives correctly, so will everything else. Test deliveries are marked
`"test": true` in the payload and never count against your endpoint's health.

### URLs

`https://` is required for anything reachable from the internet, because these payloads contain
real client and project data.

`http://` is accepted **only for local addresses** — `localhost`, `127.0.0.1`, private ranges
(`10.x`, `192.168.x`, `172.16–31.x`) and the reserved development domains (`.test`, `.local`,
`.localhost`, `.internal`). That's so you can develop against your own machine without setting up
a tunnel. A public `http://` URL is refused.

---

## What a delivery looks like

Every request is a `POST` with a JSON body:

```json
{
  "event": "task.completed",
  "sent_at": "2026-07-19T20:31:09+00:00",
  "test": false,
  "data": {
    "task": { "id": 5, "code": "WR-5", "title": "Visual design", "status": "done" },
    "project": { "id": 1, "name": "Website Redesign" },
    "completed_by": { "id": 2, "name": "Demo Owner" }
  }
}
```

The envelope (`event`, `sent_at`, `test`, `data`) is the same for every event. Only `data` differs.

### Headers

| Header | Meaning |
| --- | --- |
| `X-Waymarq-Event` | The event name, so you can route without parsing the body |
| `X-Waymarq-Timestamp` | Unix timestamp the request was signed at |
| `X-Waymarq-Signature` | `sha256=` followed by the HMAC (see below) |
| `User-Agent` | `Waymarq-Webhooks/1` |

---

## Verifying the signature

**Do this before trusting anything in the payload.** Your endpoint is a public URL; the signature
is what proves a request came from us and not from someone who found it.

The signature is an HMAC-SHA256 of the timestamp and the raw body joined by a full stop:

```
signature = "sha256=" + hmac_sha256(secret, timestamp + "." + raw_body)
```

Two things matter:

- **Use the raw request body**, exactly as received. If you parse the JSON and re-encode it, key
  order or whitespace can change and the signature won't match.
- **Compare in constant time.** A normal string comparison leaks information about how much of the
  signature was correct.

### PHP

```php
$raw = file_get_contents('php://input');
$timestamp = $_SERVER['HTTP_X_WAYMARQ_TIMESTAMP'] ?? '';
$signature = $_SERVER['HTTP_X_WAYMARQ_SIGNATURE'] ?? '';

$expected = 'sha256=' . hash_hmac('sha256', $timestamp . '.' . $raw, $secret);

if (! hash_equals($expected, $signature)) {
    http_response_code(401);
    exit;
}

// Reject anything old, so a captured request can't be replayed at you later.
if (abs(time() - (int) $timestamp) > 300) {
    http_response_code(401);
    exit;
}

$payload = json_decode($raw, true);
```

### Node

```js
import crypto from 'node:crypto';

// express.raw({ type: 'application/json' }) — you need the unparsed body
function verify(rawBody, headers, secret) {
    const timestamp = headers['x-waymarq-timestamp'];
    const expected =
        'sha256=' + crypto.createHmac('sha256', secret).update(`${timestamp}.${rawBody}`).digest('hex');

    const received = headers['x-waymarq-signature'] ?? '';
    const ok =
        expected.length === received.length &&
        crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(received));

    return ok && Math.abs(Date.now() / 1000 - Number(timestamp)) < 300;
}
```

### Python

```python
import hmac, hashlib, time

def verify(raw_body: bytes, headers, secret: str) -> bool:
    timestamp = headers.get("X-Waymarq-Timestamp", "")
    signed = f"{timestamp}.".encode() + raw_body
    expected = "sha256=" + hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()

    if not hmac.compare_digest(expected, headers.get("X-Waymarq-Signature", "")):
        return False

    return abs(time.time() - int(timestamp)) < 300
```

---

## Responding

**Reply with any 2xx status.** Anything else counts as a failure.

Reply *quickly* — acknowledge first, do the work afterwards. We time out after **10 seconds**, and
a slow endpoint will eventually be treated as a broken one. If the work takes real time, put the
payload on your own queue and return `200` immediately.

The response body is stored in your delivery log (up to 8,000 characters), so a short error message
in the body is genuinely useful to you later.

---

## Retries and failure

A failed delivery is retried **3 times**, backing off **1 minute → 5 minutes → 15 minutes**. That
covers the usual causes — a deploy, a brief outage — without hammering an endpoint that's already
struggling.

After **10 consecutive failures**, the endpoint is **switched off**. It stays in your list with its
failure count visible so you can see what happened; fix the endpoint, edit it, and set it active
again. Re-enabling resets the counter.

This is deliberate: silently dropping events forever would be worse than visibly stopping.

### Delivery may not be exactly once

A retry can duplicate an event your endpoint actually received but failed to acknowledge in time.
**Make your handler idempotent** — key off the ids in `data` and ignore something you've already
processed.

Order isn't guaranteed either. Two events fired close together may arrive in either order.

---

## The delivery log

**Integrations → your webhook → Delivery log.** Every attempt records what we sent and what came
back: the full request payload, the status code, the response body, any connection error, how long
it took, and which attempt it was.

Logs are kept for **30 days**. Each entry stores complete request and response bodies, so retaining
them indefinitely would grow without limit for no real benefit — nobody debugs a delivery from
three months ago.

---

## Events

| Event | Fires when |
| --- | --- |
| `quote.accepted` | A client accepts a quote through its public link |
| `support_ticket.received` | Something arrives through a client support link, before triage |
| `project.status_changed` | A project moves between planning, active, on hold, completed, archived |
| `task.completed` | A task moves to done |
| `payment.received` | A scheduled payment on a project is marked as received |
| `opportunity.stage_changed` | A deal moves along the pipeline, including won and lost |

Only meaningful moments are published. There is deliberately no event for every field edit — that
would be noise you'd immediately have to filter, and each event is a contract we then keep stable.

### `quote.accepted`

Fires after the opportunity is won, so the project it created is already available.

```json
{
  "quote": { "id": 3, "number": "Q-0003", "total": 7200 },
  "opportunity": { "id": 8, "title": "E-commerce rebuild", "pipeline_stage": "won" },
  "client": { "id": 4 },
  "created_project_id": 12
}
```

### `support_ticket.received`

Fires as soon as the request is stored — before any AI triage — so a subscriber routing it onward
never waits on us.

```json
{
  "ticket": {
    "id": 14,
    "subject": "Checkout page errors on mobile",
    "body": "Since this morning the basket page 500s.",
    "urgency": "high",
    "status": "new",
    "reporter_name": "Dani Okafor",
    "reporter_email": "dani@acme.test"
  },
  "client": { "id": 7 }
}
```

### `project.status_changed`

```json
{
  "project": { "id": 1, "name": "Website Redesign", "status": "active" },
  "previous_status": "planning"
}
```

### `task.completed`

Only completion is published — not every intermediate move.

```json
{
  "task": { "id": 5, "code": "WR-5", "title": "Visual design", "status": "done" },
  "project": { "id": 1, "name": "Website Redesign" },
  "completed_by": { "id": 2, "name": "Demo Owner" }
}
```

### `payment.received`

Fires when a scheduled payment is recorded as arrived, from the app or through the API. The natural
subscriber is an accounting integration reconciling what's been settled.

```json
{
  "payment_term": {
    "id": 3,
    "description": "Deposit",
    "amount_received": 5000,
    "payment_reference": "BACS 4471",
    "paid_at": "2026-07-19T12:04:11+00:00"
  },
  "project": { "id": 12, "name": "E-commerce rebuild" }
}
```

### `opportunity.stage_changed`

`created_project_id` is populated only on the transition that wins the deal, since winning creates
the project. It is `null` otherwise.

```json
{
  "opportunity": { "id": 8, "title": "E-commerce rebuild", "pipeline_stage": "won", "value": 24000 },
  "previous_stage": "negotiating",
  "client": { "id": 4 },
  "created_project_id": 12
}
```

---

## Zapier, Make and n8n

Nothing special is needed for these — each gives you a URL to send to, which is all a webhook
endpoint wants. There's no listed Waymarq app in their directories, so you paste a URL rather than
picking us from a menu.

**Catching a Waymarq event:**

1. Start a new zap / scenario / workflow with a webhook trigger:
   - **Zapier** — *Webhooks by Zapier* → *Catch Hook*
   - **Make** — *Webhooks* → *Custom webhook*
   - **n8n** — the *Webhook* node, and use its **production** URL, not the test one, which stops
     listening when you close the editor
2. Copy the URL it shows you.
3. In Waymarq, add an endpoint with that URL, leave the format as **Waymarq**, and choose your
   events.
4. Press **Send test**.

Do step 4 before you build the rest of the scenario. All three learn the shape of a payload from
one they've actually received, and until they have one there's nothing to map fields against.

The test payload carries `"test": true`, so if the scenario does something consequential — raising
an invoice, messaging a client — branch on that field rather than discovering the difference later.

**Verifying the signature** is worth doing on any scenario that acts on the data, and none of the
three do it for you. The URLs are unguessable but not secret, and anyone holding one can post
whatever they like to it. In Make and n8n you have the tools to compute an HMAC inline; in Zapier
it needs a Code step. The verification examples above translate directly — the rule that matters is
the same everywhere: hash the **raw body** exactly as it arrived, before anything parses and
re-encodes it.

**Going the other way** — an automation creating or updating something in Waymarq — is the
[REST API](/api-docs), not webhooks. Use an HTTP request module with your API token as an
`Authorization: Bearer` header. This is the half people usually want for moving work in from a
form, an inbox, or a tracker they haven't finished leaving.

---

## Testing locally

Because `http://` is allowed for local addresses, you can point a webhook straight at your own
machine — no tunnel needed.

```php
// receiver.php — php -S 127.0.0.1:9099 receiver.php
$raw = file_get_contents('php://input');
file_put_contents('received.json', $raw);
header('Content-Type: application/json');
echo '{"ok":true}';
```

Create a webhook pointing at `http://127.0.0.1:9099`, press **Send test**, and check both
`received.json` and the delivery log.

---

## Common problems

**Signature never matches.** You're almost certainly verifying against a re-encoded body. Capture
the raw bytes before any JSON middleware touches them.

**Deliveries stopped arriving.** Check whether the endpoint switched itself off after 10 failures —
the delivery log will show what was failing. Fix, then set it active again.

**Timeouts.** Return `200` first and do the work asynchronously. Ten seconds is the limit.

**Duplicate events.** Expected behaviour on retry. Key off the ids and ignore repeats.

---

## Questions

[Get in touch](/contact) — say what you're building and which events you're using, and include a
delivery id from the log if something specific went wrong.
