Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get repos from a specific team using GitHub API?

Tags:

github

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?

like image 900
Kelly Avatar asked Sep 13 '25 23:09

Kelly


1 Answers

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

like image 52
mohit sehrawat Avatar answered Sep 16 '25 11:09

mohit sehrawat