1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a site redirect |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | organizationId: string, |
12 | siteId: string, |
13 | body: { |
14 | source: string; |
15 | destination: |
16 | | { kind: "site-section"; siteSectionId: string } |
17 | | { kind: "site-space"; siteSpaceId: string } |
18 | | { kind: "site-page"; siteSpaceId: string; pageId: string }; |
19 | }, |
20 | ) { |
21 | const url = new URL( |
22 | `https://api.gitbook.com/v1/orgs/${organizationId}/sites/${siteId}/redirects`, |
23 | ); |
24 |
|
25 | const response = await fetch(url, { |
26 | method: "POST", |
27 | headers: { |
28 | "Content-Type": "application/json", |
29 | Authorization: "Bearer " + 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 |
|