Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.0 KB
Raw Blame
import { Property, createAction } from '@activepieces/pieces-framework';
import { HttpMethod, getAccessTokenOrThrow } from '@activepieces/pieces-common';

import { clickupCommon, callClickUpApi } from '../../common';
import { clickupAuth } from '../../auth';
import { taskOutputSchema } from '../../output-schemas';

export const createClickupTaskFromTemplate = createAction({
  auth: clickupAuth,
  name: 'create_task_from_template',
  classification: 'WRITE',
  description: 'Create a task in a list from a saved task template.',
  audience: 'both',
  aiMetadata: { description: 'Create a new ClickUp task in a list by instantiating an existing task template, supplying only the new task name. Pick this when the task should inherit structure (subtasks, fields, defaults) from a saved template; use Create Task for a task built from scratch. Each call creates a distinct task, so it is not idempotent.', idempotent: false },
  displayName: 'Create Task From Template',
  propertyGroups: [
    {
      key: 'location',
      display: 'section',
      label: 'Location',
      icon: 'inbox',
      props: ['workspace_id', 'space_id', 'list_id'],
    },
    {
      key: 'details',
      display: 'section',
      label: 'Task Details',
      icon: 'text',
      props: ['template_id', 'name'],
    },
  ],
  props: {
    workspace_id: clickupCommon.workspace_id(),
    space_id: clickupCommon.space_id(),
    list_id: clickupCommon.list_id(),
    template_id: clickupCommon.template_id(true),
    name: Property.ShortText({
      description: 'Name of the new task.',
      displayName: 'Task Name',
      placeholder: 'e.g. Weekly report',
      required: true,
    }),
  },
  outputSchema: taskOutputSchema,
  async run(configValue) {
    const { list_id, name, template_id } = configValue.propsValue;
    const response = await callClickUpApi(
      HttpMethod.POST,
      `list/${list_id}/taskTemplate/${template_id}`,
      getAccessTokenOrThrow(configValue.auth),
      {
        name,
      }
    );

    return response.body;
  },
});