The Box Events API: the user event stream (all, changes, sync),
the enterprise admin logs (admin_logs, admin_logs_streaming), and
long-polling.
Sync loop (user stream)
- Once:
pos ::events/current-position()(thenowposition) and store it. - Each run (a schedule, or a webhook saying "something changed"):
set ::events/sync-events(pos), applyset.events, storeset.next-stream-position.
Box can deliver an event more than once and out of order: events are
de-duplicated by event_id within a sync (pass {seen: ids} to drop
ids from earlier runs), and handlers should be idempotent. User
stream positions stay valid for a few weeks; events are kept for
about two weeks.
Admin logs (admin-events) need an admin or co-admin token with
the "Manage enterprise properties" scope and a paid enterprise.
admin_logs reads a time window (created_after, created_before,
up to a year back); admin_logs_streaming is a low-latency stream of
the last two weeks, read with stream positions like the user stream.
Long-poll. long-poll-url asks Box (OPTIONS /events) for a
realtime server URL and long-poll waits on it until Box says
new_change or reconnect. That is a blocking HTTP call: it holds
the run for up to the request timeout (120 s in Hot) and returns
{message: "timeout"} when nothing happened. A Hot schedule calling
sync-events every few minutes is usually the better fit.
Values
DEFAULT_MAX_PAGES
DEFAULT_MAX_PAGES: Int 20
LOCAL_KEYS
LOCAL_KEYS: Vec [
"seen",
"max-pages"
]
MAX_LIMIT
MAX_LIMIT: Int 500
STREAM_TYPES
STREAM_TYPES: Vec [
"all",
"changes",
"sync",
"admin_logs",
"admin_logs_streaming"
]
Functions
admin-events
fn (): Map
fn (opts: Map): Map
One chunk of the enterprise event stream: stream_type
admin_logs by default (or admin_logs_streaming), with
created_after / created_before (RFC 3339), event_type (a Vec
such as ["LOGIN", "DOWNLOAD"]), stream_position and limit (max
500). Needs an enterprise admin token.
page ::box::events/admin-events({created_after: "2026-10-01T00:00:00Z", created_before: "2026-10-02T00:00:00Z", event_type: ["UPLOAD", "DOWNLOAD"]})
page.entries
admin-events-all
fn (opts: Map): EventSet
Read the enterprise stream for a window until it is exhausted (at most
max-pages chunks, default 20), returning an EventSet. Takes the same
opts as admin-events; continue an incomplete read with
{stream_position: set.next-stream-position}.
Example
set ::box::events/admin-events-all({created_after: "2026-10-01T00:00:00Z", created_before: "2026-10-02T00:00:00Z", event_type: ["LOGIN"]})
length(set.events)
set.complete
as-position
fn (value: Any): Str?
A stream position as a Str (Box returns it as a number or a string), or null.
Example
::box::events/as-position(1152922976252290886) // "1152922976252290886"
::box::events/as-position("") // null
current-position
fn (): Str
fn (opts: Map): Str
The stream position for "from now on" (stream_position=now), as a Str.
Store it before the first sync-events.
Example
pos ::box::events/current-position()
::hot::store/put(::hot::store/Map({name: "box-sync"}), "position", pos)
dedupe-events
fn (events: Vec): Vec
fn (events: Vec, seen: Vec): Vec
Drop repeated events (pure): keep the first event per event_id, and
drop ids in seen. Events without an event_id are kept.
Example
events [{event_id: "a"}, {event_id: "a"}, {event_id: "b"}]
::box::events/dedupe-events(events) // [{event_id: "a"}, {event_id: "b"}]
::box::events/dedupe-events(events, ["a"]) // [{event_id: "b"}]
event-ids
fn (events: Vec): Vec
The event_ids of a Vec of events (pure), e.g. to pass as seen next
time.
Example
::box::events/event-ids([{event_id: "a"}, {event_type: "PING"}]) // ["a"]
event-params
fn (opts: Map): Map
The query parameters for GET /events (pure): stream_type (default
all), limit 500, then your parameters (stream_position,
stream_type, limit, event_type (a Vec or comma Str),
created_after, created_before). Nulls are dropped.
Example
::box::events/event-params({stream_position: "now", limit: 100}) // {stream_type: "all", limit: 100, stream_position: "now"}
get-events
fn (): Map
fn (opts: Map): Map
GET /events - one chunk of events: {chunk_size, next_stream_position, entries}. Options: stream_type (all, changes, sync,
admin_logs, admin_logs_streaming), stream_position ("now" for
the current position, "0" for the oldest retained), limit (max
500), event_type, created_after, created_before.
Example
page ::box::events/get-events({stream_position: "0", stream_type: "changes", limit: 100})
page.next_stream_position
page.entries
is-caught-up
fn (page: Map, position: Str?): Bool
True when a chunk means the stream is read to its end (pure): no entries, or the position did not move.
Example
::box::events/is-caught-up({entries: [], next_stream_position: "5"}, "4") // true
::box::events/is-caught-up({entries: [{event_id: "a"}], next_stream_position: "5"}, "4") // false
long-poll
fn (url: Str, stream-position: Str): Map
fn (url: Str, stream-position: Str, opts: Map): Map
Wait on a realtime server url for changes after stream-position.
Blocks the run until Box answers or the request times out (120 s).
Returns {message}: "new_change" (call sync-events now),
"reconnect" (get a new long-poll-url), or "timeout" (nothing
yet; poll again). Never retried automatically.
Example
server ::box::events/long-poll-url()
pos ::box::events/current-position()
answer ::box::events/long-poll(server.url, pos)
answer.message
long-poll-request-url
fn (url: Str, stream-position: Str): Str
The long-poll URL with stream_position appended (pure).
Example
::box::events/long-poll-request-url("https://2.realtime.services.box.net/subscribe?channel=abc", "42") // "https://2.realtime.services.box.net/subscribe?channel=abc&stream_position=42"
long-poll-url
fn (): Map
fn (opts: Map): Map
OPTIONS /events - the realtime server to long-poll: {url, ttl, max_retries, retry_timeout}. Ask again after max_retries polls or
a reconnect message.
Example
server ::box::events/long-poll-url()
server.url
server.max_retries
realtime-server
fn (response: Map): Map?
The realtime_server entry of an OPTIONS /events response (pure):
{type, url, ttl, max_retries, retry_timeout}, or null.
Example
server ::box::events/realtime-server({entries: [{type: "realtime_server", url: "https://2.realtime.services.box.net/subscribe", ttl: "10"}]})
server.ttl // "10"
sync-events
fn (stream-position: Str): EventSet
fn (stream-position: Str, opts: Map): EventSet
Read the user event stream from stream-position to its end (at
most opts.max-pages chunks of 500, default 20) and return an
EventSet with the position to use next time. Options:
stream_type (all by default; changes skips non-content events;
sync only covers synced folders), seen (event ids to drop),
max-pages, credentials.
::events ::box::events
saved-position "1152922976252290886"
set ::events/sync-events(saved-position, {stream_type: "changes"})
map(set.events, (e) { println(`${e.event_type} ${e.source.id}`) })
saved-position set.next-stream-position
Types
EventSet
EventSet type {
events: Vec,
next-stream-position: Str?,
pages: Int,
complete: Bool
}
The events read by sync-events / admin-events-all.
events- de-duplicated events in stream ordernext-stream-position- store it and pass it to the next syncpages- how many chunks were readcomplete- true when the stream was read to its end; false whenmax-pagesstopped it (call again withnext-stream-position)