1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a site |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | organizationId: string, |
12 | body: { |
13 | type?: |
14 | | "basic" |
15 | | "premium" |
16 | | "ultimate" |
17 | | "sponsored" |
18 | | "legacy-basic" |
19 | | "legacy-premium"; |
20 | title?: string; |
21 | visibility?: "public" | "unlisted" | "share-link" | "visitor-auth"; |
22 | spaces?: string[] | "sample" | "empty"; |
23 | }, |
24 | ) { |
25 | const url = new URL(`https://api.gitbook.com/v1/orgs/${organizationId}/sites`); |
26 |
|
27 | const response = await fetch(url, { |
28 | method: "POST", |
29 | headers: { |
30 | "Content-Type": "application/json", |
31 | Authorization: "Bearer " + auth.token, |
32 | }, |
33 | body: JSON.stringify(body), |
34 | }); |
35 | if (!response.ok) { |
36 | const text = await response.text(); |
37 | throw new Error(`${response.status} ${text}`); |
38 | } |
39 | return await response.json(); |
40 | } |
41 |
|