Box webhooks (v2): create, list, get, update and delete webhooks on a file or folder, and verify the deliveries Box signs.

Verification. Box signs each delivery with both of the app's webhook signature keys (Developer Console → your app → Webhooks → Manage signature keys): BOX-SIGNATURE-PRIMARY and BOX-SIGNATURE-SECONDARY are the base64 HMAC-SHA256 of the raw body followed by the BOX-DELIVERY-TIMESTAMP value. A delivery verifies when either signature matches its key (so keys can be rotated one at a time), the version is 1 and the algorithm HmacSHA256, and the timestamp is at most 10 minutes old (and not more than a minute in the future). Comparisons are constant time; a missing key, header or timestamp fails closed. Set box.webhook.primary-key and box.webhook.secondary-key in Context Variables.

Box retries a delivery that does not get a 2xx within 30 seconds, up to 10 times over about a day, so make handlers idempotent (the payload id identifies a delivery). An app can have 1,000 webhooks per user per app, and one webhook per item per trigger set.

HttpResponse ::hot::http/HttpResponse

box-webhook
meta {webhook: {service: "box", path: "/box/webhook"}}
fn (request) {
  cond {
    not(::box::webhooks/verify-request(request)) => {
      HttpResponse({status: 401, body: "invalid signature"})
    }
    => {
      event ::box::webhooks/parse-delivery(request)
      println(`${event.trigger} ${event.source.id}`)
      HttpResponse({status: 200, body: "ok"})
    }
  }
}

Context Vars

Optional
  • box.webhook.primary-key
  • box.webhook.secondary-key

Values

DEFAULT_MAX_AGE_SECONDS

DEFAULT_MAX_AGE_SECONDS: Int 600

MAX_FUTURE_SKEW_SECONDS

MAX_FUTURE_SKEW_SECONDS: Int 60

SIGNATURE_ALGORITHM

SIGNATURE_ALGORITHM: Str "HmacSHA256"

SIGNATURE_VERSION

SIGNATURE_VERSION: Str "1"

TARGET_TYPES

TARGET_TYPES: Vec [
  "file",
  "folder"
]

Functions

create-webhook

fn (target-type: Str, target-id: Str, address: Str, triggers: Vec): Map
fn (target-type: Str, target-id: Str, address: Str, triggers: Vec, opts: Map): Map

POST /webhooks - notify address (an HTTPS URL that answers within 30 seconds) when triggers fire on a file or folder (target-type "file" or "folder"). Folder webhooks cover everything inside the folder. Returns the webhook (id, target, address, triggers).

hook ::box::webhooks/create-webhook("folder", "12345", "https://example.hot.dev/box/webhook", ["FILE.UPLOADED", "FILE.TRASHED"])
hook.id

delete-webhook

fn (webhook-id: Str): Bool
fn (webhook-id: Str, opts: Map): Bool

DELETE /webhooks/{id} - delete a webhook. Returns true.

Example

::box::webhooks/delete-webhook("789")

get-webhook

fn (webhook-id: Str): Map
fn (webhook-id: Str, opts: Map): Map

GET /webhooks/{id} - one webhook.

Example

hook ::box::webhooks/get-webhook("789")
hook.triggers

list-all-webhooks

fn (): Vec
fn (opts: Map): Vec

Every webhook the app has for the current user (all marker pages).

Example

hooks ::box::webhooks/list-all-webhooks()
map(hooks, %.id)

list-webhooks

fn (): Map
fn (opts: Map): Map

GET /webhooks - one page of the app's webhooks for the current user (marker paging: {entries, next_marker, limit}; limit up to 1000).

Example

page ::box::webhooks/list-webhooks({limit: 100})
page.entries
page.next_marker

parse-delivery

fn (request: Map): Map

The webhook payload of a delivery (verify it first): {type: "webhook_event", id, created_at, trigger, webhook: {id}, created_by, source}. source is the file or folder (mini form) the trigger fired on. Accepts a request (its parsed body, or body-raw as JSON) or an already decoded Map.

Example

event ::box::webhooks/parse-delivery({body: {trigger: "FILE.UPLOADED", source: {id: "123", type: "file"}}})
event.trigger  // "FILE.UPLOADED"
event.source.id  // "123"

parse-timestamp

fn (value: Str): Int?

Parse a BOX-DELIVERY-TIMESTAMP (RFC 3339 with an offset, e.g. 2026-11-01T12:00:00-07:00, Z, optional fractional seconds) to Unix seconds, or null for anything else. Exposed for testing.

Example

::box::webhooks/parse-timestamp("2026-11-01T12:00:00Z")  // 1793534400
::box::webhooks/parse-timestamp("2026-11-01T05:00:00-07:00")  // 1793534400
::box::webhooks/parse-timestamp("yesterday")  // null

signed-payload

fn (body: Any, timestamp: Str): Bytes

The bytes Box signs (pure): the raw body followed by the delivery timestamp. Exposed for testing.

Example

Str(::box::webhooks/signed-payload("{}", "2026-11-01T12:00:00Z"))  // "{}2026-11-01T12:00:00Z"

update-webhook

fn (webhook-id: Str, changes: Map): Map
fn (webhook-id: Str, changes: Map, opts: Map): Map

PUT /webhooks/{id} - change address, triggers or target ({type, id}). Null values in changes are dropped.

Example

hook ::box::webhooks/update-webhook("789", {triggers: ["FILE.UPLOADED"]})
hook.triggers

verification-failure

fn (request: Map, primary-key: Str?, secondary-key: Str?, max-age-seconds: Int): Str?

Why a delivery fails verification, or null when it verifies. Reasons: "no-key", "missing-timestamp", "missing-signature", "unsupported-version", "unsupported-algorithm", "bad-signature", "bad-timestamp", "stale". The timestamp is only trusted after a signature matched. A max-age-seconds of 0 or less skips the age check (for replaying stored test deliveries only). Explicit keys are marked as secrets.

Example

::box::webhooks/verification-failure({headers: {}}, null, null, 600)  // "no-key"

verify-request

fn (request: Map): Bool
fn (request: Map, primary-key: Str?, secondary-key: Str?): Bool
fn (request: Map, primary-key: Str?, secondary-key: Str?, max-age-seconds: Int): Bool

Verify a Box webhook delivery (see the namespace doc). The 1-arity form uses the box.webhook.primary-key / box.webhook.secondary-key context variables and fails the run when neither is set; the other forms take the keys (either may be null or "", but not both) and an optional max-age-seconds (default 600). Returns a Bool.

Example

request {headers: {box-delivery-timestamp: "2026-11-01T12:00:00Z"}, body-raw: "{}"}

// Keys from context
ok-from-context ::box::webhooks/verify-request(request)

// Explicit keys, and a 5 minute window
::box::webhooks/verify-request(request, ::hot::ctx/get("box.webhook.primary-key"), ::hot::ctx/get("box.webhook.secondary-key"), 300)

webhook-body

fn (target-type: Str?, target-id: Str?, address: Str?, triggers: Vec?): Map

The webhook body (pure): target: {type, id}, address (HTTPS), triggers (e.g. ["FILE.UPLOADED", "FILE.TRASHED"]). Null parts are dropped (for updates).

Example

body ::box::webhooks/webhook-body("folder", "123", "https://example.com/hook", ["FILE.UPLOADED"])
body.target  // {type: "folder", id: "123"}

// For an update, null parts are dropped
::box::webhooks/webhook-body(null, null, "https://example.com/new", null)  // {address: "https://example.com/new"}