This Node.js script automates the process of inviting GitHub users to an organization based on a list of GitHub usernames.
Run the following command to install the required packages:
npm installThis script uses:
@octokit/rest@18β GitHub REST API SDK (Classic, compatible with CommonJS)dotenvβ For loading environment variables
Create a .env file in the root directory and add the following:
GITHUB_TOKEN=your_personal_access_token
GITHUB_ORG=your_organization_nameGITHUB_TOKENmust have the admin:org scope.- Generate a token here: https://github.com/settings/tokens
Save your GitHub usernames in a file called github_usernames.json using the format:
[
"username1",
"username2",
"username3"
]To execute the script:
node inviteUsers.jsAny invite failures (e.g., invalid usernames, rate limits) will be saved to:
failed_invites.jsonYou can use this file to retry the failed invites later.
The script performs the following actions:
- Loads the GitHub organization and token from
.env - Reads a list of usernames from
github_usernames.json - Attempts to invite each user via the GitHub API
- Logs successes to the console
- Writes any failures (with reasons) to
failed_invites.json
- GitHub enforces a rate limit of 50 invitations per 24 hours.
- The script skips usernames that are invalid or already invited.
- You can update the script to assign
"admin"role instead of"member"if needed.
.
βββ inviteUsers.js
βββ .env
βββ github_usernames.json
βββ failed_invites.json # Created automatically
MIT