0

Import content into a space page

by
Published Oct 17, 2025
Script gitbook Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Gitbook = {
3
  token: string;
4
};
5
/**
6
 * Import content into a space page
7
 *
8
 */
9
export async function main(
10
  auth: Gitbook,
11
  spaceId: string,
12
  pageId: string,
13
  body: {
14
    url: string;
15
    source:
16
      | "website"
17
      | "docx"
18
      | "markdown"
19
      | "html"
20
      | "zip"
21
      | "confluence"
22
      | "github-wiki"
23
      | "notion"
24
      | "google-docs";
25
  },
26
) {
27
  const url = new URL(
28
    `https://api.gitbook.com/v1/spaces/${spaceId}/content/page/${pageId}/import`,
29
  );
30

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