Skip to content

Workflow State

Retrieve the current materialized state of a workflow. The state is derived from the workflow's event log and may be supplemented by a periodic snapshot to accelerate reads. Use this endpoint when you need the latest status and result without fetching the full event history.

Endpoint

GET /api/v1/workflows/{workflowId}/state

Required Role

MEMBER

Headers

HeaderValueRequired
AuthorizationBearer <token>Yes
X-Tenant-IDTenant identifier stringYes

Path Parameters

ParameterTypeDescription
workflowIdstringThe unique identifier of the workflow.

Response Body

json
{
  "workflowId": "wf-abc123",
  "status": "COMPLETED",
  "lastEventSeq": 5,
  "result": {
    "eligible": true,
    "approvedAmount": 25000
  },
  "snapshot": {
    "intermediateState": "..."
  },
  "snapshotSeq": 3,
  "createdAt": "2024-01-15T10:29:58Z",
  "updatedAt": "2024-01-15T10:30:01Z"
}
FieldTypeDescription
workflowIdstringUnique identifier of the workflow.
statusstringCurrent lifecycle status. See Status Values below.
lastEventSeqintegerSequence number of the most recently applied event.
resultany | nullFinal output produced by the workflow. Populated once status reaches a terminal state (COMPLETED, FAILED, COMPENSATED, COMPENSATION_FAILED). null for non-terminal workflows.
snapshotobject | nullOpaque intermediate state snapshot used to accelerate event replay. null if no snapshot has been taken yet.
snapshotSeqinteger | nullSequence number at which the snapshot was taken. null when snapshot is null.
createdAtstringISO 8601 timestamp when the workflow was created.
updatedAtstringISO 8601 timestamp of the most recent state change.

Status Values

StatusTerminalDescription
READYNoWorkflow has been created but not yet started.
RUNNINGNoWorkflow is actively executing.
COMPLETEDYesWorkflow finished successfully. result is populated.
FAILEDYesWorkflow terminated due to an unrecoverable error.
COMPENSATINGNoWorkflow is executing compensation (rollback) steps.
COMPENSATEDYesCompensation completed successfully.
COMPENSATION_FAILEDYesCompensation steps also failed. Manual intervention may be required.

HTTP Status Codes

StatusMeaning
200 OKRequest succeeded. Returns the current workflow state.
401 UnauthorizedMissing or invalid bearer token.
403 ForbiddenToken is valid but the caller lacks the MEMBER role, or the workflow belongs to a different tenant.
404 Not FoundNo workflow found with the given workflowId.
500 Internal Server ErrorUnexpected engine failure.

Examples

bash
curl -X GET "https://policy.aster-lang.dev/api/v1/workflows/wf-abc123/state" \
  -H "Authorization: Bearer <token>" \
  -H "X-Tenant-ID: acme-corp"
js
const workflowId = 'wf-abc123';
const response = await fetch(
  `https://policy.aster-lang.dev/api/v1/workflows/${workflowId}/state`,
  {
    headers: {
      Authorization: 'Bearer <token>',
      'X-Tenant-ID': 'acme-corp',
    },
  }
);

const state = await response.json();

if (state.status === 'COMPLETED') {
  console.log('Workflow result:', state.result);
} else if (state.status === 'FAILED') {
  console.error('Workflow failed. Last event sequence:', state.lastEventSeq);
}

Example Response

json
{
  "workflowId": "wf-abc123",
  "status": "COMPLETED",
  "lastEventSeq": 5,
  "result": {
    "eligible": true,
    "approvedAmount": 25000
  },
  "snapshot": null,
  "snapshotSeq": null,
  "createdAt": "2024-01-15T10:29:58Z",
  "updatedAt": "2024-01-15T10:30:01Z"
}

Released under the MIT License.