Missing total field in Bamboo /api/plan pagination prevents determining total record count
0 reputation · 10 Jun 2021, 15:03 UTC
0 reputation · 10 Jun 2021, 15:03 UTC
When querying the Bamboo REST API endpoint /api/plan to list all build plans, the response includes the fields size, limit, isLastPage and the array of plan objects, but it does not contain a total field that indicates the overall number of plans.
Without a total value, a client cannot calculate progress percentages or know when the final page has been reached without relying solely on isLastPage, which requires traversing every page to discover the end.
The documentation notes that some endpoints omit total, leaving it unclear whether an alternative method exists to obtain the count efficiently or if clients must iterate through all pages to infer it.
Is there another endpoint or query parameter that returns the total number of plans? If not, what is the recommended approach for determining the total count without fetching every page?
35275 reputation · 11 Jun 2021, 00:19 UTC
Short answer: no. The Bamboo plan-list resource (typically /rest/api/latest/plan) does not expose a total field, and there is no documented companion endpoint or query parameter that returns just the plan count. This is confirmed behavior for the resource itself; what follows about workarounds is the practical recommendation, and the exact paging fields vary by Bamboo version, so verify against your instance.
The paging metadata you see — size, limit/max-result, start-index, isLastPage — is all Bamboo guarantees. Two traps to avoid:
max-result does not mean you're done. Only isLastPage=true is authoritative.max-result fetches everything in one call. Values above the server cap are silently clamped, so you'd get a capped page with isLastPage=false and no warning.Page with a reasonably large max-result (e.g., 100–500), accumulate size from each response, and stop at isLastPage=true. The summed size is the total:
total=0; start=0
while true; do
r=$(curl -s -u user:token \
"$BAMBOO/rest/api/latest/plan?max-result=200&start-index=$start")
n=$(jq '.plans.size' <<<"$r")
total=$((total+n))
[ "$(jq '.plans.isLastPage' <<<"$r")" = "true" ] && break
start=$((start+n))
done
echo $totalIf you only need the count and want to save bandwidth (not round trips), request max-result=1 and count pages — but you still traverse to the end, so this rarely wins over summing sizes on pages you'd fetch anyway.
Plans change far less often than builds. The standard pattern is to compute the count once via traversal, cache it, and invalidate on plan create/delete events (webhooks or a periodic refresh). That gives you progress percentages without per-request full scans.
Bamboo Server/DC REST behavior differs across versions. Before committing to traversal:
/rest/api/latest/plan?max-result=1&start-index=0 on your instance and inspect exactly which paging fields come back.isLastPage=true and confirm the summed sizes match the plan count shown in the Bamboo admin UI.One caveat worth flagging for review: some Bamboo resources accept expand parameters that surface extra metadata, but a total count for the plan list is not reliably among them — treat that as version-dependent and unconfirmed until you test it on your instance.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.