Edits history of script submission #14685 for ' Create Task (clickup)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clickup = {
      token: string;
    };
    /**
     * Create Task
     * Create a new task.
     */
    export async function main(
      auth: Clickup,
      list_id: string,
      custom_task_ids: string | undefined,
      team_id: string | undefined,
      body: {
        name: string;
        description?: string;
        assignees?: number[];
        archived?: false | true;
        group_assignees?: string[];
        tags?: string[];
        status?: string;
        priority?: number;
        due_date?: number;
        due_date_time?: false | true;
        time_estimate?: number;
        start_date?: number;
        start_date_time?: false | true;
        points?: number;
        notify_all?: false | true;
        parent?: string;
        markdown_content?: string;
        links_to?: string;
        check_required_custom_fields?: false | true;
        custom_fields?: { id: string; value: string | number }[];
        custom_item_id?: number;
      },
    ) {
      const url = new URL(`https://api.clickup.com/api/v2/list/${list_id}/task`);
      for (const [k, v] of [
        ["custom_task_ids", custom_task_ids],
        ["team_id", team_id],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago