#Webhooks
Antero Connect can call your system when something happens, so you do not have to ask again and again. There are two directions:
- Antero Connect calls you about your property: signed webhooks (this page).
- A channel calls Antero Connect with a booking: the channel's address.
#Antero Connect calls you
A webhook here is a nudge, not a message to trust or to build state from. It says: the feed has a new entry, number 42. When it arrives, read the feed. That way a webhook that is lost, late, doubled or out of order cannot make you wrong, because the feed is the truth. See Reservations.
#Register an address
export CHANNEL_MANAGER=https://api.anteromas.com # the address of your Channel Manager service
export KEY=cm_prod_ab12cd34_0123456789abcdef0123456789abcdef # your API key
curl -s -X POST "$CHANNEL_MANAGER/v1/properties/$PROPERTY_ID/webhook-endpoints" \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"url": "https://pms.example.com/hooks/channel-manager"
}
EOFimport os
import requests
CHANNEL_MANAGER = os.environ["CHANNEL_MANAGER"] # the address of your Channel Manager service
KEY = os.environ["KEY"] # your API key
r = requests.post(
f"{CHANNEL_MANAGER}/v1/properties/{PROPERTY_ID}/webhook-endpoints",
headers={"Authorization": f"Bearer {KEY}"},
json={
"url": "https://pms.example.com/hooks/channel-manager",
},
)
r.raise_for_status()
print(r.status_code, r.text)// Node.js 18 or newer (fetch is built in); save as a .mjs file
const CHANNEL_MANAGER = process.env.CHANNEL_MANAGER; // the address of your Channel Manager service
const KEY = process.env.KEY; // your API key
let r; // the last answer
r = await fetch(`${CHANNEL_MANAGER}/v1/properties/${PROPERTY_ID}/webhook-endpoints`, {
method: "POST",
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
url: "https://pms.example.com/hooks/channel-manager",
}),
});
if (!r.ok) throw new Error(await r.text());
console.log(r.status, await r.text());<?php
$CHANNEL_MANAGER = getenv("CHANNEL_MANAGER"); // the address of your Channel Manager service
$KEY = getenv("KEY"); // your API key
$ch = curl_init("{$CHANNEL_MANAGER}/v1/properties/{$PROPERTY_ID}/webhook-endpoints");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$KEY}", "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode([
"url" => "https://pms.example.com/hooks/channel-manager",
]),
]);
$out = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 400) { throw new RuntimeException($out); }
echo $status, " ", $out, "\n";{"id": "…", "url": "https://pms.example.com/hooks/channel-manager", "status": "active", "secret_fingerprint": "394f563012567397", "secret": "whsec_…"}- The address must be
https(in production), at most 500 characters, with no user name or password in it, and must not name a private or local place. secretis shown once. Keep it. Afterwards onlysecret_fingerprintcan be read. This call does not accept anIdempotency-Key, because its answer carries a secret.POST …/rotate-secretmakes a new secret (shown once).PATCHpauses or resumes a receiver;DELETEremoves it.
#What arrives
A POST to your address, with a JSON body and three headers:
POST /hooks/channel-manager HTTP/1.1
Content-Type: application/json
X-Channel-Manager-Event: reservation.feed
X-Channel-Manager-Delivery: 4b4dd4ba-a86e-5f6e-841e-23ed76f25234
X-Channel-Manager-Signature: t=1798772400,v1=3b5c…e91f{"id": "4b4dd4ba-…", "type": "reservation.feed", "property_id": "…", "seq": 42, "kind": "created",
"reservation_id": "…", "external_id": "KN-G6MSB7", "created_at": "2027-03-01T09:05:00Z"}The body carries no guest and no price: those are in the feed.
#Check the signature
X-Channel-Manager-Signature is t=<unix seconds>,v1=<hex>, where v1 is the HMAC-SHA256, with your secret as the key, of the text <t>.<raw body>. Check it on the raw bytes you received (not on re-encoded JSON), with a constant-time comparison, and refuse a t more than 5 minutes from your clock.
Python
import hashlib, hmac, time
def valid(secret: str, header: str, raw_body: bytes, tolerance=300) -> bool:
parts = dict(p.split("=", 1) for p in header.split(","))
t, v1 = parts.get("t", ""), parts.get("v1", "")
if not t.isdigit() or abs(time.time() - int(t)) > tolerance:
return False
want = hmac.new(secret.encode(), t.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(want, v1)Node.js
import { createHmac, timingSafeEqual } from "node:crypto";
export function valid(secret, header, rawBody, toleranceSeconds = 300) {
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
if (!/^\d+$/.test(parts.t ?? "") || Math.abs(Date.now() / 1000 - Number(parts.t)) > toleranceSeconds) return false;
const want = createHmac("sha256", secret).update(`${parts.t}.`).update(rawBody).digest("hex");
const got = Buffer.from(parts.v1 ?? "", "hex");
return got.length === want.length / 2 && timingSafeEqual(Buffer.from(want, "hex"), got);
}PHP
function valid(string $secret, string $header, string $rawBody, int $tolerance = 300): bool {
parse_str(str_replace(',', '&', $header), $p);
$t = $p['t'] ?? ''; $v1 = $p['v1'] ?? '';
if (!ctype_digit($t) || abs(time() - (int) $t) > $tolerance) return false;
return hash_equals(hash_hmac('sha256', $t . '.' . $rawBody, $secret), $v1);
}Go
func valid(secret, header string, body []byte, now time.Time) bool {
var t, v1 string
for _, p := range strings.Split(header, ",") {
k, v, _ := strings.Cut(p, "=")
if k == "t" { t = v } else if k == "v1" { v1 = v }
}
n, err := strconv.ParseInt(t, 10, 64)
if err != nil || now.Sub(time.Unix(n, 0)).Abs() > 5*time.Minute { return false }
m := hmac.New(sha256.New, []byte(secret))
m.Write([]byte(t + ".")); m.Write(body)
return hmac.Equal([]byte(hex.EncodeToString(m.Sum(nil))), []byte(v1))
}#Answer quickly, and with a 2xx
Answer within 10 seconds with any 2xx status. Anything else (or no answer) is a failed try. Do the real work after you answered: queue it and read the feed.
#When you do not answer
Antero Connect tries again with growing pauses: after the 1st failed try 1 minute, then 2, 4, 8, 16, 32 and 60 minutes. After 8 tries (a little over two hours) a delivery is dead and Antero Connect stops. It does not matter much: the next webhook, or your next read of the feed, brings you to the same place.
Delivery status | |
|---|---|
pending | waiting for its next try |
delivered | your system answered 2xx |
dead | gave up; can be replayed |
See the deliveries, with attempts and the last error:
curl -s -X GET "$CHANNEL_MANAGER/v1/webhook-endpoints/$ENDPOINT_ID/deliveries" \
-H "Authorization: Bearer $KEY"r = requests.get(
f"{CHANNEL_MANAGER}/v1/webhook-endpoints/{ENDPOINT_ID}/deliveries",
headers={"Authorization": f"Bearer {KEY}"},
)
r.raise_for_status()
print(r.status_code, r.text)r = await fetch(`${CHANNEL_MANAGER}/v1/webhook-endpoints/${ENDPOINT_ID}/deliveries`, {
method: "GET",
headers: { Authorization: `Bearer ${KEY}` },
});
if (!r.ok) throw new Error(await r.text());
console.log(r.status, await r.text());$ch = curl_init("{$CHANNEL_MANAGER}/v1/webhook-endpoints/{$ENDPOINT_ID}/deliveries");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$KEY}"],
]);
$out = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 400) { throw new RuntimeException($out); }
echo $status, " ", $out, "\n";Try a dead one again:
curl -s -X POST "$CHANNEL_MANAGER/v1/webhook-deliveries/$DELIVERY_ID/replay" \
-H "Authorization: Bearer $KEY"r = requests.post(
f"{CHANNEL_MANAGER}/v1/webhook-deliveries/{DELIVERY_ID}/replay",
headers={"Authorization": f"Bearer {KEY}"},
)
r.raise_for_status()
print(r.status_code, r.text)r = await fetch(`${CHANNEL_MANAGER}/v1/webhook-deliveries/${DELIVERY_ID}/replay`, {
method: "POST",
headers: { Authorization: `Bearer ${KEY}` },
});
if (!r.ok) throw new Error(await r.text());
console.log(r.status, await r.text());$ch = curl_init("{$CHANNEL_MANAGER}/v1/webhook-deliveries/{$DELIVERY_ID}/replay");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$KEY}"],
]);
$out = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 400) { throw new RuntimeException($out); }
echo $status, " ", $out, "\n";#Rules for your receiver
- Verify first, then act. An unsigned call, or one with a bad signature, is not from Antero Connect.
- Be idempotent. The same delivery can arrive twice (
X-Channel-Manager-Deliveryis its id). Reading the feed from your saved number makes duplicates harmless. - Do not build state from the body. Use it to learn when to read.
- Keep reading even without webhooks. Poll the feed now and then (every minute or two) as a safety net; a webhook is a faster way to come at the right time, not a replacement.
#A channel calls Antero Connect
Some channels send each booking to a web address. For such a connection:
curl -s -X POST "$CHANNEL_MANAGER/v1/channel-connections/$CONNECTION_ID/webhook" \
-H "Authorization: Bearer $KEY"r = requests.post(
f"{CHANNEL_MANAGER}/v1/channel-connections/{CONNECTION_ID}/webhook",
headers={"Authorization": f"Bearer {KEY}"},
)
r.raise_for_status()
print(r.status_code, r.text)r = await fetch(`${CHANNEL_MANAGER}/v1/channel-connections/${CONNECTION_ID}/webhook`, {
method: "POST",
headers: { Authorization: `Bearer ${KEY}` },
});
if (!r.ok) throw new Error(await r.text());
console.log(r.status, await r.text());$ch = curl_init("{$CHANNEL_MANAGER}/v1/channel-connections/{$CONNECTION_ID}/webhook");
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$KEY}"],
]);
$out = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status >= 400) { throw new RuntimeException($out); }
echo $status, " ", $out, "\n";returns a token once. Give the channel the path /hooks/<token> on your Antero Connect address as the place to post reservations. The token is the whole credential: anyone with it can post, so treat it like a key. GET …/webhook says whether one exists; DELETE makes the address answer 404; issuing again replaces the token.
What happens to a message: it is read, card numbers removed before anything is stored (the number is cut to its last four digits and the security code dropped), kept, and turned into a booking. The answer is 200 for everything Antero Connect could store, even a message it cannot understand yet, because a channel that sees errors may switch its webhook off. A bad token is 404, the same as no token. See what arrived with GET …/inbound-messages.