0
Get an installation for the authenticated app
One script reply has been approved by the moderators Verified

Enables an authenticated GitHub App to find an installation's information using the installation id.

You must use a JWT to access this endpoint.

Created by hugo697 407 days ago Viewed 9028 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 407 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get an installation for the authenticated app
6
 * Enables an authenticated GitHub App to find an installation's information using the installation id.
7

8
You must use a [JWT](https://docs.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app) to access this endpoint.
9
 */
10
export async function main(auth: Github, installation_id: string) {
11
  const url = new URL(
12
    `https://api.github.com/app/installations/${installation_id}`
13
  );
14

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