dotFactory
Documentation / Reference

The JSON API

Reference

Authentication, tokens and scopes, the endpoint map, and reading a page as data.

Everything the browser does goes through the JSON API under /api/. An integration uses the same endpoints, and a page URL can also answer as data.

Authentication

A request authenticates with either:

  • the session cookie the browser gets from /api/login or /api/signup;
  • a Bearer token: Authorization: Bearer <key>.

Mint a token on /tokens, choosing read-only or read and write access. Existing tokens show their access level there.

The key is shown once; only its SHA-256 hash is stored. The key is opaque: its fct_ prefix is followed by random URL-safe characters, so _ and - are part of the key (one may begin fct__…). Copy it exactly.

A token lives in one deployment's database: a key minted against another instance or a local factory.db does not authenticate here. Mint it on the instance you will call. Revoking a key invalidates it immediately.

A token has a scope:

scope may
write everything (the default)
read GET/HEAD/OPTIONS only; any write verb is refused with 403

Use a read token for an inspection integration or an agent that should not be able to cancel, upload or change anything.

Every factory-scoped endpoint also checks membership. An unknown factory is 404; a factory you cannot see is 404 too, so the API does not confirm that an id exists. Organization-scoped endpoints check organization membership the same way.

Errors

Failures are JSON: {"error": "…"} with a status that says what kind of failure it is.

status meaning
400 malformed JSON, a missing field, a conformance error
401 no session and no valid token
403 authenticated but not allowed (wrong role, read-only token, another tenant)
404 no such resource, or none you may see
409 the request conflicts with the current state (cancel a finished Run, delete a factory with open Runs)
422 the factory is valid but names an adapter this deployment does not implement

Endpoint map

This is the working map, not every route. The full list is in runs/urls.py.

Accounts, build and catalogue

method path does
POST /api/signup, /api/login, /api/logout session auth
GET /api/me the caller's identity
GET /api/version the running build (public)
GET /api/health process and SPA build (public; 503 if the build is missing)
GET /api/capabilities implemented adapter kinds + a factory's declared interface
GET /api/reference, /api/reference/{kind} the adapter catalogue
GET /api/docs, /api/docs/{slug} the in-app guide (see below)

Factories

method path does
GET /api/factories your factories: role, versions, runnable, problems, triggers
POST /api/factories create {name}
GET/DELETE /api/factories/{id} detail (owner may delete)
POST /api/factories/{id}/refresh re-read a repository source
GET /api/factories/{id}/diagram the flow graph
GET/POST /api/factories/{id}/steps leaf catalogue / run one step with {step, inputs?, config?, mode?}
GET /api/factories/{id}/versions version history
GET /api/factories/{id}/versions/{digest} one version's source and content
GET/POST /api/factories/{id}/members list / add a member by email
POST /api/factories/{id}/organization set the factory's organization
GET /api/factories/{id}/triggers/{trigger} a trigger's interface and history
POST /api/factories/{id}/triggers/{trigger}/schedule pause/resume a cron schedule

The diagram endpoint accepts ?digest=<factory-digest> to read a particular version. It returns 404 when that version is unavailable; omitting the digest returns the current version.

Secrets and configuration

method path scope
GET/POST /api/factories/{id}/secrets factory
GET/DELETE /api/factories/{id}/secrets/{key} factory
GET/POST /api/secrets user
GET/DELETE /api/secrets/{key} user
GET/POST /api/organizations/{id}/secrets organization
GET/POST /api/factories/{id}/config factory
GET/POST /api/config user
GET/POST /api/organizations/{id}/config organization

Secret reads return keys, labels and timestamps — never values. Configuration reads return values.

Runs

method path does
POST /api/runs admit {trigger, seed, factory?, sync?} → 202 with a Run id
GET /api/runs recent Runs (?factory_id=…&limit=…&offset=…, default limit 50, max 200; offset applies to factory-scoped history)
GET /api/runs/{id} the Run and its nodes
POST /api/runs/{id}/cancel stop a queued or running Run
GET /api/runs/{id}/values recorded outputs (secrets redacted)
GET /api/runs/{id}/logs, /spans, /events telemetry and the event stream
GET /api/values/{id} one stored value and its type

Organizations, GitHub and tokens

method path does
GET/POST /api/organizations list / create
GET /api/organizations/{id} detail and members
GET/POST /api/organizations/{id}/repositories visible repositories
GET /api/connections/github the caller's connection and grants
GET /api/connections/github/connect start the repository OAuth handshake
POST /api/connections/github/repositories replace the granted subset
POST /api/github/repositories/check check repositories for factory roots
GET/POST /api/github/repositories/{full_name}/factories/{slug} one candidate / accept it
POST …/publish, …/mode, …/dismiss update, pinned/follow, dismiss
POST /api/github/{path} verified webhook delivery (public)
POST /api/hooks/{factory_id}/{trigger} authenticated kind: http delivery (public, credential-verified)
GET/POST /api/tokens list / mint (the key is returned once)
POST /api/tokens/{id}/revoke revoke

Reading a page as data

The SPA owns its URLs, and the same URLs answer an agent. Ask for application/json (the Accept header, or ?format=json for clients that cannot set one) and a supported page returns its snapshot instead of the React shell:

curl -H 'Accept: application/json' \
     -H "Authorization: Bearer $FCT_TOKEN" \
     'http://localhost:8000/runs/<run_id>?node=<node>'

The snapshot carries the page's title and summary, an as_of, the viewer, the UI structure and the same data the page composes. /runs/<id> and /factories/<id> are the supported page snapshots; the /api/… endpoints remain the source for everything else.

The guide is public: GET /api/docs lists the pages and, when authenticated, your factories, and GET /api/docs/{slug} returns one page's markdown. That is the same content these pages render.

Public blog

Anyone can read GET /api/blog and GET /api/blog/<slug>, or browse /blog. A site administrator can publish or replace a post with a write session or bearer token using PUT /api/blog/<slug> and a JSON body containing title, summary (optional), and markdown. The slug uses lowercase letters, numbers, and hyphens. Publishing makes the post public immediately; replacing it preserves its original publication time. For example:

jq -n --rawfile markdown article.md '{title: "My article", summary: "An introduction", markdown: $markdown}' |
  curl -X PUT -H "Authorization: Bearer $FCT_TOKEN" -H 'Content-Type: application/json' \
    --data-binary @- https://example.com/api/blog/my-article

Administrators can also select Write a post on /blog or Edit post on an article. The editor accepts pasted Markdown or a Markdown file and offers a preview. Saving publishes immediately. For create-only API requests, send If-None-Match: * to avoid replacing an existing slug (the server returns 409).

Articles generated by this repository's content writer address the hosted Factory at https://factory.redbeardlab.com. They use that URL directly, explain how to create any required API token, and do not ask readers to configure environment variables or the hosted deployment.

Your factories

Your factories will appear here. Create one and open it beside this guide.