1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Import content into a change request page |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | spaceId: string, |
12 | changeRequestId: string, |
13 | pageId: string, |
14 | body: { |
15 | url: string; |
16 | source: |
17 | | "website" |
18 | | "docx" |
19 | | "markdown" |
20 | | "html" |
21 | | "zip" |
22 | | "confluence" |
23 | | "github-wiki" |
24 | | "notion" |
25 | | "google-docs"; |
26 | }, |
27 | ) { |
28 | const url = new URL( |
29 | `https://api.gitbook.com/v1/spaces/${spaceId}/change-requests/${changeRequestId}/content/page/${pageId}/import`, |
30 | ); |
31 |
|
32 | const response = await fetch(url, { |
33 | method: "POST", |
34 | headers: { |
35 | "Content-Type": "application/json", |
36 | Authorization: "Bearer " + auth.token, |
37 | }, |
38 | body: JSON.stringify(body), |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|