I have a script to download all the repos in my Organization, and it works fine.
We have recently added Teams, and I would like to target a specific team to download all the repos in that team.
To get for the whole org I can do this: (changing the page number to walk them)
Works:
https://api.github.com/orgs/MY_ORG/repos?access_token=MY_TOKEN&per_page=100&page=1
How do I do it for a team in the Org? I've tried:
Does not work
https://api.github.com/orgs/MY_ORG/teams/TEAM_SLUG/repos?access_token=MY_TOKEN
As well as a few others, none of which works.
By looking at the API Documentation it seems like what I'm trying should work. I can't even get the list of teams which the docs have as:
GET /orgs/:org/teams/:team_slug
So if I do:
https://api.github.com/orgs/MY_ORG/teams/TEAM_SLUG?access_token=MY_TOKEN
I just get back a Not Found, error with a link to the docs.
Anyone have success in doing this?
You are not trying correct API to get the Repos in a team
try
GET /teams/:team_id/repos
To get the team ID you can list all your Organisation teams as follows:
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/
Send personal access token as:
Authorization: token <PERSONALACCESSTOKEN>
Using Curl:
To get team Repos:
curl -H "Authorization: token <PERSONALACCESSTOKEN>" -X GET https://api.github.com/teams/:team_id/repos
To get the team ID :
curl -H "Authorization: token PERSONALACCESSTOKEN" -X GET https://api.github.com/orgs/<ORGANISATION>/teams
Further reading:
API Authentication: https://developer.github.com/v3/#authentication
Listing teams: https://developer.github.com/v3/teams/#list-team-repos
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