Manage access control for organization codespaces

Sets which users can access codespaces in an organization. This is synonymous with granting or revoking codespaces billing permissions for users according to the visibility. You must authenticate using an access token with the `admin:org` scope to use this endpoint.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 366 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Manage access control for organization codespaces
6
 * Sets which users can access codespaces in an organization. This is synonymous with granting or revoking codespaces billing permissions for users according to the visibility.
7
You must authenticate using an access token with the `admin:org` scope to use this endpoint.
8
 */
9
export async function main(
10
  auth: Github,
11
  org: string,
12
  body: {
13
    selected_usernames?: string[];
14
    visibility:
15
      | "disabled"
16
      | "selected_members"
17
      | "all_members"
18
      | "all_members_and_outside_collaborators";
19
    [k: string]: unknown;
20
  }
21
) {
22
  const url = new URL(`https://api.github.com/orgs/${org}/codespaces/billing`);
23

24
  const response = await fetch(url, {
25
    method: "PUT",
26
    headers: {
27
      "Content-Type": "application/json",
28
      Authorization: "Bearer " + auth.token,
29
    },
30
    body: JSON.stringify(body),
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.text();
37
}
38