Webhooks
Crux can emit webhooks for certain events. This allows you to develop integrations with Crux that are notified when certain events occur.
Webhook Typesβ
We have two types of webhook types, user and gym webhooks.
User webhooks pertain to your own user and are triggered when you do different things on Crux. You can only register user webhooks for yourself.
Gym webhooks pertain to a specific gym and can be triggered by anyone at the gym. There are two ways to have one:
- Owned by the gym. Gym admins register these in the gym's settings, and they're managed by all of the gym's admins.
- Owned by you. Anyone can register a gym webhook of their own for a gym they've opened in Crux (and, for a private gym, are still allowed to see). It belongs to you: it's listed with your webhooks, not in the gym's settings. It only receives what you could see in the app, so not other climbers' draft climbs or sends by climbers who hide their profile.
A registration's owner_type says who owns it, and its scope_type says where its events come from (User for your own events, Gym for a gym's, with the gym in gym_url_slug).
Registering a webhookβ
In the app: to register a webhook of your own, head to the user settings and tap User webhooks, then choose whether it gets My activity or the events at one of your gyms. To register a gym-owned webhook, head to the gym settings and tap Gym webhooks.
With the API: register a webhook of your own with your API key, without anyone opening the app:
# Your own events
curl -X POST https://www.cruxapp.ca/api/v1/webhook_registrations \
-H "Authorization: Bearer $CRUX_API_KEY" -H "Content-Type: application/json" \
-d '{"url": "https://example.com/crux", "event_type": "climb.sent"}'
# A gym's events
curl -X POST https://www.cruxapp.ca/api/v1/webhook_registrations \
-H "Authorization: Bearer $CRUX_API_KEY" -H "Content-Type: application/json" \
-d '{"url": "https://example.com/crux", "event_type": "climb.deactivated", "gym_slug": "your-gym"}'
The response is the new registration, including its signing_secret. Delete one with DELETE /api/v1/webhook_registrations/:id, and list yours with GET /api/v1/users/me/webhook_registrations. See the API reference for details.
Webhooks must be registered with a publicly accessible http or https endpoint. URLs that point at private, loopback or other internal addresses (localhost, 10.x.x.x, 192.168.x.x, 169.254.169.254, fc00::/7 and the like) aren't accepted, and a delivery is refused if the host resolves to one.
Each webhook has a signing secret. Copy it from the webhook list (the key icon), or read it as signing_secret from the webhook_registrations APIs.
Webhook Deliveryβ
Webhook events are delivered via POST request to the URL you provided. The body of the request will be a JSON object containing the event data.
Return any 2xx response to acknowledge receipt of the webhook. If you don't, the delivery is retried up to 3 times before failing.
All webhook deliveries have a timeout of 5 seconds. Redirects aren't followed.
Each delivery is sent with these headers:
| Header | Value |
|---|---|
Content-Type | application/json |
User-Agent | Crux-Webhooks |
X-Crux-Delivery-Id | The delivery's ID. The same ID is sent again if the delivery is retried. |
X-Crux-Signature | t=<unix time>,v1=<signature> (see below) |
Verifying deliveriesβ
Anyone can send a request to your endpoint, so check the X-Crux-Signature header before trusting a delivery:
- Split the header on
,intot(a Unix timestamp) andv1(the signature). - Compute the HMAC-SHA256 of
<t>.<raw request body>with your webhook's signing secret, as a lowercase hex string. Use the raw body exactly as received, before parsing the JSON. - Compare it with
v1in constant time. - Reject the delivery if
tis more than a few minutes old, so a captured request can't be replayed later.
// Node.js (Express): app.post("/crux", express.raw({ type: "application/json" }), handler)
const crypto = require("crypto");
function verifyCruxSignature(rawBody, header, secret, toleranceSeconds = 300) {
const parts = Object.fromEntries(header.split(",").map((part) => part.split("=", 2)));
const timestamp = Number(parts.t);
if (!timestamp || !parts.v1) return false;
if (Math.abs(Date.now() / 1000 - timestamp) > toleranceSeconds) return false;
const expected = crypto.createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest("hex");
return expected.length === parts.v1.length &&
crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}
# Python
import hashlib, hmac, time
def verify_crux_signature(raw_body: bytes, header: str, secret: str, tolerance_seconds: int = 300) -> bool:
parts = dict(part.split("=", 1) for part in header.split(",") if "=" in part)
if "t" not in parts or "v1" not in parts or not parts["t"].isdigit():
return False
if abs(time.time() - int(parts["t"])) > tolerance_seconds:
return False
expected = hmac.new(secret.encode(), parts["t"].encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])
# Ruby
require "openssl"
def verify_crux_signature(raw_body, header, secret, tolerance_seconds: 300)
parts = header.to_s.split(",").to_h { |part| part.split("=", 2) }
timestamp = parts["t"].to_s
return false unless timestamp.match?(/\A\d+\z/) && parts["v1"]
return false if (Time.now.to_i - timestamp.to_i).abs > tolerance_seconds
expected = OpenSSL::HMAC.hexdigest("SHA256", secret, "#{timestamp}.#{raw_body}")
OpenSSL.fixed_length_secure_compare(expected, parts["v1"]) rescue false
end
Delivery Introspectionβ
We do not currently have a UI to view details about webhook deliveries. You can view details about recent delivery attempts via the webhook_registrations APIs however. A failed delivery's error is a short reason (for example HTTP 500, Timed out or Refused: β¦); your endpoint's response body isn't recorded.
Available Webhook Eventsβ
Gym Eventsβ
climb.activatedβ
This event is triggered when a climb is made active on a gym wall, including when the active climb is made active again (at another angle, on an adjustable wall:
active_climb_anglein the payload is the new angle).Returns a WebhookDelivery object with a
payloadfield of type Climb (full).
climb.createdβ
This event is triggered when any climb is created at the gym.
Returns a WebhookDelivery object with a
payloadfield of type Climb (full).
climb.deactivatedβ
This event is triggered when a climb stops being the active climb on a gym wall: it was deactivated, or another climb was activated in its place. On an adjustable wall, also when the active climb is made active again at another angle (
climb.activatedfollows, with the new angle).active_climb_angleis null in this payload.Returns a WebhookDelivery object with a
payloadfield of type Climb (full).
climb.sentβ
This event is triggered when any climb at the gym is sent by any climber.
Returns a WebhookDelivery object with a
payloadfield of type Send (full).
climb.updatedβ
This event is triggered when any climb is updated at the gym.
Returns a WebhookDelivery object with a
payloadfield of type Climb (full).
gym_wall.createdβ
This event is triggered when a gym wall is created at the gym.
Returns a WebhookDelivery object with a
payloadfield of type GymWall.
User Eventsβ
climb.createdβ
This event is triggered when a climb is set by the user.
Returns a WebhookDelivery object with a
payloadfield of type Climb (full).
climb.sentβ
This event is triggered when a climb is sent by the user.
Returns a WebhookDelivery object with a
payloadfield of type Send (full).
climb.viewedβ
This event is triggered when a climb is viewed by the user in the Crux app. Specifically, the event is triggered when the user taps on a climb in the climb directory or a climb list to view it.
Returns a WebhookDelivery object with a
payloadfield of type Climb (full).