How can I use Github API to get a list of users added to a repository

Viewed 569

I would like to get all users and teams for a GitHub repository using the API. I can get the teams by using this: https://docs.github.com/en/rest/reference/repos#list-repository-teams

However, I did not find how to get the list of users added directly to the project. In the following image, I have Team A & Team B, that are returned by the API endpoint previously mentioned. However the user me is not returned.

team a/me/ team b

Any pointers on how I could get all the information I need?

1 Answers

Repository collaborators can be listed using the Collaborators API as follows:

[GET] /repos/{owner}/{repo}/collaborators

By default, you will get a list of all users with access to the repository. You can filter the returned result using the affiliation parameter set to direct in order to get only the users added directly. In your case, this would be only the user me.

Example using the API with the GitHub command line tool:

gh api -X GET repos/{owner}/{repo}/collaborators -f affiliation='direct'
Related