1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Move a site space, site section or site section group to a new position in the site structure. |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | organizationId: string, |
12 | siteId: string, |
13 | body: { |
14 | item: { |
15 | type: "site-space" | "site-section" | "site-section-group"; |
16 | id: string; |
17 | }; |
18 | position: { |
19 | before?: { |
20 | type: "site-space" | "site-section" | "site-section-group"; |
21 | id: string; |
22 | }; |
23 | after?: { |
24 | type: "site-space" | "site-section" | "site-section-group"; |
25 | id: string; |
26 | }; |
27 | }; |
28 | }, |
29 | ) { |
30 | const url = new URL( |
31 | `https://api.gitbook.com/v1/orgs/${organizationId}/sites/${siteId}/structure/sort`, |
32 | ); |
33 |
|
34 | const response = await fetch(url, { |
35 | method: "PATCH", |
36 | headers: { |
37 | "Content-Type": "application/json", |
38 | Authorization: "Bearer " + auth.token, |
39 | }, |
40 | body: JSON.stringify(body), |
41 | }); |
42 | if (!response.ok) { |
43 | const text = await response.text(); |
44 | throw new Error(`${response.status} ${text}`); |
45 | } |
46 | return await response.json(); |
47 | } |
48 |
|