Skip to content

Workflow Events

Retrieve the ordered sequence of events that make up a workflow's execution history. Events are the fundamental unit of the workflow event-sourcing model — the current state of any workflow can always be reconstructed by replaying its event log from the beginning.

Endpoint

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

Required Role

MEMBER

Headers

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

Path Parameters

ParameterTypeDescription
workflowIdstringThe unique identifier of the workflow.

Query Parameters

ParameterTypeRequiredDescription
fromSeqintegerNoReturn only events with a sequence number greater than or equal to this value. Defaults to 0 (all events). Use this to poll for new events after a known position without re-fetching the full history.

Response Body

The response is a JSON array of event objects, ordered by sequence number ascending.

json
[
  {
    "sequence": 1,
    "workflowId": "wf-abc123",
    "eventType": "WORKFLOW_STARTED",
    "payload": {},
    "occurredAt": "2024-01-15T10:30:00Z"
  },
  {
    "sequence": 2,
    "workflowId": "wf-abc123",
    "eventType": "POLICY_EVALUATED",
    "payload": {
      "policyModule": "Loan.Approval",
      "policyFunction": "isEligible",
      "result": true,
      "executionTimeMs": 6
    },
    "occurredAt": "2024-01-15T10:30:00Z"
  },
  {
    "sequence": 3,
    "workflowId": "wf-abc123",
    "eventType": "WORKFLOW_COMPLETED",
    "payload": {
      "finalResult": true
    },
    "occurredAt": "2024-01-15T10:30:01Z"
  }
]
FieldTypeDescription
sequenceintegerMonotonically increasing sequence number within the workflow. Gaps indicate missing or compacted events.
workflowIdstringIdentifier of the owning workflow (mirrors the path parameter).
eventTypestringEvent classification (e.g. WORKFLOW_STARTED, POLICY_EVALUATED, WORKFLOW_COMPLETED, COMPENSATION_STARTED).
payloadobjectEvent-specific data. Structure varies by eventType.
occurredAtstringISO 8601 timestamp when the event was recorded.

HTTP Status Codes

StatusMeaning
200 OKRequest succeeded. Returns an array (may be empty if fromSeq is beyond the last recorded event).
400 Bad RequestMalformed fromSeq parameter.
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
# Fetch all events for a workflow
curl -X GET "https://policy.aster-lang.dev/api/v1/workflows/wf-abc123/events" \
  -H "Authorization: Bearer <token>" \
  -H "X-Tenant-ID: acme-corp"

# Poll for new events after sequence 42
curl -X GET "https://policy.aster-lang.dev/api/v1/workflows/wf-abc123/events?fromSeq=43" \
  -H "Authorization: Bearer <token>" \
  -H "X-Tenant-ID: acme-corp"
js
const workflowId = 'wf-abc123';

// Fetch all events
const response = await fetch(
  `https://policy.aster-lang.dev/api/v1/workflows/${workflowId}/events`,
  {
    headers: {
      Authorization: 'Bearer <token>',
      'X-Tenant-ID': 'acme-corp',
    },
  }
);

const events = await response.json();

// Poll for new events after a known sequence
async function pollNewEvents(workflowId, lastSeq) {
  const params = new URLSearchParams({ fromSeq: String(lastSeq + 1) });
  const res = await fetch(
    `https://policy.aster-lang.dev/api/v1/workflows/${workflowId}/events?${params}`,
    {
      headers: {
        Authorization: 'Bearer <token>',
        'X-Tenant-ID': 'acme-corp',
      },
    }
  );
  return res.json();
}

Released under the MIT License.