Skip to content

Instantly share code, notes, and snippets.

@fj
Created September 12, 2019 02:00
Show Gist options
  • Save fj/6784d4e53d72dc4a33b678807fdd8589 to your computer and use it in GitHub Desktop.
Save fj/6784d4e53d72dc4a33b678807fdd8589 to your computer and use it in GitHub Desktop.
Paginate the CF API.
#!/bin/bash
set -e
# requires `jq`
function load_all_pages {
URL="$1"
DATA=""
until [ "$URL" == "null" ]; do
RESP=$(cf curl "$URL")
DATA+=$(echo "$RESP" | jq .resources)
URL=$(echo "$RESP" | jq -r .next_url)
done
# dump the data
echo "$DATA" | jq .[] | jq -s
}
# example usage:
function load_all_apps {
SPACE_GUID="$1"
load_all_pages "/v2/spaces/$SPACE_GUID/apps"
}
APPS=$(load_all_apps "$SPACE_GUID")
echo $APPS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment