Skip to content

Instantly share code, notes, and snippets.

@morozov
Created September 24, 2023 18:44
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 morozov/8cb4eb539d841212f889f432e60f8055 to your computer and use it in GitHub Desktop.
Save morozov/8cb4eb539d841212f889f432e60f8055 to your computer and use it in GitHub Desktop.
Iterator of paginated Bitbucket REST API results
#!/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