Webhooks
Create webhooks from the API, test them, and react to every step of a plan, from optimization to proof of delivery. Retries, delivery log and replay included.
Webhooks let Routal notify your systems when something changes, without you polling. Subscribe an endpoint to one or more event types and Routal will POST a JSON envelope to it.
Webhooks are configured per project. Manage them through the API (see Manage webhooks through the API) or in the planner dashboard at planner.routal.com/h/settings/developers/webhooks. Both change the same webhooks.
The full cycle
A complete integration hears about every step of the day without asking. This is the order the events arrive in, and what your integration usually does with each one:
Your system Routal API Webhook to your endpoint
─────────── ────────── ────────────────────────
Setup (once) ──▶ POST /v2/webhook
POST /v2/webhook/{id}/test ──▶ sample event (no id)
Plan the day ──▶ POST /v2/plan ──▶ plan.created
POST /v2/stops ──▶ stop.created (one per stop)
Optimize ──▶ POST /v2/plan/{id}/optimize/async (returns at once)
──▶ optimization.succeeded
or optimization.failed
On succeeded ──▶ GET /v2/plan/{id}/routes
POST /v2/route/{id}/dispatch
Execution (drivers) ──▶ route.started
──▶ stop.reported (one per report)
──▶ route.finished
Reconcile (nightly) ──▶ GET /v2/webhook/{id}/events?status=error
POST /v2/webhook/event/{event_id}/resendThe two signals that matter most:
routal.optimizer.2.optimization.succeededreplaces polling afterPOST /v2/plan/{id}/optimize/async. When it arrives the routes are saved: read them and dispatch.routal.planner.2.stop.reportedcarries the outcome of every visit (completed, attempted, canceled) with its proof of delivery. It is the event that closes orders in your ERP, OMS or CRM.
Every recipe follows this cycle with the events its scenario needs, in cURL, TypeScript and Python.
Configuration
A webhook record has three fields you control:
| Field | Type | Description |
|---|---|---|
url | string | The endpoint that will receive the POST. It must be reachable from the internet: localhost, private, loopback and link-local addresses, internal hostnames (.local, .internal, .svc, single-label names) and URLs with credentials (https://user:pass@…) are rejected with highway.webhook.error.invalid_url. A token in the query string is fine. Use https://. |
enabled_events | string[] | The event types this webhook should fire for (see Event catalog). |
enabled | boolean | Whether the webhook is active. Disabled webhooks receive nothing. |
A single project can have multiple webhooks, each subscribed to a different subset of events.
Manage webhooks through the API
The webhook endpoints take the same private_key as the rest of the API. Your Routal plan must include webhooks, or you get a 403. The key's user also needs permission to manage developer settings, or you get a 400 with highway.user.error.invalid_credentials.
| Endpoint | What it does |
|---|---|
POST /v2/webhook?project_id=... | Create a webhook in a project. |
GET /v2/webhooks?project_id=... | List the project's webhooks, enabled or not, with their failure_count. |
PUT /v2/webhook/{id} | Replace url, enabled_events and enabled. enabled_events is replaced as a whole, not merged. |
DELETE /v2/webhook/{id} | Delete a webhook. Pending retries are dropped. Set enabled: false instead to pause it. |
POST /v2/webhook/{id}/test | Send a sample event of a given type to the webhook's URL. |
GET /v2/webhook/{id}/events | Read the delivery log: one entry per attempt, with the body sent and your endpoint's answer. |
POST /v2/webhook/event/{event_id}/resend | Send a past delivery again, with the same body and id. |
Create a webhook, then check that your endpoint answers:
curl -X POST 'https://api.routal.com/v2/webhook?private_key=YOUR_KEY&project_id=YOUR_PROJECT_ID' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://your-host.example.com/webhooks/routal?token=YOUR_SECRET",
"enabled_events": ["routal.planner.2.stop.reported", "routal.drivers.2.route.finished"],
"enabled": true
}'
curl -X POST 'https://api.routal.com/v2/webhook/WEBHOOK_ID/test?private_key=YOUR_KEY' \
-H 'Content-Type: application/json' \
-d '{ "event_type": "routal.planner.2.stop.reported" }'The test call fails unless your endpoint answers 2xx within 10 seconds. A test event carries example data, has no id, sends project_id inside meta, and is not retried or written to the delivery log.
Creating a webhook is not idempotent: two POST /v2/webhook calls create two webhooks, and each delivers its own copy of every event. If your integration sets up its webhook on deploy, list them first with GET /v2/webhooks and update the existing one.
Delivery
When a subscribed event happens, Routal sends an HTTPS POST to your url with a JSON body. There are no custom Routal headers today: no X-Routal-Signature, no X-Routal-Event, no distinguishing User-Agent. Identify the call by the body's id, event_id and project_id, not by headers.
Envelope
{
"id": "6701c2e9f4a3b2c1d0e9f8a7",
"created_at": "2026-05-21T10:30:00.000Z",
"project_id": "4f75d991ac359f8c4c79d762",
"event_id": "routal.planner.2.plan.created",
"meta": { /* event metadata */ },
"data": { /* event payload */ }
}| Field | Type | Description |
|---|---|---|
id | string | Unique identifier of the event. It is the same on every delivery of that event, retries included, so use it to drop duplicates. |
created_at | ISO 8601 string | When the event was emitted server-side. Use it to order events. |
project_id | string | The project the event belongs to. Useful if you proxy multiple projects through a single endpoint. |
event_id | string | The event type (despite the name). One of the values in the Event catalog. |
meta | object | Event-type-specific metadata. Schema varies by event_id. |
data | object | Event-type-specific payload: the resource that changed. Schema varies by event_id. |
event_id is the event type, not an identifier: every plan.created event has the same event_id. The identifier of the event is id.
Event catalog
These are the ten event types currently delivered to webhooks:
event_id | When it fires | data |
|---|---|---|
routal.planner.2.plan.created | A plan was created. | The plan. |
routal.planner.2.plan.updated | A plan was updated (metadata, status, or contents). | The plan. |
routal.planner.2.plan.deleted | A plan was deleted. | The plan. |
routal.planner.2.stop.created | A stop was created, from the API, the planner or the driver app. | The stop. |
routal.planner.2.stop.deleted | A stop was deleted. | The stop. |
routal.planner.2.stop.reported | A stop received a report (proof of delivery, completion, or failure). | The stop, with its reports. The newest report is the last one. |
routal.drivers.2.route.started | A driver opened the route in the driver app. | The route, with its stops. |
routal.drivers.2.route.finished | A driver marked the route finished. | The route, with its stops. |
routal.optimizer.2.optimization.succeeded | An optimization of a plan or a route finished. The optimized plan is already saved when the event is sent. | The run, and the plan. |
routal.optimizer.2.optimization.failed | An optimization of a plan or a route failed. | The run, and the error. |
Optimization events
The optimization events carry no meta; data describes the run:
| Field | In | Description |
|---|---|---|
result | both | The optimizer's result for the run. |
duration | both | How long the run took. |
routes | both | Number of routes in the run. |
live | both | Whether it was a live optimization, respecting routes already in progress. |
keep_current_assignment | both | Whether stops kept their current route. |
traffic | both | Whether traffic was taken into account. |
plan | succeeded | The optimized plan. |
error | failed | What went wrong. |
optimization.succeeded is the completion signal for POST /v2/plan/{id}/optimize/async: dispatch when it arrives instead of polling the routes (see Lifecycle). data.plan.id tells you which plan finished; read its routes with GET /v2/plan/{id}/routes before dispatching, since the event says how the run went, not where each stop ended up.
Both events also fire for runs someone started from the planner or from the MCP server. Keep a record of the runs your integration started and only dispatch those.
optimization.failed does not carry the plan id today. When it arrives, check the runs you are still waiting on (their plans keep the routes they had) and alert. If someone cancels a run from the planner, neither event is sent, so give every run you start a timeout as well.
routal.planner.2.stop.moved, routal.planner.2.route.created and routal.planner.2.route.deleted are accepted in enabled_events but not delivered today: a webhook subscribed to them receives nothing for those events.
More domain events fire inside Routal (route updates, vehicle CRUD, etc.) but are not delivered via webhooks today. If you need one of them for your integration, tell us.
Acknowledgement
Your endpoint should respond with any 2xx HTTP status code within 10 seconds. Anything else counts as a failed delivery, and so does a response that takes longer: Routal stops waiting at 10 seconds.
Answer first and do the work afterwards: put the event on a queue of your own and return 2xx straight away. A handler that does the work before answering risks the timeout, and a timeout is retried even if your handler finished the work.
Retries and failure handling
A delivery that fails for a reason that may be temporary is tried again, up to three more times:
| Attempt | When |
|---|---|
| 1st | As soon as the event happens. |
| 2nd | 1 minute after the 1st fails. |
| 3rd | 5 minutes after the 2nd fails. |
| 4th | 30 minutes after the 3rd fails. |
Retried: a timeout, a connection error (refused, reset, DNS), and a 408, 429 or 5xx response.
Not retried: any other 4xx. Routal takes it as your endpoint deliberately refusing the event, and asking again would get the same answer.
Every retry carries exactly the same body as the first attempt, id included. If you change the webhook's URL while an event is waiting for a retry, the retry goes to the new URL; if you disable the webhook or unsubscribe it from that event type, the retry is dropped.
Lost events and disable
An event is lost when its 4th attempt fails, or when your endpoint rejects it with a 4xx. Failures are counted per webhook in failure_count, which counts lost events, not attempts, and resets on the first successful delivery.
| Threshold | What happens |
|---|---|
| 5 lost events in a row | Routal sends an email to the organization owner warning that the webhook is failing. |
| 50 lost events in a row | The webhook is automatically disabled (enabled is set to false) and another email is sent to the owner. Future events are not delivered until you re-enable it, from the dashboard or with PUT /v2/webhook/{id} and enabled: true. Re-enabling resets failure_count. |
Every attempt, successful or not, appears in the webhook's delivery log: in the planner dashboard, or through GET /v2/webhook/{id}/events. You can replay a lost event by hand from the dashboard or with POST /v2/webhook/event/{event_id}/resend, using the id of its entry in the log. A replay sends the same body, with the same id.
Replay missed events every night
A deploy at the wrong minute or an outage longer than the retry window loses events. A nightly job closes that gap:
# 1. Yesterday's failed attempts. Filter with status and date, page with
# offset and limit (up to 100) until hasNextPage is false.
curl "https://api.routal.com/v2/webhook/WEBHOOK_ID/events?private_key=YOUR_KEY&status=error&date=2026-05-21&limit=100"
# 2. Resend each one your system never processed, by the id of its log entry.
curl -X POST "https://api.routal.com/v2/webhook/event/LOG_ENTRY_ID/resend?private_key=YOUR_KEY"Each log entry carries the body that was sent in data.payload_sent, with its
id. An event that failed and then got through on a retry has both an error
and a success entry, so check your table of processed ids before resending.
Because a resend keeps the id, running the job twice is harmless.
Idempotency
Webhooks are delivered at least once: the same event can reach your endpoint more than once. That happens when:
- Your endpoint did the work but Routal did not get a
2xxback. It answered after 10 seconds, the connection dropped before the response arrived, or it answered5xxafter doing part of the work. Routal cannot tell this apart from an event that never arrived, so it tries again. - A delivery is repeated on Routal's side. Rarely, an event is sent again after a restart of the service that delivers it.
- Someone replays the event from the delivery log, in the dashboard or through the API.
In every case the repeated delivery carries the same id, so deduplicate on it:
- Keep the
ids you have processed and skip a delivery whoseidyou have already seen. Keep them for at least a day: retries stop after about 36 minutes, but a manual replay can come later. - Make the handler naturally idempotent where you can. "Set the stop to completed" is safe to run twice; "add one to the completed count" is not.
A receiver that answers in time and leaves the work, and the dedup, to a worker:
app.post('/webhooks/routal', express.json({ limit: '10mb' }), async (req, res) => {
if (req.query.token !== process.env.ROUTAL_WEBHOOK_TOKEN) return res.sendStatus(401); // not retried
const event = req.body;
if (!event.id) return res.sendStatus(200); // test event: acknowledge, don't process
await queue.add(event); // durable queue; if this throws, the 500 makes Routal retry
res.sendStatus(200); // within 10 seconds
});
// Worker
async function handle(event) {
if (await processed.has(event.id)) return; // a retry, a replay or a redelivery
// ... your logic, by event.event_id ...
await processed.add(event.id);
}If one URL receives more than one webhook (for example, two webhooks in the same project pointing to the same endpoint), each webhook delivers its own copy of the event, with the same id.
Ordering
Events are not guaranteed to arrive in order. A retried event can arrive after newer events about the same resource: a stop.reported that needed a retry can land after a later plan.updated.
Use created_at to order events, and do not let an older event overwrite newer state. A common pattern is to store the created_at of the last event you applied to each resource and skip any event older than that.
Signature verification
Routal does not sign webhook payloads today. There is no HMAC, no X-Routal-Signature header, no shared secret stored on the webhook record. If you need to authenticate that a request came from Routal, options today:
- IP allowlist. Restrict your endpoint to accept only requests from Routal's egress IPs (ask support for the current list).
- Secret in the URL. Subscribe a URL containing an opaque token, e.g.
https://your-host/webhooks/routal?token=.... Verify the token server-side. Lower-trust than HMAC but workable. - mTLS or VPC private link. If you have stronger requirements, talk to us.
Signed deliveries with HMAC-SHA256 are on the roadmap.
Local development
To test webhooks against a local server, use a tunnel like ngrok or Cloudflare Tunnel to expose your localhost URL: Routal rejects localhost and private addresses. Subscribe the tunnel URL with POST /v2/webhook or from the planner dashboard, then send it a sample event with POST /v2/webhook/{id}/test.
What's not supported today
- HMAC signing: see above.
- Configurable retries: the retry schedule and the 10-second timeout are the same for every webhook.
- Webhook events for routes (
route.created/updated/deleted) and stops other than created/deleted/reported: not delivered today, even thoughstop.moved,route.createdandroute.deletedcan be subscribed. - Webhook events for vehicles: not delivered today.
When any of the above ships, the changelog is the canonical place to find out.
