Lightning's API lets a program manage an instance's users, projects, credentials and collections, and read its workflows, runs and logs.

Still being built

The API is undergoing extensive improvements. Expect fixes and new endpoints. This page covers what every route shares and lists the routes.

Authenticate

Send a token in the Authorization header on every request:

Authorization: Bearer <token>

Two kinds of token work:

  • The service account's access token, for automation that sets up an instance. Service accounts explains how to get one. It carries only the token grants it asked for, and the routes table lists the grant each route needs.
  • A personal access token, which you create in Lightning under your profile at Personal Access Tokens. It acts with your own permissions on your projects and lasts until you revoke it. /api/users takes only the service account's token. It answers a personal access token with 403 forbidden, and a project repo connection's token with 403 insufficient_scope naming users:read or users:write.

Conventions

  • Send request bodies as JSON with Content-Type: application/json. Responses are JSON, except GET /api/provision/yaml.
  • Ids are UUIDs.
  • A PUT on a route the table marks "create or replace" takes an id you choose. It answers 201 when it creates the record and 200 when it replaces one.
  • Send only the keys a route accepts. A route can refuse any other key with a 422 whose entry has the code unknown_key.
  • Lists that page take page, from 1, and page_size, which defaults to 10 and is at most 100. Their links give the next and prev pages.

Errors

Every error from /api is an RFC 9457 problem document, except those from the token endpoint, which Service accounts covers. Its content type is application/problem+json when your Accept header names that type, and application/json otherwise.

{
  "type": "about:blank",
  "status": 400,
  "title": "Bad Request",
  "code": "invalid_parameter",
  "detail": "A path or query parameter is not valid. See errors.",
  "errors": [{ "path": "id", "code": "type", "detail": "is not a UUID" }]
}

Branch on code. It is stable, and each one always comes with the same status. title and detail are for people and can change.

errors appears when the problem is in specific parts of the request. Each entry has a code, a detail, and one member that says where the problem is:

  • pointer: a JSON Pointer into the request body, such as #/members/0/email.
  • parameter: a query parameter's name.
  • header: a request header's name, in lower case.
  • path: a path segment, named as in the routes table, such as id or project_id.

These are the codes most callers handle. The full list, entry codes included, is in LightningWeb.API.Codes.

StatuscodeMeaning
400invalid_requestThe Authorization: Bearer header is malformed.
400invalid_parameterA path or query parameter isn't valid. See errors.
400malformedThe body isn't a JSON object.
401unauthenticatedThe request has no bearer token.
401invalid_tokenThe token is unknown, revoked or expired, or the route doesn't take that kind of token. An expired service account token says so in WWW-Authenticate: error_description="The access token expired".
403insufficient_scopeThe token lacks the token grant the route needs. scope in the body and in WWW-Authenticate names it.
403forbiddenYou may not do this, or the record might not exist.
404not_foundThe record doesn't exist, or the route doesn't.
409id_takenThe id belongs to a record elsewhere.
409scheduled_for_deletionThe record is scheduled for deletion.
409concurrent_editAnother request changed the record first. Fetch it again and retry.
422invalidThe body isn't valid. See errors.

What you hear for a record you name

Lightning checks a request in this order, and the first check that fails answers:

  1. The token: 401, or 400 for a header it can't read.
  2. The token grant: 403 insufficient_scope.
  3. Your permission on the project or record: 403 forbidden.
  4. The id: 400 invalid_parameter if it isn't a UUID, 404 not_found if no such record exists.
  5. The body: 400 or 422.

A caller without permission hears 403 whether the record exists or not, and whether the id is a UUID or not. Only a caller who may learn which records exist hears 404 or 400 for the id:

The id names404 and 400 go to
A record under /api/projects/:project_id/Anyone with permission on the project
A projectSuperusers and the service account
A workflow, job, run or work order at the top levelThe service account
A credential, to read itThe service account
A userThe service account

A record in another project counts as missing. A project scheduled for deletion answers 409 scheduled_for_deletion, but only to a caller who would otherwise be allowed.

Routes

"Session only" routes serve Lightning's own web app and take no token. A route "not open to the service account" answers its token with 403 forbidden.

Accounts

MethodPathWhat it doesToken grant
POST/api/oauth/tokenExchanges a service account's assertion for a tokenNone
GET/api/usersLists users, or finds one by emailusers:read
GET/api/users/:idReads a userusers:read
POST/api/usersCreates a userusers:write
PATCH/api/users/:idChanges a userusers:write
POST/api/users/registerSigns up, where the instance offers itNone

Projects

MethodPathWhat it doesToken grant
GET/api/projectsLists projectsprojects:write
GET/api/projects/:idReads a projectprojects:write
PUT/api/projects/:idCreates or replaces a projectprojects:write
GET/api/provision/:idReads a project as a provisioning documentprojects:write
GET/api/provision/yamlReads a project, named by id, as YAMLprojects:write
POST/api/provisionApplies a provisioning documentNot open to the service account
GET/api/projects/:project_id/collections/:idReads a collectioncollections:write
PUT/api/projects/:project_id/collections/:idCreates or replaces a collectioncollections:write

Credentials

The service account must send project_id to list credentials at /api/credentials.

MethodPathWhat it doesToken grant
GET/api/credentialsLists your credentials, or a project's by project_idcredentials:write
GET/api/projects/:project_id/credentialsLists a project's credentialscredentials:write
GET/api/credentials/:idReads a credential, without its secretscredentials:write
PUT/api/credentials/:idCreates or replaces a credentialcredentials:write
POST/api/credentialsCreates a credential you ownNot open to the service account
DELETE/api/credentials/:idDeletes a credential you ownNot open to the service account

Workflows and runs

The service account must send project_id to list work orders, runs or log lines at the top level.

MethodPathWhat it doesToken grant
GET/api/projects/:project_id/workflowsLists a project's workflowsprojects:write
GET/api/projects/:project_id/workflows/:idReads a workflowprojects:write
POST/api/projects/:project_id/workflowsCreates a workflowprojects:write
PATCH/api/projects/:project_id/workflows/:idChanges a workflowprojects:write
PUT/api/projects/:project_id/workflows/:idChanges a workflowprojects:write
GET/api/projects/:project_id/jobsLists a project's jobsprojects:write
GET/api/projects/:project_id/jobs/:idReads a jobprojects:write
GET/api/projects/:project_id/work_ordersLists a project's work ordersprojects:write
GET/api/projects/:project_id/work_orders/:idReads a work orderprojects:write
GET/api/projects/:project_id/runsLists a project's runsprojects:write
GET/api/projects/:project_id/runs/:idReads a runprojects:write
GET/api/workflowsLists workflows across projectsprojects:write
GET/api/workflows/:idReads a workflowprojects:write
GET/api/jobsLists jobs across projectsprojects:write
GET/api/jobs/:idReads a jobprojects:write
GET/api/work_ordersLists work orders across projectsprojects:write
GET/api/work_orders/:idReads a work orderprojects:write
GET/api/runsLists runs across projectsprojects:write
GET/api/runs/:idReads a runprojects:write
GET/api/log_linesLists log linesprojects:write

Lightning's web app

MethodPathWhat it doesToken grant
GET/api/ai_assistant/sessionsLists AI assistant sessionsSession only
GET/api/projects/:project_id/workflows/:workflow_id/health/outcomesWorkflow health: run outcomesSession only
GET/api/projects/:project_id/workflows/:workflow_id/health/failuresWorkflow health: failuresSession only
GET/api/projects/:project_id/workflows/:workflow_id/health/runsWorkflow health: runsSession only