Skip to main content
Create a new workflow that executes custom JavaScript/TypeScript code in response to events. Workflows run in Cloudflare Workers with access to room data, stores, and file storage.

Endpoint

POST /v1/accounts/:accountId/workflows

Authentication

Bearer token required.

Request Body

name
string
required
A descriptive name for the workflow.
code
string
required
JavaScript or TypeScript source code to execute when triggered.
events
string[]
required
List of events that trigger this workflow. At least one event is required. Same event types as webhooks.
roomId
string
Scope the workflow to a specific room. If omitted, the workflow triggers for events in all rooms.

Available Events

EventDescription
participant.joinedA user came online in a room
participant.leftA user went offline
session.startedA new session started
session.closedA session ended
user.createdA new user was added
user.updatedA user’s fields changed
user.deletedA user was removed

Worker Bindings

Your workflow code has access to these bindings:
BindingTypeDescription
storeStoreBindingRead-only access to KV stores
roomRoomBindingRead-only room and user metadata
filesFilesBindingScoped R2 file operations
eventEventBindingThe event that triggered the workflow

Response

workflow
WorkflowRegistration
The created workflow. See WorkflowRegistration.

Example

curl -X POST https://api.collab-kit.com/v1/accounts/${ACCOUNT_ID}/workflows \
  -H "Authorization: Bearer ${TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Welcome message",
    "code": "export default async function(event, { store, room }) {\n  console.log(`User ${event.data.userId} joined room ${event.data.roomId}`);\n  return { success: true };\n}",
    "events": ["participant.joined"]
  }'
Response (201)
{
  "type": "response",
  "success": true,
  "description": "Workflow created",
  "data": {
    "workflow": {
      "id": "wf_abc123",
      "organization_id": "a1b2c3d4-...",
      "name": "Welcome message",
      "code": "export default async function(event, { store, room }) { ... }",
      "events": ["participant.joined"],
      "room_id": null,
      "enabled": true,
      "created_at": "2026-05-29T10:00:00.000Z",
      "updated_at": "2026-05-29T10:00:00.000Z"
    }
  },
  "error": null
}