Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.