List machine types for a codespace

List the machine types a codespace can transition to use. You must authenticate using an access token with the `codespace` scope to use this endpoint. GitHub Apps must have read access to the `codespaces_metadata` repository permission to use this endpoint.

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * List machine types for a codespace
6
 * List the machine types a codespace can transition to use.
7

8
You must authenticate using an access token with the `codespace` scope to use this endpoint.
9

10
GitHub Apps must have read access to the `codespaces_metadata` repository permission to use this endpoint.
11
 */
12
export async function main(auth: Github, codespace_name: string) {
13
  const url = new URL(
14
    `https://api.github.com/user/codespaces/${codespace_name}/machines`
15
  );
16

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