Jorn
Jorn

Reputation: 272

How to get a JSON of all GitHub public repos in api v3?

I'm using this url and I get only the first 30 repos:

https://api.github.com/users/octocat/repos //Works fine

But for some reasons, the following url doesn't work:

https://api.github.com/users/octocat/repos?page=3&per_page=100

How to get the following pages?

Upvotes: 0

Views: 138

Answers (2)

phd
phd

Reputation: 94407

The account https://github.com/octocat has only 8 repositories. The URL https://api.github.com/users/octocat/repos lists all 8.

The URL https://api.github.com/users/octocat/repos?page=3&per_page=100 tries to list the 3rd page of repositories having 100 repos by page. That certainly returns an empty list of repos — there are simply not enough repositories to fill 3 pages with 100 repositories per page.

If you're just learning try to list your 8 repositories paged by, for example, 4:

First 4 repos: https://api.github.com/users/octocat/repos?page=1&per_page=4

Next 4 repos: https://api.github.com/users/octocat/repos?page=2&per_page=4

Empty list: https://api.github.com/users/octocat/repos?page=3&per_page=4

Upvotes: 2

Krishna Prasad
Krishna Prasad

Reputation: 21

https://api.github.com/users/octocat/repos?page=3&per_page=100

This means that you are trying to access 100 repos in the third page but the api returns only one page with all the repos which in this case is 30.

Thus what you get is an empty list

Upvotes: 2

Related Questions