Created
November 29, 2022 18:05
-
-
Save gabrielsroka/b7d6802f3227f24499e3d193db747708 to your computer and use it in GitHub Desktop.
paginate Okta with curl and shell
This file contains 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
#!/usr/bin/env bash | |
# Set these: | |
url='https://COMPANY.okta.com/api/v1/users' | |
token='...' | |
# Pagination code based on https://michaelheap.com/follow-github-link-header-bash | |
while [ "$url" ]; do | |
r=$(curl -i --compressed -Ss -H "authorization: SSWS $token" "$url" | tr -d '\r') | |
headers=$(echo "$r" | sed '/^$/q') | |
body=$(echo "$r" | sed '1,/^$/d') | |
echo "$body" | jq -r '.[].profile.login' | |
url=$(echo "$headers" | sed -n -E 's/link: <(.*)>; rel="next"/\1/pi') | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this shell script is broken out into functions