Skip to main content

Overview

This guide covers advanced task management patterns including batch operations, assignment workflows, draft management, and filtering strategies.

Task Lifecycle

Understanding the complete task lifecycle helps you build robust integrations:

Creating Tasks

Basic Task Creation

const task = await fetch('https://app.daycopilot.ai/api/v1/tasks', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    title: 'Complete Q4 planning',
    description: 'Finalize objectives and key results',
    priority: 'high',
    status: 'pending',
    due_date: '2025-12-15T17:00:00Z'
  })
}).then(r => r.json());

console.log('Task ID:', task.data.id);

Task in Context

Create task within a specific context (project):
const task = await createTask({
  title: 'Review API documentation',
  context_id: 'project-uuid',
  priority: 'medium'
});

Task with Time Estimate

const task = await createTask({
  title: 'Implement user authentication',
  time_estimate_minutes: 240, // 4 hours
  due_date: '2025-11-10T17:00:00Z'
});

Assigning Tasks

Assign to User

POST /api/v1/tasks/{taskId}/assign
{
  "user_email": "colleague@example.com",
  "notify": true
}
Response:
{
  "data": {
    "task_id": "task-uuid",
    "assignee": {
      "user_id": "user-uuid",
      "email": "colleague@example.com",
      "assigned_at": "2025-11-02T12:00:00Z"
    }
  }
}

Multiple Assignees

// Assign to multiple users
const assignees = ['alice@example.com', 'bob@example.com'];

for (const email of assignees) {
  await fetch(`https://app.daycopilot.ai/api/v1/tasks/${taskId}/assign`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ user_email: email, notify: true })
  });
}

Get Assigned Tasks

# Get tasks assigned to me
GET /api/v1/tasks/assigned

# Filter by status
GET /api/v1/tasks/assigned?status=in_progress

Filtering & Searching

By Status

GET /api/v1/tasks?status=pending,in_progress

By Priority

GET /api/v1/tasks?priority=high,urgent

By Context

GET /api/v1/tasks?context_id=project-uuid

By Due Date Range

GET /api/v1/tasks?due_after=2025-11-01&due_before=2025-11-30
GET /api/v1/tasks/search?q=api+documentation
Response:
{
  "data": [
    {
      "id": "task-uuid",
      "title": "Complete API documentation",
      "description": "Write comprehensive API docs",
      "relevance_score": 0.95
    }
  ]
}

Complex Filtering Example

const filters = {
  status: ['pending', 'in_progress'],
  priority: ['high', 'urgent'],
  context_id: 'project-uuid',
  assigned_to_me: true,
  due_before: '2025-12-01T00:00:00Z',
  limit: 50,
  offset: 0
};

const queryString = new URLSearchParams(filters).toString();
const tasks = await fetch(
  `https://app.daycopilot.ai/api/v1/tasks?${queryString}`,
  { headers: { 'Authorization': `Bearer ${token}` } }
).then(r => r.json());

Draft Workflow

Making Changes as Draft

// Update task (creates draft)
const draft = await fetch(`https://app.daycopilot.ai/api/v1/tasks/${taskId}`, {
  method: 'PUT',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    title: 'Updated title',
    description: 'Updated description',
    priority: 'urgent'
  })
}).then(r => r.json());

console.log('Draft version:', draft.data.version_minor);
console.log('Published:', draft.data.is_published); // false

Publishing Draft

const published = await fetch(
  `https://app.daycopilot.ai/api/v1/tasks/${taskId}/draft`,
  {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ action: 'accept' })
  }
).then(r => r.json());

console.log('New version:', published.data.version_major); // Incremented

Discarding Draft

await fetch(`https://app.daycopilot.ai/api/v1/tasks/${taskId}/draft`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ action: 'discard' })
});

// Task reverted to last published state

Comments & Discussion

Add Comment

const comment = await fetch(
  `https://app.daycopilot.ai/api/v1/tasks/${taskId}/comments`,
  {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      message: 'Updated priority based on stakeholder feedback'
    })
  }
).then(r => r.json());

console.log('Comment timestamp:', comment.data.created_at);

List Comments

GET /api/v1/tasks/{taskId}/comments
Response:
{
  "data": [
    {
      "task_id": "task-uuid",
      "message": "Great progress!",
      "created_at": "2025-11-02T12:00:00Z",
      "user_id": "user-uuid",
      "user_name": "Alice Smith"
    }
  ]
}

Update Comment

// Use timestamp as ID
const timestamp = '2025-11-02T12:00:00Z';

await fetch(
  `https://app.daycopilot.ai/api/v1/tasks/${taskId}/comments/${timestamp}`,
  {
    method: 'PUT',
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      message: 'Updated comment text'
    })
  }
);

Status Management

Update Status

// Direct status update (no draft)
await fetch(`https://app.daycopilot.ai/api/v1/tasks/${taskId}`, {
  method: 'PUT',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    status: 'in_progress',
    publish: true  // Skip draft workflow
  })
});

Complete Task

POST /api/v1/tasks/{taskId}/complete
This is a shortcut for:
{
  "status": "completed",
  "completed_at": "2025-11-02T12:00:00Z",
  "publish": true
}

Cancel Task

await fetch(`https://app.daycopilot.ai/api/v1/tasks/${taskId}`, {
  method: 'PUT',
  headers: {
    'Authorization': `Bearer ${token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    status: 'canceled',
    cancellation_reason: 'Requirements changed',
    publish: true
  })
});

Batch Operations

Create Multiple Tasks

const tasks = [
  { title: 'Task 1', priority: 'high' },
  { title: 'Task 2', priority: 'medium' },
  { title: 'Task 3', priority: 'low' }
];

const created = await Promise.all(
  tasks.map(task =>
    fetch('https://app.daycopilot.ai/api/v1/tasks', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(task)
    }).then(r => r.json())
  )
);

console.log(`Created ${created.length} tasks`);

Bulk Status Update

// Get all pending tasks
const pending = await fetch(
  'https://app.daycopilot.ai/api/v1/tasks?status=pending',
  { headers: { 'Authorization': `Bearer ${token}` } }
).then(r => r.json());

// Update all to in_progress
await Promise.all(
  pending.data.map(task =>
    fetch(`https://app.daycopilot.ai/api/v1/tasks/${task.id}`, {
      method: 'PUT',
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ status: 'in_progress', publish: true })
    })
  )
);

Pagination

Iterate Through All Tasks

async function getAllTasks(token) {
  const allTasks = [];
  let offset = 0;
  const limit = 100;
  let hasMore = true;

  while (hasMore) {
    const response = await fetch(
      `https://app.daycopilot.ai/api/v1/tasks?limit=${limit}&offset=${offset}`,
      { headers: { 'Authorization': `Bearer ${token}` } }
    ).then(r => r.json());

    allTasks.push(...response.data);
    hasMore = response.meta.pagination.hasMore;
    offset += limit;
  }

  return allTasks;
}

Best Practices

Group related tasks into contexts. This makes filtering, sharing, and bulk operations much easier.
// Good: Tasks in context
await createTask({
  title: 'Review PR #123',
  context_id: 'engineering-project-uuid'
});
Always set due dates for time-sensitive tasks. This enables timeline views and reminders.
await createTask({
  title: 'Submit quarterly report',
  due_date: '2025-12-31T23:59:59Z',
  priority: 'high'
});
Establish team conventions for priority levels:
  • Urgent: Do immediately, blocks others
  • High: Important, do this week
  • Medium: Normal priority
  • Low: Nice to have, when time permits
Use comments instead of editing descriptions to preserve history:
// Instead of updating description
await addComment(taskId, 'Blocker: Waiting for API key from DevOps');
  • Use drafts for major changes that need review
  • Skip drafts for status updates and quick fixes
  • Publish drafts promptly to avoid conflicts

Common Patterns

Daily Standup Report

async function getStandupReport(token) {
  const yesterday = new Date();
  yesterday.setDate(yesterday.getDate() - 1);

  // Completed yesterday
  const completed = await fetch(
    `https://app.daycopilot.ai/api/v1/tasks?` +
    `status=completed&` +
    `completed_after=${yesterday.toISOString()}`,
    { headers: { 'Authorization': `Bearer ${token}` } }
  ).then(r => r.json());

  // In progress today
  const inProgress = await fetch(
    'https://app.daycopilot.ai/api/v1/tasks?status=in_progress',
    { headers: { 'Authorization': `Bearer ${token}` } }
  ).then(r => r.json());

  return {
    completed: completed.data,
    inProgress: inProgress.data
  };
}

Overdue Tasks Alert

async function getOverdueTasks(token) {
  const now = new Date().toISOString();

  const overdue = await fetch(
    `https://app.daycopilot.ai/api/v1/tasks?` +
    `status=pending,in_progress&` +
    `due_before=${now}`,
    { headers: { 'Authorization': `Bearer ${token}` } }
  ).then(r => r.json());

  return overdue.data;
}

Task Template

const taskTemplates = {
  bugFix: {
    priority: 'high',
    status: 'pending',
    context_id: 'engineering-uuid',
    labels: ['bug', 'needs-triage']
  },
  feature: {
    priority: 'medium',
    status: 'pending',
    context_id: 'product-uuid',
    labels: ['feature', 'roadmap']
  }
};

// Use template
const bugTask = await createTask({
  ...taskTemplates.bugFix,
  title: 'Fix login redirect issue',
  description: 'Users report redirect loop after login'
});

Next Steps