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

Create a page in a Doc.

Created by hugo697 168 days ago Picked 2 times
Submitted by hugo697 Bun
Verified 168 days ago
1
//native
2
type Clickup = {
3
  token: string;
4
};
5
/**
6
 * Create page
7
 * Create a page in a Doc.
8
 */
9
export async function main(
10
  auth: Clickup,
11
  workspaceId: string,
12
  docId: string,
13
  body: {
14
    parent_page_id?: string;
15
    name?: string;
16
    sub_title?: string;
17
    content?: string;
18
    content_format?: string;
19
  },
20
) {
21
  const url = new URL(
22
    `https://api.clickup.com/api/v3/workspaces/${workspaceId}/docs/${docId}/pages`,
23
  );
24

25
  const response = await fetch(url, {
26
    method: "POST",
27
    headers: {
28
      "Content-Type": "application/json",
29
      Authorization: auth.token,
30
    },
31
    body: JSON.stringify(body),
32
  });
33
  if (!response.ok) {
34
    const text = await response.text();
35
    throw new Error(`${response.status} ${text}`);
36
  }
37
  return await response.json();
38
}
39