Workspaces
Workspace files
client.workspaces.files lists, reads, replaces and deletes the files you uploaded to a workspace. To make them searchable, use client.workspaces.ingest.
- Arguments: every method takes the
workspaceIdfirst, and the file methods take thefileIdnext. - A missing file: one that doesn't exist, or was deleted, rejects with
NotFoundError, codefile_not_found. - Cost: listing, reading, replacing and deleting files is free, at any balance.
See List workspace files in the API reference.
List workspace files
client.workspaces.files.list(workspaceId, params?, options?) returns APIPromise<WorkspaceFilePage>. params is a WorkspaceFileListParams; each list filter is sent once per value.
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | The workspace. |
params.path_prefix | string | No | Only files whose path starts with this. |
params.ingestion_status | IngestionStatus[] | No | Only files in these ingestion statuses. |
params.categories | string[] | No | Only files in these categories, set by ingestion. |
params.file_types | string[] | No | Only these extensions, such as pdf or xlsx. |
params.modified_after | string | No | Only files whose updated_at falls after this time, ISO 8601. |
params.modified_before | string | No | Only files whose updated_at falls before this time, ISO 8601. |
params.limit | number | No | 1 to 200. Default: 50. Out of range throws a NaceError. |
params.cursor | string | null | No | The previous page's next_cursor. Keep going until it's null. |
const page = await client.workspaces.files.list(workspaceId, {
path_prefix: "reports/",
ingestion_status: ["stale"],
});
for (const file of page.items) console.log(file.path, file.ingestion_status);Read a workspace file
client.workspaces.files.get(workspaceId, fileId, options?) returns APIPromise<WorkspaceFileDetail>, the file with download_url and preview_url, links to its bytes that work without your API key for 15 minutes.
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | The workspace. |
fileId | string | Yes | The file. |
const file = await client.workspaces.files.get(workspaceId, fileId);
console.log(file.path, file.download_url);File metadata
client.workspaces.files.metadata(workspaceId, fileId, options?) returns APIPromise<WorkspaceFileMetadata>, what ingestion learned about the file, its outputs, and whether each representations entry is current. Most of it is empty until the file is ingested. See File metadata.
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | The workspace. |
fileId | string | Yes | The file. |
const metadata = await client.workspaces.files.metadata(workspaceId, fileId);
console.log(metadata.lane, metadata.representations, metadata.outputs?.length);File versions
client.workspaces.files.versions(workspaceId, fileId, params?, options?) returns APIPromise<WorkspaceFileVersionPage>, the file's versions, newest first. Only the current version's bytes are kept. params is a WorkspaceFileVersionListParams.
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | The workspace. |
fileId | string | Yes | The file. |
params.limit | number | No | 1 to 200. Default: 50. |
params.cursor | string | null | No | The previous page's next_cursor. |
const { items } = await client.workspaces.files.versions(workspaceId, fileId);
for (const version of items) console.log(version.version, version.size_bytes, version.is_current);Replace a workspace file
client.workspaces.files.replace(workspaceId, fileId, content, params?, options?) returns APIPromise<DocumentJob>, a job that has already succeeded, with result.file and result.previous_version.
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | The workspace. |
fileId | string | Yes | The file. Its path stays the same. |
content | FileContent | Yes | The new bytes: a Blob (a File included), a Uint8Array or an ArrayBuffer. |
params.file_name | string | No | The name sent with the bytes. The file keeps its path either way. Default: the File's own name. |
params.labels | Record<string, string> | No | Your own key-value metadata, replacing the file's. {} clears it. Default: keep them. |
params is a ReplaceWorkspaceFileParams. The bytes go through Drex, so a replace takes about 4.5 MB at most; to replace a larger file, upload it to the same path with on_conflict: "new_version" instead. Sending the same bytes and labels again changes nothing. An ingested file becomes stale until you ingest it again. See Replace a file.
import { readFile } from "node:fs/promises";
const job = await client.workspaces.files.replace(workspaceId, fileId, await readFile("report-v2.pdf"));Delete a workspace file
client.workspaces.files.delete(workspaceId, fileId, params?, options?) returns APIPromise<DocumentJob>, a file_delete job. It removes the file, its outputs and its search-index entries, cancels ingestions still running on it, and can't be undone.
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | The workspace. |
fileId | string | Yes | The file. |
params.wait_seconds | number | No | 0 to 60 (MAX_WAIT_SECONDS). |
params.idempotency_key | string | No | Up to 200 characters. Minted per call when omitted. |
params is a DeleteWorkspaceFileParams.
const done = await client.jobs.wait((await client.workspaces.files.delete(workspaceId, fileId)).job_id);Read an output
client.workspaces.files.output(workspaceId, fileId, outputId, options?) returns APIPromise<WorkspaceFileOutput>, with links to the output's bytes. See Read an output.
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | The workspace. |
fileId | string | Yes | The file. |
outputId | string | Yes | A derived_file output from the file's metadata. Another kind rejects with UnprocessableEntityError. |
const output = await client.workspaces.files.output(workspaceId, fileId, outputId);
console.log(output.path, output.download_url);List output members
client.workspaces.files.outputMembers(workspaceId, fileId, outputId, params?, options?) returns APIPromise<WorkspaceFileOutputMembers>, one page of the files inside a folder output, such as a recording's frames, with links to each. A single-file output has no members.
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | The workspace. |
fileId | string | Yes | The file. |
outputId | string | Yes | A folder output. |
params.offset | number | No | How many members to skip. Default: 0. A negative one throws a NaceError. |
params.limit | number | No | 1 to 200. Default: 50. |
params is an OutputMembersParams.
const { members, total_count } = await client.workspaces.files.outputMembers(workspaceId, fileId, outputId, { limit: 100 });Ingest files
client.workspaces.ingest(workspaceId, params?, options?) returns APIPromise<DocumentJob>, an ingestion job. Ingestion builds the search index, metadata and outputs, and is the only call that makes files searchable. One bad file doesn't fail the run: the result's outcomes reports each file. See Ingest files.
| Parameter | Type | Required | Description |
|---|---|---|---|
workspaceId | string | Yes | The workspace. |
params.file_ids | string[] | No | Ingest these files, 1 to 1000. Not with path_prefix or stale_only. |
params.path_prefix | string | No | Ingest the files under this path. Not with file_ids. Leave both out for the whole workspace. |
params.stale_only | boolean | No | Only files that changed since they were last ingested, under path_prefix or across the whole workspace. Default: false. |
params.reingest_unchanged | boolean | No | Rebuild files that are already ingested and unchanged, instead of skipping them. Default: false. |
params.wait_seconds | number | No | 0 to 60 (MAX_WAIT_SECONDS). |
params.idempotency_key | string | No | Up to 200 characters. Minted per call when omitted. |
params is an IngestParams. file_ids with path_prefix or stale_only throws a NaceError before sending.
const job = await client.workspaces.ingest(workspaceId, { path_prefix: "reports/", stale_only: true });
const done = await client.jobs.wait(job.job_id);