Created
September 24, 2023 18:44
-
-
Save morozov/8cb4eb539d841212f889f432e60f8055 to your computer and use it in GitHub Desktop.
Iterator of paginated Bitbucket REST API results
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
#!/bin/bash | |
API_URL="$1" | |
while true; do | |
echo "Fetching $API_URL" >&2 | |
RESPONSE="$(curl -sn "$API_URL")" | |
if [[ $? -ne 0 ]]; then | |
echo "Error making API request. Exiting." >&2 | |
exit 1 | |
fi | |
echo "$RESPONSE" | |
# Check if there is a next page | |
API_URL="$(echo "$RESPONSE" | jq -re ".next")" | |
if [[ $? -ne 0 ]]; then | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment