0

Get a space revision page by its ID

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
 * Get a space revision page by its ID
7
 *
8
 */
9
export async function main(
10
  auth: Gitbook,
11
  spaceId: string,
12
  revisionId: string,
13
  pageId: string,
14
  format: "document" | "markdown" | undefined,
15
  evaluated: string | undefined,
16
  metadata: string | undefined,
17
  computed: string | undefined,
18
) {
19
  const url = new URL(
20
    `https://api.gitbook.com/v1/spaces/${spaceId}/revisions/${revisionId}/page/${pageId}`,
21
  );
22
  for (const [k, v] of [
23
    ["format", format],
24
    ["evaluated", evaluated],
25
    ["metadata", metadata],
26
    ["computed", computed],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
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