Create List From Template in Folder
One script reply has been approved by the moderators Verified

Create a new list using a list template in a folder This request runs synchronously by default with return_immediately=true. The request returns the future List ID immediatly, but the List might not created at the time of the request returning. Small temmplates can be applied syncronously, which guarantees that all sub objects are created. In case of a timeout on syncronous requests, the of objects from the template will continue to be created past the timeout.

Created by hugo697 168 days ago
Submitted by hugo697 Bun
Verified 168 days ago
1
//native
2
type Clickup = {
3
  token: string;
4
};
5
/**
6
 * Create List From Template in Folder
7
 * Create a new list using a list template in a folder
8
This request runs synchronously by default with `return_immediately=true`. The request returns the future List ID immediatly, but the List might not created at the time of the request returning.
9
Small temmplates can be applied syncronously, which guarantees that all sub objects are created. In case of a timeout on syncronous requests, the of objects from the template will continue to be created past the timeout.
10

11
 */
12
export async function main(
13
  auth: Clickup,
14
  folder_id: string,
15
  template_id: string,
16
  body: {
17
    name: string;
18
    options?: {
19
      return_immediately?: false | true;
20
      content?: string;
21
      time_estimate?: number;
22
      automation?: false | true;
23
      include_views?: false | true;
24
      old_due_date?: false | true;
25
      old_start_date?: false | true;
26
      old_followers?: false | true;
27
      comment_attachments?: false | true;
28
      recur_settings?: false | true;
29
      old_tags?: false | true;
30
      old_statuses?: false | true;
31
      subtasks?: false | true;
32
      custom_type?: false | true;
33
      old_assignees?: false | true;
34
      attachments?: false | true;
35
      comment?: false | true;
36
      old_status?: false | true;
37
      external_dependencies?: false | true;
38
      internal_dependencies?: false | true;
39
      priority?: false | true;
40
      custom_fields?: false | true;
41
      old_checklists?: false | true;
42
      relationships?: false | true;
43
      old_subtask_assignees?: false | true;
44
      start_date?: string;
45
      due_date?: string;
46
      remap_start_date?: false | true;
47
      skip_weekends?: false | true;
48
      archived?: 1 | 2;
49
    };
50
  },
51
) {
52
  const url = new URL(
53
    `https://api.clickup.com/api/v2/folder/${folder_id}/list_template/${template_id}`,
54
  );
55

56
  const response = await fetch(url, {
57
    method: "POST",
58
    headers: {
59
      "Content-Type": "application/json",
60
      Authorization: auth.token,
61
    },
62
    body: JSON.stringify(body),
63
  });
64
  if (!response.ok) {
65
    const text = await response.text();
66
    throw new Error(`${response.status} ${text}`);
67
  }
68
  return await response.json();
69
}
70