// clickup/create_task.ts type TaskInput = { // REQUIRED FIELDS /** The ID of the list to put this task into */ list_id: string; /** Name of the task (max 99840 chars) */ name: string; // OPTIONAL CORE FIELDS /** Detailed task description (supports markdown) */ description?: string; /** Task status must match existing status in List */ status?: string; /** Unix timestamp in milliseconds */ due_date?: number; /** Unix timestamp in milliseconds */ start_date?: number; /** Time estimate in milliseconds */ time_estimate?: number; /** Markdown-formatted description */ markdown_description?: string; /** Priority level (1-4) */ priority?: 1 | 2 | 3 | 4; /** Parent task ID for subtasks */ parent?: string; /** Custom task type ID */ custom_item_id?: number; // PEOPLE MANAGEMENT /** Array of user IDs */ assignees?: number[]; /** Notify all task members */ notify_all?: boolean; // TAGS & RELATIONSHIPS /** Array of tag names */ tags?: string[]; /** Task dependencies */ depends_on?: string[]; /** Linked task IDs */ links_to?: string; // CUSTOMIZATION /** Array of custom field objects */ custom_fields?: { /** Custom field ID */ id: string; /** Field value (type-specific) */ value: string | number | boolean | string[]; }[]; // VALIDATION FLAGS /** Enforce required custom fields */ check_required_custom_fields?: boolean; // ADVANCED OPTIONS /** Team ID for custom task IDs */ team_id?: number; /** Custom task ID (requires team_id) */ custom_task_id?: string; /** Task creation source (max 6 chars) */ source?: string; }; // All we need here is the access token. type ClickupCredentials = { access_token: string; }; export async function main( params: TaskInput, credentials: ClickupCredentials ) { // 1. Input Validation if (!params.list_id?.trim()) { throw new Error("Missing required field: list_id"); } if (!params.name?.trim()) { throw new Error("Missing required field: name"); } // 2. API Request Configuration const response = await fetch(`https://api.clickup.com/api/v2/list/${params.list_id}/task`, { method: "POST", headers: { "Content-Type": "application/json", "accept": 'application/json', "Authorization": "Bearer " + credentials.access_token }, body: JSON.stringify({ // Required name: params.name, // Core optional parameters description: params.description, status: params.status, due_date: params.due_date, start_date: params.start_date, time_estimate: params.time_estimate, markdown_description: params.markdown_description, priority: params.priority, parent: params.parent, custom_item_id: params.custom_item_id, // People management assignees: params.assignees, notify_all: params.notify_all, // Tags & relationships tags: params.tags, depends_on: params.depends_on, links_to: params.links_to, // Customization custom_fields: params.custom_fields?.map(field => ({ id: field.id, value: field.value })), // Validation flags check_required_custom_fields: params.check_required_custom_fields, // Advanced configurations team_id: params.team_id, custom_task_id: params.custom_task_id, source: params.source }) }); // 3. Error Handling if (!response.ok) { const errorBody = await response.text(); throw new Error(`ClickUp API Error (${response.status}): ${errorBody}`); } // 4. Response Processing const result = await response.json(); // Validate successful task creation if (!result?.id) { throw new Error("Failed to create task: No ID returned"); } return { task_id: result.id, url: result.url, status: result.status?.status || "created", _metadata: { clickup_space: result.space?.id, created_at: new Date().toISOString() } }; }