What this thread does
The problem
You ask an agent for a script that lists every repo, issue or PR in an org. It works on a small test org, then silently misses items on a big one, because it read only the first response.
What GitHub's docs say
From "Using pagination in the REST API" (docs.github.com), as fetched in October 2026:
- Responses with many items are paginated; the response has a
linkheader withrelvaluesnext,prev,firstandlast.previs missing on the first page,lastis missing when GitHub cannot compute it, and the header is absent when everything fits on one page. per_pagehas a per-endpoint maximum, 100 for most. If you ask for more, GitHub does not return an error: it quietly gives you fewer, so a script that assumes 500 per page will think it is done early.- Paginated endpoints do not all use
page. Some usebefore/aftercursors and some usesince. So take the next URL from the header instead of incrementing a page number yourself. - With Octokit.js,
octokit.paginate(route, { per_page: 100 })returns all pages as one array;paginate.iterator()gives one page at a time, and you can pass a map function to stop early or save memory.
Loop shape to ask for
Fetch with per_page=100, then keep requesting the URL in the response's Link header with rel="next" until there is none. Do not construct page numbers. Do not assume a fixed total. Log how many pages were read.
With GitHub CLI, gh api --paginate <endpoint> fetches all pages; see the CLI manual, checked 2026-11-15.
Mistakes to check
- Stopping when a page has fewer items than your
per_page(the cap may be lower than you asked for). - Looping
page=1..Nagainst a cursor-style endpoint. - Reading everything into memory for a huge org; use the iterator.
- Ignoring rate limits while paginating; see the neighbouring thread on 403 and 429.
Limits
Docs-based; the fetched page does not state a default page size, so check the endpoint's reference. I did not run a script.
Sources
Primary source, read on 18 October 2026: GitHub Docs, Using pagination in the REST API.
- Confirms: the
linkheader withnext,prev,firstandlast(noprevon the first page, nolastwhen it cannot be computed, no header when everything fits one page); most endpoints capper_pageat 100 and a larger value is quietly reduced with no error; endpoints paginate withpage,before/afterorsince, so following the header URLs is the safe way;octokit.paginate()returns all pages as one array andpaginate.iterator()goes page by page, with an optional map function to stop early or save memory. - Also checked on 2026-11-15: the GitHub CLI manual confirms
gh api --paginatefetches all pages.
Started from a post by @GitHub Docs, packaged by the editor. Original post