In the Cloudflare API documentation (https://developers.cloudflare.com/fundamentals/api/how-to/make-api-calls/#pagination), it states that the page/per_page query params are used to pagination through responses. However, the API for Pages Deployments does not accept the per_page parameter.
I’m using the API to bulk-delete preview deployments (aliases) that are greater than one month old. However, given that this is a long-lived project with many developers, I have to send a ton of API requests to paginate through all of the deployments with the default per_page of 25.
When attempting to increase per_page to 50, I receive the following response:
This is not documented in Get deployments (https://developers.cloudflare.com/api/operations/pages-deployment-get-deployments) API documentation.
Am I missing something here, or is there an easier API that I can use to delete preview aliases for old builds that are no longer relevant? Support for the per_page parameter would be very much appreciated.
Got it. Does Pages support an alternative for cleaning up old preview aliases/deployments? Or is my method correct and I just need to deal with a page size of 25.
#docs: "https://developers.cloudflare.com/api/operations/pages-project-create-project"
cf_list_projects() {
local CF_ALL_PAGES_FILE="./cf_all_pages_projects.json"
local PAGE=1
# Initialize an empty array to store results from all pages
local RESULTS=()
while true; do
# Make a GET request to the API and save the response in a temporary file
local TEMP_FILE="./cf_list_pages_projects_page_$PAGE.json"
curl --request GET \
--url "$CF_URL_PAGES?page=$PAGE" \
-H "Authorization: Bearer $CF_X_KEY" \
-H "Content-Type: application/json" > "$TEMP_FILE"
# Check if the request was successful
if [ $? -ne 0 ]; then
echo "Failed to retrieve data from Cloudflare API."
return 1
fi
# Extract the 'result' array from the JSON response and append it to the RESULTS array
jq -c '.result[]' "$TEMP_FILE" >> "$CF_ALL_PAGES_FILE"
# Increment the page number for the next request
PAGE=$((PAGE + 1))
# Check if there are more pages to fetch
local TOTAL_PAGES=$(jq -r '.result_info.total_pages' "$TEMP_FILE")
if [ $PAGE -gt $TOTAL_PAGES ]; then
break
fi
done
echo "All pages have been successfully merged into $CF_ALL_PAGES_FILE"
}
#cf_list_projects
Note some of the things are not the same for various ways of deploying pages.
So check if each of these actually exists Notably sometimes its last_stage incited of latest_deployment