I'm trying to do a Curl request to add a team to a repo like this:
curl --user $USERNAME:$TOKEN -X PUT -d "" "https://api.github.com/teams/<team name>/repos/<org>/$REPONAME"
My variables are the correct one, but I keep getting a message not found error. Anyone have an advice on how to proceed?
The correct endpoint from here is :
PUT /teams/:id/repos/:org/:repo
You have to specify the team ID not the team name
The following will get the team ID for the Developers
team and perform the PUT
request to add repo to the specified team :
username=your_user
password=your_password
org=your_org
repo=your_repo
team=Developers
teamid=$(curl -s --user $username:$password "https://api.github.com/orgs/$org/teams" | \
jq --arg team "$team" '.[] | select(.name==$team) | .id')
curl -v --user $username:$password -d "" -X PUT "https://api.github.com/teams/$teamid/repos/$org/$repo"
Note for this example JSON parsing is done with jq
Also consider to use Personal access token with scope admin:org
instead of your username/password (then use -H "Authorization: Token $TOKEN"
)
The accepted answer is slightly out of date now.
Try here: https://docs.github.com/en/rest/reference/teams#add-or-update-team-repository-permissions
put /orgs/{org}/teams/{team_slug}/repos/{owner}/{repo}
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ......." \
https://api.github.com/orgs/ORG/teams/TEAM_SLUG/repos/ORG/REPO \
-d '{"permission":"permission"}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With