Issue
I am having trouble on using the github api to add the Repos to a team in Github Enterprise
according to GitHub API: i should call:
PUT /teams/:team_id/repos/:owner/:repo
and iam making the below call using my access token
curl -H "Authorization: token personal_access_token" https://api.github.com/teams/test-team/repos/mohit/test_data
I received the json data:
{
"message": "Bad credentials",
"documentation_url": "https://developer.github.com/v3"
}
here is the link for the documentation: https://developer.github.com/v3/teams/#add-or-update-team-repository
Iam not able to add Repos to team. How to proceed with adding Repos to a team in an organization in Github Enterprise?
Solution
When making the curl command, the Authorization header should look like this:
-H "Authorization: token <PERSONALACCESSTOKEN>"
So a full curl put command would look like this:
curl -H "Authorization: token <PERSONALACCESSTOKEN>" -X PUT https://api.github.com/teams/<TEAMID>/repos/<ORGANISATION>/<REPO>
To get the team ID you can list all your Organisation teams as follows:
curl -H "Authorization: token PERSONALACCESSTOKEN" -X GET https://api.github.com/orgs/<ORGANISATION>/teams
If you are self hosting your GitHub Enterprise then replace
https://api.github.com
with
https://<HOSTNAME>/api/v3/
Further reading:
API Authentication: https://developer.github.com/v3/#authentication
Listing teams: https://developer.github.com/v3/teams/#list-teams
Answered By - Mick Answer Checked By - Mary Flores (WPSolving Volunteer)