Pagination & Error Handling Patterns

API pagination and error handling patterns from real automation work. Every entry has a date and context.

2026-03-22: ISE ERS Pagination Loop

Problem: ERS returns max 100 results per page. Need to iterate through all pages for full endpoint inventory.

Context: ISE endpoint audit, CHLA environment with ~1800 endpoints

The Fix:

# Shell pagination loop for full endpoint inventory
PAGE=1
TOTAL=1  # will be updated from first response
while [ $PAGE -le $((TOTAL / 100 + 1)) ]; do
  RESPONSE=$(curl -s -k -u "$ISE_API_USER:$ISE_API_PASS" \
    -H "Accept: application/json" \
    "https://ise-01.inside.domusdigitalis.dev:9060/ers/config/endpoint?page=$PAGE&size=100")
  TOTAL=$(echo "$RESPONSE" | jq '.SearchResult.total')
  echo "$RESPONSE" | jq '.SearchResult.resources[]'
  PAGE=$((PAGE + 1))
done

Rule: Read total from first response. Calculate page count. Loop until done. Never assume one page is all. ERS max is size=100 — requesting more silently caps at 100.

Worklog: WRKLOG-2026-03-22


2026-03-24: Retry with Exponential Backoff

Problem: ISE ERS occasionally returns 429 (rate limited) or 503 (service unavailable) during bulk operations.

Context: netapi development, bulk endpoint operations against CHLA ISE with thousands of endpoints

The Fix:

# Simple retry with exponential backoff
MAX_RETRIES=3
DELAY=2
for i in $(seq 1 $MAX_RETRIES); do
  HTTP_CODE=$(curl -s -w '%{http_code}' -o /tmp/api-response.json \
    -k -u "$ISE_API_USER:$ISE_API_PASS" \
    -H "Accept: application/json" \
    "https://ise-01.inside.domusdigitalis.dev:9060/ers/config/endpoint?size=100")
  [ "$HTTP_CODE" = "200" ] && break
  echo "Retry $i/$MAX_RETRIES (HTTP $HTTP_CODE), waiting ${DELAY}s..."
  sleep $DELAY
  DELAY=$((DELAY * 2))
done

# Process result
if [ "$HTTP_CODE" = "200" ]; then
  jq '.SearchResult.resources' /tmp/api-response.json
else
  echo "FAILED after $MAX_RETRIES retries (last HTTP $HTTP_CODE)"
  exit 1
fi

Rule: Retry on 429/503/5xx. Exponential backoff (2s, 4s, 8s). Never retry on 4xx (client error) except 429 — those are bugs in your request, not transient failures.

Worklog: WRKLOG-2026-03-24