Reputation: 493
I'm trying to get all the repos in my account, I have several private repos and 1 public repo, i do a get request to this endpoint https://api.github.com/users/$user/repos and I get only the public repo, I have my token with the repo scope and I use authorization type bearer but it just wont show the private repos, do you know what am I missing?
Upvotes: 1
Views: 2507
Reputation: 4177
Private repositories are not listed in the /users/$user/repos
API, which comes a bit unexpected given that the documentation says "allows to get public and private information about the authenticated user".
But you can retrieve them via the /user/repos
endpoint which lists "repositories that the authenticated user has explicit permission to access.".
This will include all repos you have, not just your own. You could of course filter by owner.login
or full_name
in the result to get what you want, but you can also query right away by adding a quer string ?type=private
to your URL.
Sample Python code:
import requests
token = "****"
url = "https://api.github.com/user/repos?type=private"
headers = {
"Authorization": f"token {token}",
"Accept": "application/vnd.github.v3+json"
}
r = requests.get(url, headers=headers)
for repo in r.json():
print(repo["name"])
Upvotes: 3