0

I was using following GitHub CLI command to add new member to a GitHub org through the command line. I am using the username to add:

# GitHub CLI api
# https://cli.github.com/manual/gh_api

gh api \
  --method PUT \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /orgs/ORG/teams/TEAM_SLUG/memberships/USERNAME \
  -f role='maintainer'

However, I want to invite using Email ID, because a simple typo in the username may invite the wrong members.

I tried the code below, but it results in "gh not found 404 error":

gh api \
  --method PUT \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /orgs/ORG/teams/TEAM_SLUG/memberships \
  -f email='NEW_MEMBER_EMAIL' \
  -f role='maintainer'

How can I fix this?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116

1 Answers1

0

You're using the endpoint to add a user to a team, not to invite them to an organization.

To invite to an organization, use this endpoint:

gh api orgs/ORG/invitations -f email=NEW_MEMBER_EMAIL

You can add a role: admin, direct_member (default), or billing_manager, with -f role=ROLE.

And you can add the new member to teams with -f team_ids[]=ID1 -f team_ids[]=ID2.

To get a list of team names with their IDs:

gh api orgs/ORG/teams --jq 'map("\(.name): \(.id)")[]'
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116