Home > Software design >  How to pull all repo's from a page using Git REST API
How to pull all repo's from a page using Git REST API

Time:06-25

I am accessing repo data by team using https://api.github.com/orgs/ORG/teams/TEAM/repos. However, the team has over 30 repos and the API only pulls the first 30 repos. How can I fix this issue and have my application pull all the repos, even if they are on the next page?

CodePudding user response:

The GitHub API is using pagination by default and limits the values to 30 results. Using the per_page parameter in your request, you can fetch more results if needed.

Here's the extract from their documentation which explains how to use it:

Pagination Requests that return multiple items will be paginated to 30 items by default. You can specify further pages with the page parameter. For some resources, you can also set a custom page size up to 100 with the per_page parameter. Note that for technical reasons not all endpoints respect the per_page parameter, see events for example.

$ curl 'https://api.github.com/user/repos?page=2&per_page=100' Note that page numbering is 1-based and that omitting the page parameter will return the first page.

  • Related