Box folders: list a folder's items (marker or offset paging, fields,
sort), get folder info, create, update, rename, move, copy, trash and
restore. The root folder of every account is "0".
Every function has an options arity taking an opts Map: Box query
parameters by their Box names (fields, limit, marker,
offset, sort, direction, ...), if-match (an etag) for safe
writes, and the credential keys handled by ::box::auth.
Values
LOCAL_KEYS
LOCAL_KEYS: Vec [
"if-match",
"if-none-match",
"boxapi",
"paging",
"name",
"parent-id",
"recursive"
]
MAX_LIMIT
MAX_LIMIT: Int 1000
Functions
conflict-item
fn (error: Result): Map?
The existing item a 409 item_name_in_use error points at
(context_info.conflicts, a Map or the first of a Vec), or null (pure).
Example
error err({status: 409, context-info: {conflicts: [{type: "folder", id: "123"}]}})
::box::folders/conflict-item(error) // {type: "folder", id: "123"}
copy-body
fn (parent-id: Str, name: Str?): Map
The copy body (pure): parent: {id} and an optional new name.
Example
::box::folders/copy-body("67890", "Copy") // {parent: {id: "67890"}, name: "Copy"}
copy-folder
fn (folder-id: Str, parent-id: Str): Map
fn (folder-id: Str, parent-id: Str, opts: Map): Map
POST /folders/{id}/copy - copy a folder and its contents into
parent-id; opts.name renames the copy. Large folders copy
asynchronously on Box's side.
Example
copy ::box::folders/copy-folder("12345", "67890", {name: "Archive copy"})
copy.id
create-body
fn (name: Str, parent-id: Str, opts: Map): Map
The POST /folders body (pure): name, parent: {id}, plus extra
fields from opts.metadata (e.g. sync_state, folder_upload_email).
Example
::box::folders/create-body("Reports", "0", {}) // {name: "Reports", parent: {id: "0"}}
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
ensure-folder
fn (name: Str, parent-id: Str): Map
fn (name: Str, parent-id: Str, opts: Map): Map
Create a folder named name in parent-id, or return the existing one
when Box answers 409 item_name_in_use with a folder conflict. One API
call either way; handy for idempotent workflow output folders.
Example
folder ::box::folders/ensure-folder("Output", "0")
folder.id
get-doc-file
fn (folder-id: Str): ::box/DocFile
fn (folder-id: Str, opts: Map): ::box/DocFile
get-folder normalised to a ::box/DocFile.
Example
folder ::box::folders/get-doc-file("12345")
folder.is-folder
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
get-trashed-folder
fn (folder-id: Str): Map
fn (folder-id: Str, opts: Map): Map
GET /folders/{id}/trash - a trashed folder's information (404 when it is not in the trash).
Example
folder ::box::folders/get-trashed-folder("12345")
folder.trashed_at
items-params
fn (opts: Map): Map
The query parameters list-items sends for opts (pure): fields =
::box/ITEM_FIELDS, limit 1000, and usemarker=true unless opts
asks for offset paging (by passing offset), then your parameters
(fields, limit, marker, offset, sort (id, name, date,
size), direction (ASC, DESC)). Nulls are dropped.
Example
params ::box::folders/items-params({sort: "name", limit: 50})
params.usemarker // true
params.limit // 50
// Offset paging drops usemarker
::box::folders/items-params({offset: 0, fields: "id"}) // {fields: "id", limit: 1000, offset: 0}
list-all-doc-files
fn (folder-id: Str): Vec
fn (folder-id: Str, opts: Map, limit: Int?): Vec
list-all-items normalised to ::box/DocFiles.
Example
files ::box::folders/list-all-doc-files("12345")
map(files, %.name)
first-page ::box::folders/list-all-doc-files("12345", {fields: "id,type,name,size,sha1,etag"}, 100)
length(first-page)
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
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
move-folder
fn (folder-id: Str, parent-id: Str): Map
fn (folder-id: Str, parent-id: Str, opts: Map): Map
Move a folder (and its contents) into parent-id.
Example
folder ::box::folders/move-folder("12345", "67890")
folder.parent.id
rename-folder
fn (folder-id: Str, name: Str): Map
fn (folder-id: Str, name: Str, opts: Map): Map
Rename a folder.
Example
folder ::box::folders/rename-folder("12345", "Archive")
folder.name
restore-body
fn (opts: Map): Map
The restore body (pure): an optional new name and parent: {id}, for
when the original name or location is taken.
Example
::box::folders/restore-body({name: "Restored", parent-id: "67890"}) // {name: "Restored", parent: {id: "67890"}}
restore-folder
fn (folder-id: Str): Map
fn (folder-id: Str, opts: Map): Map
POST /folders/{id} - restore a trashed folder. opts.name /
opts.parent-id restore it under a new name or into another folder when
the original is taken or gone.
Example
folder ::box::folders/restore-folder("12345", {name: "Restored"})
folder.item_status
trash-folder
fn (folder-id: Str): Bool
fn (folder-id: Str, opts: Map): Bool
DELETE /folders/{id} - move a folder to the trash (recoverable until
the enterprise's trash retention, 30 days by default). A non-empty
folder needs {recursive: true}. opts.if-match guards against
concurrent changes. Returns true.
Example
::box::folders/trash-folder("12345")
// A folder with items in it
::box::folders/trash-folder("67890", {recursive: true})
update-folder
fn (folder-id: Str, changes: Map): Map
fn (folder-id: Str, changes: Map, opts: Map): Map
PUT /folders/{id} - update a folder: name, description, parent
({id}, to move), tags, shared_link, folder_upload_email,
sync_state, ... Null values in changes are dropped. opts.if-match
(an etag) makes the write fail with 412 when the folder changed.
Example
folder ::box::folders/update-folder("12345", {description: "Quarterly reports"})
folder.description
// Fails with 412 if the folder changed
safe ::box::folders/update-folder("12345", {tags: ["finance"]}, {if-match: folder.etag})
safe.etag