Create a registration token for an organization

Returns a token that you can pass to the `config` script. The token expires after one hour. You must authenticate using an access token with the `admin:org` scope to use this endpoint. #### Example using registration token Configure your self-hosted runner, replacing `TOKEN` with the registration token provided by this endpoint. ``` ./config.sh --url https://github.com/octo-org --token TOKEN ```

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
 * Create a registration token for an organization
6
 * Returns a token that you can pass to the `config` script. The token expires after one hour.
7

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

10
#### Example using registration token
11

12
Configure your self-hosted runner, replacing `TOKEN` with the registration token provided by this endpoint.
13

14
```
15
./config.sh --url https://github.com/octo-org --token TOKEN
16
```
17
 */
18
export async function main(auth: Github, org: string) {
19
  const url = new URL(
20
    `https://api.github.com/orgs/${org}/actions/runners/registration-token`
21
  );
22

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