Quickstart

Install the SDK, get an API key, and create your first workflow.

1. Install

bash
npm install @clockwork/sdk
# or
pnpm add @clockwork/sdk

2. Get an API key

  1. Sign in at console.clockwork-co.com
  2. Go to Settings → API Keys and click Create key
  3. Copy the key — it starts with ck_live_ and is shown only once

3. Create a workflow

typescript
import { Clockwork } from '@clockwork/sdk'
 
const client = new Clockwork({
  apiKey: process.env.CLOCKWORK_API_KEY,
})
 
// Create a workflow instance
const { data: instance } = await client.workflowInstances.create({
  subjectType: 'onboarding',
  subjectId: 'employee-42',
})
 
// Add tasks
const { data: task1 } = await client.tasks.create({
  name: 'Set up workstation',
  workflowInstanceId: instance.id,
  durationMinutes: 60,
  priority: 'high',
})
 
const { data: task2 } = await client.tasks.create({
  name: 'Complete security training',
  workflowInstanceId: instance.id,
  durationMinutes: 120,
})
 
// task2 starts only after task1 finishes
await client.dependencies.create({
  fromTaskId: task1.id,
  toTaskId: task2.id,
})
 
// Complete task1
const { data: result } = await client.tasks.complete(task1.id)
console.log('Unlocked tasks:', result.unlockedTasks)
// → [{ id: '...', name: 'Complete security training' }]

4. Listen for events

typescript
// Stream real-time task events
for await (const event of client.events.stream()) {
  if (event.type === 'task.completed') {
    console.log('Task completed:', event.data)
  }
}

Or subscribe a webhook endpoint to receive events as HTTP POST requests:

typescript
const { data: sub } = await client.events.subscribe({
  url: 'https://yourapp.com/webhooks/clockwork',
  events: ['task_completed', 'task_delayed', 'conflict_detected'],
})
 
// Store sub.secret — you'll use it to verify incoming webhook payloads
console.log('Webhook secret:', sub.secret)

Next steps