Skip to content

Instantly share code, notes, and snippets.

@Himura2la
Created October 7, 2021 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Himura2la/6ddaa12085dae2b8c873b68d5a457865 to your computer and use it in GitHub Desktop.
Save Himura2la/6ddaa12085dae2b8c873b68d5a457865 to your computer and use it in GitHub Desktop.
Get paginated data from GitHub API
# Token: https://github.com/settings/tokens | Scope: user
$Headers = @{
"Authorization" = "token <...>"
"Accept" = "application/vnd.github.v3+json";
}
$Api = 'https://api.github.com'
function MassCollect {
param (
[Parameter(Mandatory)] [string] $ApiMethod
)
$accumulator = New-Object Collections.Generic.List[System.Object]
$page = 0
do {
$page++
$response = Invoke-RestMethod -Method Get "${Api}${ApiMethod}?per_page=100&page=${page}" -Headers $Headers
$accumulator.AddRange($response)
} while ($resp.Count -gt 0)
}
$subscriptions = MassCollect "/user/subscriptions"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment