Created
October 7, 2021 10:01
-
-
Save Himura2la/6ddaa12085dae2b8c873b68d5a457865 to your computer and use it in GitHub Desktop.
Get paginated data from GitHub API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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