0

Create an integration installation API token

by
Published Oct 17, 2025

Creates a temporary API token of an integration's installation that has access to the installation and it's scopes. You must be authenticated as the integration to obtain this token.

Script gitbook Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Gitbook = {
3
  token: string;
4
};
5
/**
6
 * Create an integration installation API token
7
 * Creates a temporary API token of an integration's installation that has access to the installation and it's scopes. You must be authenticated as the integration to obtain this token.
8

9
 */
10
export async function main(
11
  auth: Gitbook,
12
  integrationName: string,
13
  installationId: string,
14
) {
15
  const url = new URL(
16
    `https://api.gitbook.com/v1/integrations/${integrationName}/installations/${installationId}/tokens`,
17
  );
18

19
  const response = await fetch(url, {
20
    method: "POST",
21
    headers: {
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: undefined,
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32