Box Platform API v2.0 bindings: folders and files, search, binary-safe downloads (with Range chunking past the response cap), multipart and chunked uploads, extracted-text representations, shared links, collaborations, versions, the Events API, admin logs, and webhooks v2 with signature verification.
Credentials come from context by default, or per call from an
opts Map (see ::box::auth for the full table):
box.access.token- a ready access token (developer token, or one you manage)- OAuth 2.0 refresh tokens through the store-backed keeper
(
box.oauth.account, or a seedbox.oauth.refresh-token). Box refresh tokens are single-use: every refresh returns a new pair, which the keeper persists with compare-and-set. box.jwt.config- the Box app config JSON (JWT server auth), withbox.jwt.private-keyholding the unencrypted PKCS#8 keybox.client.id+box.client.secret+box.enterprise.idorbox.user.id- Client Credentials Grant
box.as-user (or opts.as-user) sends the As-User header so an
admin or service account acts as a managed user.
Namespaces
::box::auth- credential resolution, CCG, JWT, token cache, refresh-token keeper::box::oauth-authorize-url,exchange-code,refresh-tokens,revoke-token::box::api-request/json,HttpError,is-retryable, marker and offset paging::box::folders- folder items, get, create, update, rename, move, copy, trash, restore::box::files- file info, update, rename, move, copy, trash, restore, versions::box::search- search with typed filters::box::content- downloads, Range chunks, extracted text,read-document::box::upload- multipart upload, new versions, chunked upload sessions, preflight::box::sharing- shared links and collaborations::box::events- user event stream, admin logs, long-poll::box::webhooks- webhook CRUD and signature verification
Quick start
::folders ::box::folders
::content ::box::content
items ::folders/list-all-items("0", {fields: "id,type,name,size,modified_at,sha1"}, 200)
doc ::content/read-document(first(items).id, "text")
doc.text
Context Vars
box.api-rootbox.upload-root
Values
API_ROOT
API_ROOT: Str "https://api.box.com"
AUTHORIZE_URL
AUTHORIZE_URL: Str "https://account.box.com/api/oauth2/authorize"
DEFAULT_MIME
DEFAULT_MIME: Str "application/octet-stream"
FILE_FIELDS
FILE_FIELDS: Str "id,type,name,size,sha1,etag,sequence_id,file_version,parent,path_collection,created_at,modified_at,content_created_at,content_modified_at,trashed_at,purged_at,item_status,extension,description,shared_link,owned_by,modified_by"
FOLDER_FIELDS
FOLDER_FIELDS: Str "id,type,name,size,etag,sequence_id,parent,path_collection,created_at,modified_at,content_created_at,content_modified_at,trashed_at,purged_at,item_status,description,shared_link,owned_by,modified_by,has_collaborations"
FOLDER_MIME
FOLDER_MIME: Str "inode/directory"
HEADER_KEYS
HEADER_KEYS: Vec [
"if-match",
"if-none-match",
"boxapi"
]
ITEM_FIELDS
ITEM_FIELDS: Str "id,type,name,size,sha1,etag,sequence_id,file_version,parent,created_at,modified_at,content_modified_at,trashed_at,item_status,extension"
REVOKE_URL
REVOKE_URL: Str "https://api.box.com/oauth2/revoke"
ROOT_FOLDER_ID
ROOT_FOLDER_ID: Str "0"
TOKEN_URL
TOKEN_URL: Str "https://api.box.com/oauth2/token"
UPLOAD_ROOT
UPLOAD_ROOT: Str "https://upload.box.com"
WEB_LINK_MIME
WEB_LINK_MIME: Str "application/vnd.box.web-link"
WEB_ROOT
WEB_ROOT: Str "https://app.box.com"
Functions
api-root
fn (): Str
The API root, https://api.box.com unless the box.api-root context
variable points at a proxy or test server.
Example
::box/api-root() // "https://api.box.com"
base-mime
fn (content-type: Str?): Str?
A Content-Type without parameters, lowercased: "text/plain; charset=utf-8" becomes "text/plain".
Example
::box/base-mime("Text/Plain; charset=utf-8") // "text/plain"
compact
fn (body: Map): Map
Drop null values from a request body (unset optionals are never sent as JSON null).
Example
::box/compact({name: "a.txt", description: null}) // {name: "a.txt"}
condition-headers
fn (opts: Map): Map
The conditional / shared-link headers in opts (pure): if-match (an
etag: the write fails with 412 if the item changed), if-none-match,
and boxapi (shared_link=<url>&shared_link_password=<pw> for items
reached through a shared link).
Example
::box/condition-headers({if-match: "3", limit: 10}) // {if-match: "3"}
content-from-bytes
fn (file-id: Str, bytes: Bytes, mime-type: Str?, source: Str): FileContent
Build a FileContent from raw bytes and their MIME type.
Example
content ::box/content-from-bytes("123", Bytes("hello"), "text/plain", "download")
content.text // "hello"
content.size // 5
content-text
fn (content: Map): Str
The text of a FileContent: its text, or the UTF-8 decoding of
bytes (invalid sequences become U+FFFD).
Example
::box/content-text({text: "hello", bytes: Bytes([])}) // "hello"
::box/content-text({bytes: Bytes("hi")}) // "hi"
create-folder of ::box::folders/create-folder
fn (name: Str): Map
fn (name: Str, parent-id: Str): Map
fn (name: Str, parent-id: Str, opts: Map): Map
POST /folders - create a folder in parent-id (default the root,
"0"). Fails with 409 item_name_in_use when the name is taken; see
ensure-folder.
folder ::box::folders/create-folder("Reports", "0")
folder.id
creds
fn (opts: Map): Map
The credential part of opts (credentials, as-user, retry), passed
through to ::box::api.
Example
::box/creds({limit: 50, as-user: "123", retry: false}) // {as-user: "123", retry: false}
download-file of ::box::content/download-file
fn (file-id: Str): ::box/FileContent
fn (file-id: Str, opts: Map): ::box/FileContent
GET /files/{id}/content - download a file's bytes as a FileContent.
When the file is larger than http.max-response-bytes, it is fetched
again in Range chunks (download-file-chunked).
Options: range: {start, end} (inclusive; end null for the rest)
for a partial download, version (an older file version id),
chunk-size for the chunked fallback, boxapi for shared-link
access, plus credentials.
pdf ::box::content/download-file("12345")
pdf.bytes // exact bytes
encode-id
fn (id: Any): Str
URL-encode an id for a path segment.
Example
::box/encode-id("a b") // "a%20b"
::box/encode-id(12345) // "12345"
get-file of ::box::files/get-file
fn (file-id: Str): Map
fn (file-id: Str, opts: Map): Map
GET /files/{id} - file information. fields defaults to
::box/FILE_FIELDS (a Str or Vec; Box returns only a mini
representation for fields you do not name). opts.rep-hints with a
representations field asks for representations.
file ::box::files/get-file("12345")
file.sha1
file.file_version.id
get-folder of ::box::folders/get-folder
fn (folder-id: Str): Map
fn (folder-id: Str, opts: Map): Map
GET /folders/{id} - folder information. fields defaults to
::box/FOLDER_FIELDS. The response also carries the first page of
item_collection when you ask for that field.
Example
folder ::box::folders/get-folder("12345")
folder.name
// The first page of items as well
items ::box::folders/get-folder("12345", {fields: "id,name,item_collection"})
items.item_collection.entries
is-textual-mime
fn (mime-type: Str?): Bool
True when content of this MIME type is text: text/*, JSON, XML, SVG,
JavaScript, YAML, NDJSON and +json / +xml types.
Example
::box/is-textual-mime("application/json; charset=utf-8") // true
::box/is-textual-mime("application/pdf") // false
is-trashed
fn (item: Map): Bool
True when a Box item is in the trash or deleted: trashed_at is set or
item_status is trashed / deleted.
Example
::box/is-trashed({item_status: "active"}) // false
::box/is-trashed({trashed_at: "2026-11-01T00:00:00Z"}) // true
json
fn (method: Str, full-url: Str, body: Any, opts: Map): Any
::box::api/json with this package's conventions: credential opts and a
JSON or empty body.
Example
me ::box/json("GET", ::box/url("/users/me"), "", {})
me.login
// A per-call token, and a JSON body
folder ::box/json("POST", ::box/url("/folders"), {name: "Reports", parent: {id: "0"}}, {token: ::hot::ctx/get("box.access.token")})
folder.id
json-with
fn (method: Str, full-url: Str, headers: Map, body: Any, opts: Map): Any
json with extra headers (for if-match and friends).
Example
// Fails with 412 when the file changed since etag "3"
headers ::box/condition-headers({if-match: "3"})
file ::box/json-with("PUT", ::box/url("/files/12345"), headers, {name: "Renamed.pdf"}, {})
file.etag
list-all-items of ::box::folders/list-all-items
fn (folder-id: Str): Vec
fn (folder-id: Str, opts: Map): Vec
fn (folder-id: Str, opts: Map, limit: Int?): Vec
Every item in a folder (all pages, or at most limit), following
next_marker (or offsets with {paging: "offset"}). Takes the same
opts as list-items. Items are not recursive: list sub-folders
yourself, or use ::box::search/search with ancestor_folder_ids.
files ::box::folders/list-all-items("12345", {fields: "id,type,name,sha1"}, 5000)
list-items of ::box::folders/list-items
fn (folder-id: Str): Map
fn (folder-id: Str, opts: Map): Map
GET /folders/{id}/items - one page of a folder's files, folders and
web links. Marker paging by default: Box returns {entries, next_marker, limit}; pass {marker: page.next_marker} for the next
page, or use list-all-items. Pass offset instead for offset paging
({entries, total_count, offset, limit}; Box caps offset paging at
10,000 items, marker paging has no cap).
page ::box::folders/list-items("0", {fields: "id,type,name,size,modified_at", sort: "date", direction: "DESC"})
page.entries
mime-for
fn (item: Map): Str
The MIME type for a Box item (pure): folders and web links get
FOLDER_MIME / WEB_LINK_MIME; files get one from their name's
extension, else application/octet-stream.
Example
::box/mime-for({type: "file", name: "report.pdf"}) // "application/pdf"
::box/mime-for({type: "folder", name: "Reports"}) // "inode/directory"
parent-ref
fn (folder-id: Any): Map?
The {id} reference Box uses for a parent folder, or null for a null
id.
Example
::box/parent-ref("123") // {id: "123"}
::box/parent-ref(null) // null
query-params
fn (defaults: Map, opts: Map): Map
fn (defaults: Map, opts: Map, local-keys: Vec): Map
Build a call's query parameters: defaults, overridden by the Box
parameters in opts (credential keys and the function's own
local-keys are removed), with nulls dropped. Pass a key as null in
opts to drop a default.
Example
::box/query-params({limit: 100}, {limit: 50, as-user: "123"}) // {limit: 50}
// A null drops a default; local keys are left out
::box/query-params({limit: 100, fields: "id"}, {fields: null, chunked: true}, ["chunked"]) // {limit: 100}
read-document of ::box::content/read-document
fn (file-id: Str): ::box/FileContent
fn (file-id: Str, format: Str?): ::box/FileContent
fn (file-id: Str, format: Str?, opts: Map): ::box/FileContent
Read any file as a FileContent with its DocFile attached, in one
metadata call plus one content call.
format"auto"(default) or"text": textual files (txt, md, csv, json, ...) are downloaded as is; other documents use Box'sextracted_textwhen it is ready (source: "extracted-text"). When it is not ready, generation is requested and the original is downloaded instead (textis then null for binary files);text-statesays what Box reported, so read again later for the text.{download-fallback: false}skips that download (emptybytes)."original"(or"download","raw"): download the stored bytes.
doc ::box::content/read-document("12345", "text")
doc.text // ready for chunking and embedding, or null
doc.text-state // "success", "pending", "unavailable", ...
doc.file.sha1 // for incremental re-indexing
response-bytes
fn (response: Map): Bytes
The exact body of an HTTP response: body-bytes, or the UTF-8 bytes of
a Str body, or empty.
Example
Str(::box/response-bytes({status: 200, body: "hello"})) // "hello"
search of ::box::search/search
fn (query: Str): Map
fn (opts: Map): Map
fn (query: Str?, opts: Map): Map
GET /search - one page of results: {entries, total_count, offset, limit}. Pass a query Str, or an opts Map (with query and/or
mdfilters), or both. Box needs a query or mdfilters.
page ::box::search/search("quarterly report", {
file_extensions: ["pdf", "docx"],
ancestor_folder_ids: ["12345"],
content_types: ["name", "file_content"],
updated_at_range: ["2026-01-01T00:00:00Z", ""],
limit: 50
})
page.entries
to-doc-file
fn (item: Map): DocFile
Normalise a Box file, folder or web-link item (from get-file, folder
items, search, events) into a DocFile. Missing fields become
null/false.
Example
file ::box/to-doc-file({type: "file", id: "123", name: "notes.txt", size: "10", etag: "2", parent: {id: "0"}})
file.mime-type // "text/plain"
file.parents // ["0"]
file.version // "2"
to-doc-files
fn (items: Vec): Vec
to-doc-file over a Vec of Box items.
Example
map(::box/to-doc-files([{type: "folder", id: "1", name: "Docs"}]), %.mime-type) // ["inode/directory"]
to-int
fn (value: Any): Int?
Parse an Int from an Int or a decimal Str, or null (never halts on bad input).
Example
::box/to-int("42") // 42
::box/to-int("soon") // null
upload-file of ::box::upload/upload-file
fn (name: Str, content: Any): Map
fn (name: Str, content: Any, parent-id: Str): Map
fn (name: Str, content: Any, parent-id: Str, opts: Map): Map
Upload a new file into parent-id (default the root, "0"). Returns
the file. Options: content-created-at / content-modified-at
(RFC 3339), description, attributes (extra fields), chunked
(true / false to force; default chunked from 20 MB), fields,
plus credentials. A name already used in the folder fails with 409
item_name_in_use; ::box::folders/conflict-item reads the existing
file from that error, and upload-version replaces its content.
csv-text "name,total\nAna,12\n"
file ::box::upload/upload-file("report.csv", csv-text, "12345")
file.id
upload-root
fn (): Str
The upload root, https://upload.box.com unless the box.upload-root
context variable overrides it.
Example
::box/upload-root() // "https://upload.box.com"
upload-url
fn (path: Str): Str
fn (path: Str, params: Map): Str
A Box upload URL (https://upload.box.com/api/2.0...) with params.
Example
::box/upload-url("/files/content") // "https://upload.box.com/api/2.0/files/content"
url
fn (path: Str): Str
fn (path: Str, params: Map): Str
A Box API v2.0 URL: path (e.g. "/files/123") plus non-null params
as a query string (see ::box::api/with-query).
Example
::box/url("/files/123") // "https://api.box.com/2.0/files/123"
::box/url("/folders/0/items", {limit: 100}) // "https://api.box.com/2.0/folders/0/items?limit=100"
web-url
fn (item: Map): Str?
The Box web app link for an item: https://app.box.com/file/{id},
/folder/{id} or /web_link/{id}.
Example
::box/web-url({type: "folder", id: "123"}) // "https://app.box.com/folder/123"
::box/web-url({type: "file", id: "456"}) // "https://app.box.com/file/456"
Types
DocFile
DocFile type {
provider: Str,
id: Str,
name: Str,
mime-type: Str,
size: Int?,
modified: Str?,
created: Str?,
parents: Vec,
drive-id: Str?,
web-url: Str?,
version: Str?,
revision-id: Str?,
md5: Str?,
sha256: Str?,
sha1: Str?,
is-folder: Bool,
is-google-native: Bool,
is-shortcut: Bool,
shortcut-target-id: Str?,
trashed: Bool,
export-formats: Vec,
raw: Map
}
Provider-neutral file metadata with the same fields as
hot.dev/google-drive's DocFile, plus sha1 (Box's content hash),
so a documents package can treat Drive, OneDrive, Dropbox and Box alike.
Fields
provider-"box"id,namemime-type- from the file extension (application/octet-streamwhen unknown);FOLDER_MIMEfor folders,WEB_LINK_MIMEfor web linkssize- bytes (Int); for folders Box reports the total size of the contentsmodified,created- RFC 3339 timestamps (modified_at,created_at)parents- the parent folder id, as a one-element Vec (empty for the root)drive-id- always null (Box has no shared drives)web-url-https://app.box.com/file/{id}or/folder/{id}version- the itemetag(send it asif-matchfor safe updates)revision-id- the currentfile_version.idmd5,sha256- always null (Box hashes with SHA-1)sha1- the content SHA-1 (hex), files onlyis-folder,is-google-native(always false),is-shortcut(always false; Box web links are bookmarks, not shortcuts),shortcut-target-id(null)trashed- true whentrashed_atis set oritem_statusis notactiveexport-formats- always empty (see::box::content/extracted-text)raw- the Box item as returned
FileContent
FileContent type {
file-id: Str,
name: Str?,
mime-type: Str?,
size: Int,
bytes: Bytes,
text: Str?,
source: Str,
format: Str?,
file: DocFile?,
text-state: Str?
}
Downloaded file content or extracted text, with the same fields as
hot.dev/google-drive's FileContent plus text-state.
Fields
file-id,namemime-type- the MIME type ofbytessize-length(bytes)bytes- the exact response body (binary safe)text- the UTF-8 decoding when the content is textual, else nullsource-"download","range","chunked"or"extracted-text"format- the formatread-documentwas asked for, else nullfile- theDocFile(set byread-document)text-state- the extracted-text representation state seen byread-document("success","pending","none","unavailable", ...), else null