Create Space
One script reply has been approved by the moderators Verified

Add a new Space to a Workspace.

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 Space
7
 * Add a new Space to a Workspace.
8
 */
9
export async function main(
10
  auth: Clickup,
11
  team_id: string,
12
  body: {
13
    name: string;
14
    multiple_assignees: false | true;
15
    features: {
16
      due_dates: {
17
        enabled: false | true;
18
        start_date: false | true;
19
        remap_due_dates: false | true;
20
        remap_closed_due_date: false | true;
21
      };
22
      time_tracking: { enabled: false | true };
23
      tags: { enabled: false | true };
24
      time_estimates: { enabled: false | true };
25
      checklists: { enabled: false | true };
26
      custom_fields: { enabled: false | true };
27
      remap_dependencies: { enabled: false | true };
28
      dependency_warning: { enabled: false | true };
29
      portfolios: { enabled: false | true };
30
    };
31
  },
32
) {
33
  const url = new URL(`https://api.clickup.com/api/v2/team/${team_id}/space`);
34

35
  const response = await fetch(url, {
36
    method: "POST",
37
    headers: {
38
      "Content-Type": "application/json",
39
      Authorization: auth.token,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49