{"openapi":"3.0.3","info":{"title":"Stagecoach HTTP API","version":"1","description":"The API a Stagecoach server exposes to the\n[`drupal\/stage_coach`](https:\/\/www.drupal.org\/project\/stage_coach) module,\nscripts and CI. It is the contract in the module\u0027s\n[docs\/STAGE_COACH_API.md](https:\/\/git.drupalcode.org\/project\/stage_coach\/-\/blob\/main\/docs\/STAGE_COACH_API.md).\n\nOn both plans the server runs in your own cluster (the `stagecoach` Helm\nchart). The module reaches it one of two ways, listed under Servers:\n\n- **Self-hosted** (Community): directly, at its Service, e.g.\n  `http:\/\/stagecoach.stagecoach.svc:8080`, with the server\u0027s API token.\n- **Hosted**: through `https:\/\/api.stagecoach.sh\/v1\/clusters\/{clusterId}`,\n  which relays each `\/api\/*` request to the server, with a *site* token\n  from the stagecoach.sh portal (CI uses a *release* token, which may only\n  `POST \/api\/releases`). `GET \/events` is not relayed: poll `\/api\/state`.\n  Errors from stagecoach.sh itself (token refused, cluster unknown or not\n  connected) are `{\u0022error\u0022: {\u0022code\u0022: ..., \u0022message\u0022: ...}}`.\n\n**Writes are form-encoded.** Booleans are the literal string `true`;\nanything else, or leaving the field out, is false.\n\n**Operations are single-flight.** A write that starts an operation answers\n`202` straight away and the work continues in the background; progress\narrives on `GET \/events` or by polling `GET \/api\/state`. Starting a second\noperation while one runs answers `409`, naming the running one.\n\n**JSON answers.** Send `Accept: application\/json` to get JSON bodies on\nwrites (`{\u0022operation\u0022: ...}`) and errors (`{\u0022error\u0022: ...}`). Without it,\nwrites answer plain text (`started`, `cancelled`, `recorded`), which is what\nthe bundled web UI expects.\n\n`POST \/api\/console` (command execution in a running container) and schedule\nmanagement exist for the bundled UI and the CLI. They are deliberately not\npart of this API and the module does not use them.\n","license":{"name":"GPL-2.0-or-later","url":"https:\/\/www.gnu.org\/licenses\/old-licenses\/gpl-2.0.html"}},"servers":[{"url":"{server}","description":"Self-hosted (Community) \u2014 your Stagecoach server, directly","variables":{"server":{"default":"http:\/\/stagecoach.stagecoach.svc:8080","description":"The server\u0027s Service URL, as the chart\u0027s install notes print it."}}},{"url":"https:\/\/api.stagecoach.sh\/v1\/clusters\/{clusterId}","description":"Hosted \u2014 through stagecoach.sh to the server in your cluster","variables":{"clusterId":{"default":"cl_0123456789abcdef","description":"The cluster\u0027s id, shown in the portal and in the server\u0027s log."}}}],"security":[{"apiToken":[]}],"tags":[{"name":"Read","description":"What the environment grid, dashboard and Drush commands show."},{"name":"Operations","description":"Long-running, single-flight writes. Each answers `202` and runs in the background."},{"name":"Control","description":"Instant control-plane writes."},{"name":"Releases","description":"CI records the images it builds so environments can be deployed by git ref."},{"name":"Events","description":"The live stream the bundled UI runs on."},{"name":"Environment status","description":"Served by each managed Drupal site (the module\u0027s `StatusReporter`), not by\nStagecoach. Phase 2 of the contract: Stagecoach may poll it on the grid tick\nand treat pending updates or config drift after a deploy as a failed check.\n"}],"paths":{"\/api\/version":{"get":{"tags":["Read"],"summary":"API and server version","operationId":"getVersion","responses":{"200":{"description":"The API version, bumped only for changes clients must know about, and the server build.","content":{"application\/json":{"schema":{"type":"object","required":["api","stage_coach"],"properties":{"api":{"type":"integer","example":1},"stage_coach":{"type":"string","example":1817446}}}}}},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/grid":{"get":{"tags":["Read"],"summary":"Environment grid","description":"One row per registered environment, in promotion order (`rank`).","operationId":"getGrid","responses":{"200":{"description":"The environments.","content":{"application\/json":{"schema":{"type":"array","items":{"$ref":"#\/components\/schemas\/GridRow"}}}}},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/jobs":{"get":{"tags":["Read"],"summary":"Jobs of the current and recent sequences","operationId":"getJobs","responses":{"200":{"description":"Kubernetes Jobs Stagecoach planned, by sequence (`group`) and step (`seq`).","content":{"application\/json":{"schema":{"type":"array","items":{"$ref":"#\/components\/schemas\/JobRow"}}}}},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/state":{"get":{"tags":["Read"],"summary":"The running operation","operationId":"getState","responses":{"200":{"description":"Whether an operation is running, which, and its log so far.","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/State"}}}},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/snapshots":{"get":{"tags":["Read"],"summary":"Database snapshots","operationId":"getSnapshots","parameters":[{"name":"env","in":"query","description":"Only this environment\u0027s snapshots.","schema":{"type":"string"},"example":"prod"}],"responses":{"200":{"description":"Snapshots by environment, newest first within each.","content":{"application\/json":{"schema":{"type":"array","items":{"$ref":"#\/components\/schemas\/SnapshotRow"}}}}},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/history":{"get":{"tags":["Read"],"summary":"Audit log","operationId":"getHistory","parameters":[{"name":"limit","in":"query","description":"How many entries. Values above 500 are capped at 500.","schema":{"type":"integer","minimum":1,"default":50}}],"responses":{"200":{"description":"Audit entries, newest first.","content":{"application\/json":{"schema":{"type":"array","items":{"$ref":"#\/components\/schemas\/HistoryRow"}}}}},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/stalled":{"get":{"tags":["Read"],"summary":"Stalled sequences","description":"Sequences whose next step cannot run until someone resumes or cancels them.","operationId":"getStalled","responses":{"200":{"description":"The stalled sequences.","content":{"application\/json":{"schema":{"type":"array","items":{"$ref":"#\/components\/schemas\/StallRow"}}}}},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/schedules":{"get":{"tags":["Read"],"summary":"Schedules","description":"Read-only here. Schedules are managed in the bundled UI and the CLI.","operationId":"getSchedules","responses":{"200":{"description":"The schedules.","content":{"application\/json":{"schema":{"type":"array","items":{"$ref":"#\/components\/schemas\/ScheduleRow"}}}}},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/releases":{"get":{"tags":["Releases","Read"],"summary":"Recorded releases","operationId":"getReleases","responses":{"200":{"description":"Releases CI recorded, newest first.","content":{"application\/json":{"schema":{"type":"array","items":{"$ref":"#\/components\/schemas\/ReleaseRow"}}}}},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}},"post":{"tags":["Releases"],"summary":"Record a release","description":"For CI, authenticated with the **release token** (`serve -release-token`),\nwhich is accepted on this one request and nowhere else. The API token is\nnot accepted here: the Drupal site never needs to record releases.\n","operationId":"recordRelease","security":[{"releaseToken":[]}],"requestBody":{"required":true,"content":{"application\/x-www-form-urlencoded":{"schema":{"type":"object","required":["image","ref"],"properties":{"image":{"type":"string","description":"Image reference, ideally by digest.","example":"ghcr.io\/example\/site@sha256:2dc8\u2026"},"ref":{"type":"string","description":"Git ref the image was built from.","example":"v2.1.0"},"sha":{"type":"string","description":"Git commit sha.","example":1817446},"built_at":{"type":"string","format":"date-time","description":"When CI built it (RFC 3339)."}}}}}},"responses":{"201":{"description":"Recorded.","content":{"text\/plain":{"schema":{"type":"string","example":"recorded"}}}},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"404":{"description":"Release recording is not enabled (the server was started without `-release-token`).","content":{"text\/plain":{"schema":{"type":"string"}}}}}}},"\/api\/deploy":{"post":{"tags":["Operations"],"summary":"Deploy an image or release","description":"Takes a pre-deploy snapshot, patches the workload\u0027s image, waits for the\nrollout, then runs `drush updatedb` and `drush config:import` behind\nmaintenance mode. Give exactly one of `image` or `release`.\n","operationId":"deploy","parameters":[{"$ref":"#\/components\/parameters\/Actor"}],"requestBody":{"required":true,"content":{"application\/x-www-form-urlencoded":{"schema":{"type":"object","required":["env"],"properties":{"env":{"type":"string","example":"stage"},"image":{"type":"string","description":"An image reference."},"release":{"type":"string","description":"A recorded release\u0027s git ref.","example":"v2.1.0"},"skip_update":{"$ref":"#\/components\/schemas\/FormBool"},"skip_config_import":{"$ref":"#\/components\/schemas\/FormBool"},"no_snapshot":{"$ref":"#\/components\/schemas\/FormBool"}}}}}},"responses":{"202":{"$ref":"#\/components\/responses\/Started"},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"409":{"$ref":"#\/components\/responses\/Busy"}}}},"\/api\/copy-down":{"post":{"tags":["Operations"],"summary":"Copy database and files to a lower environment","description":"Copies `from` into `to` and sanitizes the copy with `drush sql:sanitize`.\nCopying files across namespaces needs an `s3:\/\/` snapshot store.\n","operationId":"copyDown","parameters":[{"$ref":"#\/components\/parameters\/Actor"}],"requestBody":{"required":true,"content":{"application\/x-www-form-urlencoded":{"schema":{"type":"object","required":["from","to"],"properties":{"from":{"type":"string","example":"prod"},"to":{"type":"string","example":"dev"},"skip_files":{"$ref":"#\/components\/schemas\/FormBool"},"skip_db":{"$ref":"#\/components\/schemas\/FormBool"},"clean":{"allOf":[{"$ref":"#\/components\/schemas\/FormBool"}],"description":"Remove target files absent from the source."}}}}}},"responses":{"202":{"$ref":"#\/components\/responses\/Started"},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"409":{"$ref":"#\/components\/responses\/Busy"}}}},"\/api\/snapshot":{"post":{"tags":["Operations"],"summary":"Snapshot an environment\u0027s database","operationId":"snapshot","parameters":[{"$ref":"#\/components\/parameters\/Actor"}],"requestBody":{"required":true,"content":{"application\/x-www-form-urlencoded":{"schema":{"type":"object","required":["env"],"properties":{"env":{"type":"string","example":"prod"}}}}}},"responses":{"202":{"$ref":"#\/components\/responses\/Started"},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"409":{"$ref":"#\/components\/responses\/Busy"}}}},"\/api\/restore":{"post":{"tags":["Operations"],"summary":"Restore a snapshot","description":"Restores the snapshot into `env` with the site scaled down, then rebuilds caches.","operationId":"restore","parameters":[{"$ref":"#\/components\/parameters\/Actor"}],"requestBody":{"required":true,"content":{"application\/x-www-form-urlencoded":{"schema":{"type":"object","required":["env","snapshot"],"properties":{"env":{"type":"string","example":"dev"},"snapshot":{"type":"integer","format":"int64","description":"A snapshot `id` from `GET \/api\/snapshots`."}}}}}},"responses":{"202":{"$ref":"#\/components\/responses\/Started"},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"409":{"$ref":"#\/components\/responses\/Busy"}}}},"\/api\/rollback":{"post":{"tags":["Operations"],"summary":"Roll back the last deploy","description":"Redeploys the image in the grid row\u0027s `rollback_to`; with `with_data`, also restores the pre-deploy snapshot.","operationId":"rollback","parameters":[{"$ref":"#\/components\/parameters\/Actor"}],"requestBody":{"required":true,"content":{"application\/x-www-form-urlencoded":{"schema":{"type":"object","required":["env"],"properties":{"env":{"type":"string","example":"prod"},"with_data":{"$ref":"#\/components\/schemas\/FormBool"}}}}}},"responses":{"202":{"$ref":"#\/components\/responses\/Started"},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"409":{"$ref":"#\/components\/responses\/Busy"}}}},"\/api\/resume":{"post":{"tags":["Operations"],"summary":"Resume stalled sequences","operationId":"resume","parameters":[{"$ref":"#\/components\/parameters\/Actor"}],"responses":{"202":{"$ref":"#\/components\/responses\/Started"},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"409":{"$ref":"#\/components\/responses\/Busy"}}}},"\/api\/cancel":{"post":{"tags":["Control"],"summary":"Cancel a stalled sequence","description":"Runs inline rather than as an operation, so it answers with the outcome.","operationId":"cancel","parameters":[{"$ref":"#\/components\/parameters\/Actor"}],"requestBody":{"required":true,"content":{"application\/x-www-form-urlencoded":{"schema":{"type":"object","required":["group"],"properties":{"group":{"type":"string","description":"A sequence `group` from `GET \/api\/stalled`."}}}}}},"responses":{"200":{"description":"Cancelled.","content":{"application\/json":{"schema":{"type":"object","properties":{"operation":{"type":"string","example":"cancel deploy-20261024-0101"}}}},"text\/plain":{"schema":{"type":"string","example":"cancelled"}}}},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"409":{"description":"The sequence cannot be cancelled.","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/Error"}}}}}}},"\/events":{"get":{"tags":["Events"],"summary":"Server-sent events","description":"A `text\/event-stream` carrying the same rows as the read endpoints whenever\nthey change. Event names: `grid`, `jobs`, `stalled`, `snapshots`,\n`history`, `releases`, `schedules`, `state` and `log`. Each `data:` line is\nJSON. PHP clients should prefer the read endpoints, which need no open\nstream.\n","operationId":"events","responses":{"200":{"description":"The event stream.","content":{"text\/event-stream":{"schema":{"type":"string"},"example":"event: state\ndata: {\u0022running\u0022:true,\u0022operation\u0022:\u0022deploy stage v2.1.0\u0022,\u0022log\u0022:[]}\n"}}},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/stage_coach\/status":{"servers":[{"url":"{site}","description":"A managed Drupal site with stage_coach enabled","variables":{"site":{"default":"https:\/\/dev.example.com"}}}],"get":{"tags":["Environment status"],"summary":"Drupal environment status","description":"Answers `404` unless `$settings[\u0027stage_coach_status_token\u0027]` is set in that\nenvironment\u0027s settings.php, so copy-down never moves the token. Any field\nmay be `null` if its probe failed.\n","operationId":"getEnvironmentStatus","security":[{"statusToken":[]}],"responses":{"200":{"description":"The site\u0027s status.","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/EnvironmentStatus"}}}},"401":{"description":"Missing or wrong status token."},"404":{"description":"No status token is configured on this site."}}}}},"components":{"securitySchemes":{"apiToken":{"type":"http","scheme":"bearer","description":"Self-hosted: the server\u0027s API token (`serve -api-token`, env\n`STAGE_COACH_API_TOKEN`), accepted on every `\/api\/*` path and on\n`\/events`, never on the HTML UI. Hosted: a site token from the\nstagecoach.sh portal, accepted for the cluster it names. The module\nreads it from `$settings[\u0027stage_coach_api_token\u0027]`, never from config.\n"},"releaseToken":{"type":"http","scheme":"bearer","description":"CI\u0027s release token. Self-hosted, the server\u0027s own (`serve -release-token`); hosted, a release token from the stagecoach.sh portal for the cluster it names. Only `POST \/api\/releases` accepts it."},"statusToken":{"type":"http","scheme":"bearer","description":"A managed site\u0027s own `$settings[\u0027stage_coach_status_token\u0027]`."}},"parameters":{"Actor":{"name":"X-Stage-Coach-Actor","in":"header","description":"Who to record in the audit log. Honoured only on requests authenticated\nwith the API token; anything else is recorded as `web`. With the token and\nno header, the actor is `api`. A value that does not match the pattern is\nrefused with `400`.\n","schema":{"type":"string","pattern":"^[a-z]+:[A-Za-z0-9._@-]{1,64}$"},"example":"drupal:admin"}},"responses":{"Started":{"description":"The operation started. Follow it on `GET \/api\/state` or `GET \/events`.","content":{"application\/json":{"schema":{"type":"object","required":["operation"],"properties":{"operation":{"type":"string","description":"The operation\u0027s label, for showing to the person who started it.","example":"deploy stage v2.1.0"}}}},"text\/plain":{"schema":{"type":"string","example":"started"}}}},"Busy":{"description":"Another operation is running.","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/Error"},"example":{"error":"deploy prod v2.0.9 is already running"}}}},"BadRequest":{"description":"A required field is missing or invalid.","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/Error"},"example":{"error":"deploy needs env and exactly one of image or release"}}}},"Unauthorized":{"description":"No valid credential.","content":{"text\/plain":{"schema":{"type":"string","example":"unauthorized"}}}}},"schemas":{"FormBool":{"type":"string","enum":["true"],"description":"The literal string `true`. Leave the field out for false."},"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"string"}}},"GridRow":{"type":"object","properties":{"env":{"type":"string","example":"prod"},"namespace":{"type":"string","example":"mysite"},"host":{"type":"string","example":"example.com"},"rank":{"type":"integer","description":"Promotion order; higher is further along.","example":30},"prod":{"type":"boolean"},"code":{"type":"string","description":"Short digest of the running image, for display."},"pinned":{"type":"boolean","description":"The workload names a digest rather than a tag."},"promote":{"type":"string","description":"The exact ref a promotion out of this environment would deploy; empty if not traceable."},"release":{"type":"string","description":"Git ref of the running image, if CI recorded it."},"git_sha":{"type":"string","description":"Short sha of that release."},"replicas":{"type":"string","example":"2\/2"},"state":{"type":"string","description":"Rollout state of the workload."},"db_synced":{"type":"string","description":"When a database was last copied into this environment; empty if never."},"files_synced":{"type":"string","description":"When files were last copied into this environment; empty if never."},"snapshots":{"type":"integer","description":"How many database snapshots are recorded for this environment."},"rollback_to":{"type":"string","description":"The image the last deploy would roll back to; empty if there is nothing to undo."}}},"JobRow":{"type":"object","properties":{"group":{"type":"string","description":"The sequence this Job belongs to."},"seq":{"type":"integer","description":"Step number within the sequence."},"env":{"type":"string"},"kind":{"type":"string","example":"snapshot"},"state":{"type":"string"},"reason":{"type":"string"},"updated":{"type":"string"}}},"StallRow":{"type":"object","properties":{"group":{"type":"string"},"env":{"type":"string"},"seq":{"type":"integer"},"kind":{"type":"string"},"state":{"type":"string"},"reason":{"type":"string"},"waiting":{"type":"integer","description":"Steps waiting behind the stalled one."}}},"SnapshotRow":{"type":"object","properties":{"id":{"type":"integer","format":"int64"},"env":{"type":"string"},"taken":{"type":"string"},"key":{"type":"string","description":"Where the dump is stored, e.g. a `pvc:\/\/` or `s3:\/\/` key."},"sanitized":{"type":"boolean"}}},"HistoryRow":{"type":"object","properties":{"when":{"type":"string"},"actor":{"type":"string","example":"drupal:admin"},"action":{"type":"string","example":"deploy"},"target":{"type":"string","example":"stage"},"ok":{"type":"boolean"},"outcome":{"type":"string","description":"`ok`, or the first line of the failure."}}},"ReleaseRow":{"type":"object","properties":{"built":{"type":"string"},"ref":{"type":"string","example":"v2.1.0"},"git_sha":{"type":"string"},"image":{"type":"string"}}},"ScheduleRow":{"type":"object","properties":{"name":{"type":"string"},"spec":{"type":"string","description":"Cron expression.","example":"0 3 * * *"},"what":{"type":"string","description":"Human summary of the operation."},"env":{"type":"string","description":"The environment acted on (for copy-down, the target)."},"enabled":{"type":"boolean"},"next":{"type":"string","description":"Next fire time; empty if disabled."},"last_run":{"type":"string"},"last_status":{"type":"string"}}},"State":{"type":"object","properties":{"running":{"type":"boolean"},"operation":{"type":"string","example":"deploy stage v2.1.0"},"log":{"type":"array","items":{"type":"string"}}}},"EnvironmentStatus":{"type":"object","properties":{"schema":{"type":"integer","example":1},"drupal":{"type":"string","nullable":true,"example":"11.2.5"},"php":{"type":"string","nullable":true,"example":"8.3.12"},"maintenance_mode":{"type":"boolean","nullable":true},"last_cron":{"type":"string","format":"date-time","nullable":true},"pending_updates":{"type":"object","nullable":true,"properties":{"update_hooks":{"type":"integer"},"post_updates":{"type":"integer"}}},"config":{"type":"object","nullable":true,"properties":{"in_sync":{"type":"boolean"},"changes":{"type":"integer"}}},"generated":{"type":"string","format":"date-time"}}}}}}