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

Enables an authenticated GitHub App to find the user’s installation information.

You must use a JWT to access this endpoint.

Created by hugo697 359 days ago Viewed 9003 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 359 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Get a user installation for the authenticated app
6
 * Enables an authenticated GitHub App to find the user’s installation information.
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, username: string) {
11
  const url = new URL(`https://api.github.com/users/${username}/installation`);
12

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