API overview
Authenticate to the Data Hub REST API, make a first request, and understand pagination, filtering, token attribution, and errors.
The Data Hub web app serves the REST API at /api/v1/. The watcher, the Lambda, and the web app all call it. Data Hub is self-hosted, so the base URL is your deployment’s host plus /api/v1. Examples use https://datahub.example.com; replace it with your host.
The generated pages in this API section of the sidebar describe each endpoint’s request and response. Each deployment also publishes an OpenAPI 3.1 document at /api/v1/openapi.json.
Authentication
The REST API accepts two kinds of credentials, and Security and permissions describes the full model:
- Session cookies: the web app uses these after someone signs in with Google. Scopes apply only to tokens, so a signed-in session passes every scope check.
- Bearer tokens: the watcher, the Lambda, and scripts send
Authorization: Bearer dhub_…
curl https://datahub.example.com/api/v1/instruments \
-H "Authorization: Bearer dhub_your_token_here"Every token request needs a scope, and a missing scope returns 403 FORBIDDEN. Some actions that change data also need the admin role; see Admin-gated operations.
Some routes accept only one of the two kinds of credentials:
- The routes the watcher and the Lambda call accept only tokens, and return
401 UNAUTHORIZEDto a session. These cover watcher registration and heartbeats, upload links, file updates, run creation and updates, and instrument creation. - Claiming runs, sending feedback, reviewing feedback, and managing tokens need a signed-in person, so tokens can’t call them.
Admins create tokens in the web app; see Issue and revoke tokens.
First request
List instruments:
curl https://datahub.example.com/api/v1/instruments \
-H "Authorization: Bearer dhub_your_token_here"Fetch the OpenAPI document, which needs no credentials:
curl https://datahub.example.com/api/v1/openapi.jsonThe document covers the routes that integrations use:
- instruments
- runs
- comments
- lab notebooks
- files
- watchers
- archive jobs
- search
POST /notifications/dispatch
It leaves out the routes that only the web app uses: /tokens, /users, /feedback, /settings/*, and the notification inbox. The MCP server has its own docs; see MCP.
Instruments and their watcher
An instrument has at most one active watcher, so GET /instruments and GET /instruments/:id describe it with one object instead of counts:
watcher: the instrument’s active watcher, ornullwhen it has none. It includesid,status,status_reason,last_heartbeat_at,file_patterns,upload_mode, andconfig_state. With thewatchers:readscope, it also includes five fields that say where the watcher runs:hostname,os_info,version,watch_directory, andshared_computer_with. A token that hasinstruments:readbut notwatchers:readgets the watcher without those five fields. The fields are missing from the object, not set tonull. A signed-in browser session passes every scope check, so it always gets them.connection: whether new files can reach Data Hub.stateisonline,restarting,connecting, oroffline.reasonsays why the instrument is offline (folder_missing,unresponsive,never_checked_in,stopped,no_watcher, orderegistered), and isnullotherwise. The rules are the same ones behind the badge in the web app; see Instrument status.connectionignores the instrument’s ownstatus, so apendinginstrument can beonline. The web app shows Pending or Retired first, andconnection.stateonly after that.past_watcher_count: how many deregistered watchers the instrument has had.
GET /instruments/:id still returns watcher_count, but it’s deprecated. It keeps its old value for now. A later release will remove it, and the changelog will announce the date first. Read watcher instead, which is null when there’s no watcher.
GET /search returns the same instrument results as the global_search MCP tool. An instrument result now includes connection, which replaces the deprecated watcherStatus and lastWatcherHeartbeatAt. Those two fields keep their old values for now.
Actions taken by a token
A token acts under its own name, not as a person, so responses name the token when it did something:
- A comment posted by a token has
user: nulland atokenobject with the token’sidandname. A comment posted by a person hastoken: null. - A run deleted by a token has
deleted_by_tokenset, alongsidedeleted_at. - A file deleted by a token has
deleted_by_tokenset, alongsidedeleted_at, anddeleted_bynull. A file deleted by a person hasdeleted_byset to their user ID anddeleted_by_tokennull. - A lab notebook created, last edited, or deleted by a token has
created_by_token,updated_by_token, ordeleted_by_tokenset, and the matching person field null. A run added to a lab notebook by a token haslinked_by_tokenset andlinked_bynull.
Read both fields when you display who did something. See How a token acts.
Deleted files
Deleting a file hides it from its run. The file stays in storage, records who deleted it, and can be restored. A deleted file is left out of the run’s downloads and of the files that GET /instruments/:id/runs/:runId returns. Pass include_deleted=true to that route to list deleted files too, each with deleted_at and who deleted it. A deleted file keeps its ID, so you can still download it by ID.
DELETE /files/:iddeletes one file, andPOST /files/:id/restorebrings it back. Passinclude_linked=trueto take along the files linked to it. For a raw file, those are the processed files made from it and therun.jsonsaved with its capture, which a delete takes only when every raw file in that folder is being deleted. A restore also brings back the raw file a processed file was made from.POST /instruments/:id/runs/:runId/files/deleteand.../files/restoretakefile_ids(1 to 100) andinclude_linked, and answer with a result for each file in the order you sent them. A file that can’t be changed, for example because it’s still processing or another file now has its name, gets a409result and doesn’t stop the others.GET /instruments/:id/runs/:runId/files/linked?file_ids=1,2lists the files that a delete would take along, so you can show them first. Addfor=restoreto list the deleted files a restore would bring back.
All of them need the files:delete scope. A file that’s queued or processing can’t be deleted until it finishes, and the files of a deleted run can’t be deleted or restored.
Send notifications
POST /notifications/dispatch sends a short message to chosen people, with an optional link to a run. It needs a token with the notifications:create scope. Each person’s Service notifications setting decides whether the message appears in the notification bell, as a Slack direct message, or both. The message shows the token’s name as its sender. The generated dispatch notifications page lists the request fields.
Pagination and filtering
Run search (GET /instrument-runs and GET /instruments/:id/runs) and the lab notebook list (GET /lab-notebooks) return results in pages. They accept:
page: the page number, starting at 1per_page: page size, 1 to 100 for runs and 1 to 200 for lab notebooks
Responses include pagination fields such as page, per_page, total, and total_pages.
Run report items use offset and limit (up to 200) instead. Their responses return offset, limit, and total.
Run search can also filter by:
- instrument
- date range
- who ran it (
ran_by) - lab notebook
- instrument-specific metadata
Each generated endpoint page in this API section lists the exact query parameters.
Error responses
Errors come back inside an error object:
{
"error": {
"code": "NOT_FOUND",
"message": "Instrument not found.",
"details": null
}
}The common codes are:
VALIDATION_ERROR(400)UNAUTHORIZED(401)FORBIDDEN(403)NOT_FOUND(404)CONFLICT(409)
A missing scope returns code: "FORBIDDEN" with a message that names the scope.
Feedback routes have two more codes. LINEAR_UNAVAILABLE (502) means Data Hub couldn’t reach Linear, where reports are stored. FEEDBACK_NOT_CONFIGURED (503) means no admin has connected Linear yet; see Set up integrations.
MCP
The MCP server answers GET and POST requests at /mcp/v1 over Streamable HTTP, outside /api/v1. Clients sign in with OAuth instead of a personal access token. They need the read scope to connect and the write scope to call any tool that changes data. See MCP overview.