How a script lists templates, starts a run, reads it, saves step data and completes a step with a personal access token, using the same JSON API the app's screens use.
Every route below is a platform backend route (platform/backend/src/routes/), served by ProcessOS and by each
app's own frontend. The OpenAPI document (applications/main/src/lib/openapi.ts, Swagger UI at /docs/api)
describes each one in full. A step-by-step walk through the same calls on a local install, with no token, is
your first process.
Make a key. Tokens are made from a signed-in browser session: Spell review's setup page
(https://spell-risk.soterlabs.com/mcp/setup, Create key), or POST /api/access-tokens from the app
with { "name", "expiresInDays", "scope" }. The secret (ppat_…) is shown once; keep it in an environment
variable or a secret store. A token cannot make or list tokens.
Choose its access when you make it (personal access tokens):
full (the default) acts as you, with every permission you have, in every application.steps is bound to the application it was made in and can save and complete steps there; it cannot start,
share, abandon, reopen or delete runs.read is bound in the same way and changes nothing: every write is refused (403, with code: token-scope
once the request reaches the run).Whatever its access, a token acts as its owner and never does more than the owner may do now.
Base URL. https://os.soterlabs.com/api reaches every application you are a member of. An app's own
frontend forwards /api/… to the same backend and narrows every list to that app's runs (for example
https://spell-risk.soterlabs.com/api).
Send the key on every request: Authorization: Bearer ppat_…. No cookie or organization header is needed.
GET /api/me answers who the key belongs to, its permissions, and accessTokenScope for a steps or read
key (preset, applicationId, permissions). Add ?templateKey=<key> to get the permissions in that
template's application (platform/backend/src/routes/me/route.ts).
| Request | Needs | Source |
|---|---|---|
GET /api/process-templates | processes:read | platform/backend/src/routes/process-templates/route.ts |
POST /api/process | processes:write and the template's start permissions | platform/backend/src/routes/process/route.ts |
GET /api/process | signed in; rows you may read | platform/backend/src/routes/process/route.ts |
GET /api/process/{id} | read access to the run | platform/backend/src/routes/process/[id]/route.ts |
PUT /api/process/{id}/steps/{visitId} | edit access, the step's and each field's permission | platform/backend/src/routes/process/[id]/steps/[stepId]/route.ts |
POST /api/process/{id}/steps/{visitId}/complete | as PUT, and the run waiting on that visit | platform/backend/src/routes/process/[id]/steps/[stepId]/complete/route.ts |
Use GET /api/process-templates, not GET /api/templates: the second is the template definitions route and needs
templates:read, which most people do not hold.
GET /api/process-templates returns the templates of every application where you hold processes:read, newest
version of each: key, name, description, status (archived templates cannot be started), processMode
(tight or loose), firstStepKey and steps. Each step has key, title, type (input for a form a
person fills), permissions (who may act on it, any one of them) and inputs, the fields: key, title,
type, permissions and the like. A field whose choices come from a data source lists its live entries at
GET /api/templates/{key}/choice-sources/{source}.
POST /api/process
{ "templateKey": "<key>", "initialValues": {} }
initialValues is optional and must be an object; the template's start rules decide which values, if any, it
seeds. The answer is the new run, in the shape GET /api/process/{id} returns. A steps or read key is
refused (403): start runs with a full-access key.
GET /api/process/{id} returns one run as you may see it:
status: running or completed; revision counts its writes.steps: the step visits reached so far, in order, each { id, stepKey, … }. While the run is running,
the last one is the current step. A loop visits the same stepKey again with a new id.context: every saved answer, keyed by step key, then field key (context.<stepKey>.<fieldKey>).canActOnCurrentStep: you may save on the current step now; canCompleteCurrentStep: its completion rule is
met as things stand.executionPending and automaticWait: the run is busy with an automatic step (the worker runs it); no one can
act until it reaches the next form.template.steps: the steps and fields of the version the run is pinned to; fieldAudit: who changed which
field, when.A field or note you may not read is left out of every read. A run you may not read answers 404.
GET /api/process lists the runs you may read, as an array of the same shape. ?templates=shared returns
{ templates, processes } instead, each template once and each row naming it by templateRef.
?contextPath=<stepKey>.<fieldKey>&contextValue=<value> keeps only the rows with that exact value.
PUT /api/process/{id}/steps/{visitId}
{ "<fieldKey>": <value>, … }
{visitId} is the visit's id from steps, not the step key.context[stepKey]: fields you do not send keep
their values.processMode is loose, which also lets you correct an earlier
form.strict step refuses it (403 field-forbidden); others drop it without an error, so compare context[stepKey] in the answer with what you
sent. A field the step does not declare is refused (400 unknown-field) on a strict step.{ "id", "name" }. Send the entry's id (from
GET /api/templates/{key}/choice-sources/{source}); the server records the name.The answer is the run after the write.
POST /api/process/{id}/steps/{visitId}/complete
{ "<fieldKey>": <value>, … }
The body is optional. Values in it are saved first, as by PUT; then the step is completed if its mandatory fields
are filled and its completion rule holds. Only the current visit, and only while the run waits on it. The answer is
{ process, nextStepKey }: the run after the write and the step it moved to (null when no step is open, for
example when the run finished).
Refusals answer { "error", "code", "reasons"? }:
| Status | Common code | Meaning |
|---|---|---|
401 | The key is wrong, expired or revoked. | |
403 | token-scope | The key's access does not allow this (a read key saving or completing, a steps key sharing or abandoning). |
403 | activity-forbidden, field-forbidden, past-step | You may not act on this step or field, or the visit is not the current one. |
404 | No such run, or one you may not read. | |
409 | terminal, not-waiting, held | The run has finished, is not waiting on that visit, or is held for reconciliation. |
422 | completion | The completion rule is not met; reasons names the fields still needed. |
requests)Starts a run, fills its first form and completes it, then lists the runs waiting on you. Needs a full-access key
(a steps key can do everything here but the start).
#!/usr/bin/env python3
"""Start a ProcessOS run, fill its first form, complete it, and list what waits on you."""
import json
import os
import sys
import time
import requests
BASE = os.environ.get("PROCESSOS_API", "https://os.soterlabs.com/api")
KEY = os.environ["PROCESSOS_KEY"] # ppat_...
TEMPLATE = sys.argv[1] # a template key from GET /api/process-templates
VALUES = json.loads(sys.argv[2]) if len(sys.argv) > 2 else {} # {"fieldKey": value, ...}
session = requests.Session()
session.headers["Authorization"] = f"Bearer {KEY}"
def call(method, path, body=None, **params):
response = session.request(method, BASE + path, json=body, params=params, timeout=60)
if response.status_code >= 400:
sys.exit(f"{method} {path}: {response.status_code} {response.text}")
return response.json()
templates = {t["key"]: t for t in call("GET", "/process-templates")}
if TEMPLATE not in templates:
sys.exit(f"Unknown template {TEMPLATE}; you may start one of: {', '.join(sorted(templates))}")
run = call("POST", "/process", {"templateKey": TEMPLATE, "initialValues": {}})
run_id = run["processId"]
while run["status"] == "running" and run.get("executionPending"): # an automatic step first: wait for the worker
time.sleep(2)
run = call("GET", f"/process/{run_id}")
if run["status"] != "running" or not run["canActOnCurrentStep"]:
sys.exit(f"{run_id}: nothing for you to do now ({run['status']})")
visit = run["steps"][-1] # the current visit
print(f"{run_id}: at {visit['stepKey']} (visit {visit['id']})")
run = call("PUT", f"/process/{run_id}/steps/{visit['id']}", VALUES)
saved = run["context"].get(visit["stepKey"], {})
differs = [key for key, value in VALUES.items() if saved.get(key) != value]
if differs:
print("Not saved as sent (check your permission on these fields):", ", ".join(differs))
result = call("POST", f"/process/{run_id}/steps/{visit['id']}/complete", {})
print(f"Completed {visit['stepKey']}; next: {result['nextStepKey'] or 'finished'}")
waiting = [r for r in call("GET", "/process") if r["status"] == "running" and r["canActOnCurrentStep"]]
for row in sorted(waiting, key=lambda r: r["updatedAt"]):
print(f" waiting on you: {row['processId']} {row['template']['key']} at {row['steps'][-1]['stepKey']}")
Run it with PROCESSOS_KEY=ppat_… python3 run.py <template-key> '{"fieldKey": "value"}'. A read key can run
the reads only: GET /api/me, /api/process-templates, /api/process and /api/process/{id}.
A write made with a token is recorded under its owner's name, exactly as one made in the browser. The session is
recorded too: a completed visit's updatedBySessionId is access-token:<token id>, so the audit shows which key
made it. Revoking the key on the page it was made on stops it at once.