A reseller asks you to move 240 of their cPanel accounts from a gold-2024 plan to a gold-2026 plan with bigger quota and a different feature list. The WHM UI lets you do this one account at a time, with a confirmation click. At 240 accounts, that’s an afternoon of clicking and a coffee-break-induced mistake on row 187. The right answer is the modifyacct API, called in a controlled loop with idempotency, rate limiting, and a dry-run mode — because the operation that does 240 things at once is also the operation that breaks 240 things at once if you’re not careful.
What’s happening
WHM exposes Account Functions via the /json-api/ interface — createacct, modifyacct, suspendacct, unsuspendacct, removeacct, passwd, changepackage, editquota. Each call is synchronous and takes 1-10 seconds depending on the action; a fleet of 200 accounts means 5-30 minutes of serial calls, and the WHM control plane is single-threaded for most account operations — running ten parallel modifyacct calls against the same server will cause wwwacctd queue contention and intermittent failures rather than 10x speedup.
The other thing the UI hides from you is that some operations are not idempotent. Calling suspendacct twice in a row is fine — the second call is a no-op. Calling changepackage twice with the same target package is fine. But calling modifyacct with a new quota will succeed the first time and might “succeed” the second time while actually clobbering a value the customer changed in between. Idempotency is a property you have to design in.
How to verify
Confirm your token has the right ACLs for the operations you plan to run:
whmapi1 --output=jsonpretty api_token_list_tokens | \
jq '.data.tokens[] | select(.name=="bulk-ops-2026-05") | {acls: .acls}'
You need modify-acct, change-package, suspend-acct, unsuspend-acct, passwd, and list-accts for the playbooks in this article.
Sample the target list with a read-only call first — this catches typos in usernames before you mutate anything:
while IFS= read -r user; do
whmapi1 --output=jsonpretty accountsummary user="$user" | \
jq -r --arg u "$user" '
if .data.acct[0].user then "OK \($u) \(.data.acct[0].plan)"
else "MISSING \($u)" end'
done < /tmp/target-users.txt
Any MISSING line is a username that does not exist on this server. Fix the list before running the mutation.
Watch the WHM access log live during a bulk operation:
tail -F /usr/local/cpanel/logs/access_log | grep -E '(modifyacct|changepackage|suspendacct)'
And watch the account-funcs log for the actual operations:
tail -F /var/cpanel/logs/account_actions
The fix
The pattern is: read the inventory, plan the changes, dry-run them, apply with rate limiting, verify, log. A single bash script that does the lot:
#!/usr/bin/env bash
# /usr/local/bin/whm-bulk-ops
# Bulk WHM account operations with idempotency + rate limiting + dry-run
set -euo pipefail
WHM_HOST="${WHM_HOST:-whm.example.com}"
WHM_USER="${WHM_USER:-root}"
WHM_TOKEN="${WHM_TOKEN:?set WHM_TOKEN env var (do not pass on cmdline)}"
RATE_DELAY="${RATE_DELAY:-2}" # seconds between calls
LOG_DIR="${LOG_DIR:-/var/log/whm-bulk}"
DRY_RUN="${DRY_RUN:-1}" # 1 = dry-run, 0 = apply
OP="${1:?usage: whm-bulk-ops <changepackage|suspend|unsuspend|modify-quota|reset-password> <input-file>}"
INPUT="${2:?}"
mkdir -p "$LOG_DIR"
RUN_ID="$(date +%Y%m%d-%H%M%S)-${OP}"
RUN_LOG="$LOG_DIR/$RUN_ID.log"
api() {
curl -sH "Authorization: whm ${WHM_USER}:${WHM_TOKEN}" \
"https://${WHM_HOST}:2087/json-api/$1"
}
log() { echo "[$(date -u +%FT%TZ)] $*" | tee -a "$RUN_LOG"; }
case "$OP" in
changepackage)
# input file: user,new_package
while IFS=, read -r user newpkg; do
[[ -z "$user" || "$user" =~ ^# ]] && continue
# idempotency: skip if already on target package
CUR=$(api "accountsummary?api.version=1&user=${user}" | jq -r '.data.acct[0].plan // "MISSING"')
if [[ "$CUR" == "MISSING" ]]; then
log "SKIP $user (not found)"
continue
fi
if [[ "$CUR" == "$newpkg" ]]; then
log "SKIP $user (already on $newpkg)"
continue
fi
if [[ "$DRY_RUN" == "1" ]]; then
log "DRY $user: $CUR -> $newpkg"
else
RESP=$(api "changepackage?api.version=1&user=${user}&pkg=${newpkg}")
OK=$(echo "$RESP" | jq -r '.metadata.result')
REASON=$(echo "$RESP" | jq -r '.metadata.reason')
if [[ "$OK" == "1" ]]; then
log "OK $user: $CUR -> $newpkg"
else
log "FAIL $user: $REASON"
fi
sleep "$RATE_DELAY"
fi
done < "$INPUT"
;;
suspend)
# input file: user,reason
while IFS=, read -r user reason; do
[[ -z "$user" || "$user" =~ ^# ]] && continue
STATE=$(api "accountsummary?api.version=1&user=${user}" | jq -r '.data.acct[0].suspended // "MISSING"')
if [[ "$STATE" == "MISSING" ]]; then
log "SKIP $user (not found)"; continue
fi
if [[ "$STATE" == "1" ]]; then
log "SKIP $user (already suspended)"; continue
fi
if [[ "$DRY_RUN" == "1" ]]; then
log "DRY suspend $user (reason: $reason)"
else
ENC_REASON=$(printf '%s' "$reason" | jq -sRr @uri)
RESP=$(api "suspendacct?api.version=1&user=${user}&reason=${ENC_REASON}")
OK=$(echo "$RESP" | jq -r '.metadata.result')
if [[ "$OK" == "1" ]]; then
log "OK suspended $user"
else
log "FAIL $user: $(echo "$RESP" | jq -r '.metadata.reason')"
fi
sleep "$RATE_DELAY"
fi
done < "$INPUT"
;;
unsuspend)
while IFS= read -r user; do
[[ -z "$user" || "$user" =~ ^# ]] && continue
STATE=$(api "accountsummary?api.version=1&user=${user}" | jq -r '.data.acct[0].suspended // "MISSING"')
if [[ "$STATE" == "MISSING" ]]; then log "SKIP $user (not found)"; continue; fi
if [[ "$STATE" == "0" ]]; then log "SKIP $user (not suspended)"; continue; fi
if [[ "$DRY_RUN" == "1" ]]; then
log "DRY unsuspend $user"
else
RESP=$(api "unsuspendacct?api.version=1&user=${user}")
OK=$(echo "$RESP" | jq -r '.metadata.result')
[[ "$OK" == "1" ]] && log "OK unsuspended $user" || log "FAIL $user"
sleep "$RATE_DELAY"
fi
done < "$INPUT"
;;
modify-quota)
# input file: user,new_quota_mb
while IFS=, read -r user newquota; do
[[ -z "$user" || "$user" =~ ^# ]] && continue
CUR=$(api "accountsummary?api.version=1&user=${user}" | jq -r '.data.acct[0].diskquota // "MISSING"')
if [[ "$CUR" == "MISSING" ]]; then log "SKIP $user (not found)"; continue; fi
if [[ "$CUR" == "$newquota" ]]; then log "SKIP $user (quota already $newquota)"; continue; fi
if [[ "$DRY_RUN" == "1" ]]; then
log "DRY $user quota $CUR -> $newquota"
else
RESP=$(api "modifyacct?api.version=1&user=${user}"a=${newquota}")
OK=$(echo "$RESP" | jq -r '.metadata.result')
[[ "$OK" == "1" ]] && log "OK $user quota $newquota" || log "FAIL $user"
sleep "$RATE_DELAY"
fi
done < "$INPUT"
;;
reset-password)
# input file: user
# generates a new password, stores it in vault under secret/cpanel/<user>/2026-05
while IFS= read -r user; do
[[ -z "$user" || "$user" =~ ^# ]] && continue
EXISTS=$(api "accountsummary?api.version=1&user=${user}" | jq -r '.data.acct[0].user // "MISSING"')
[[ "$EXISTS" == "MISSING" ]] && { log "SKIP $user (not found)"; continue; }
NEWPASS=$(openssl rand -base64 24 | tr -d '=/+')
if [[ "$DRY_RUN" == "1" ]]; then
log "DRY reset $user"
else
RESP=$(api "passwd?api.version=1&user=${user}&password=${NEWPASS}")
OK=$(echo "$RESP" | jq -r '.metadata.result')
if [[ "$OK" == "1" ]]; then
vault kv put "secret/cpanel/${user}/$(date +%Y-%m)" value="$NEWPASS" >/dev/null
log "OK reset $user (new pw in vault)"
else
log "FAIL $user: $(echo "$RESP" | jq -r '.metadata.reason')"
fi
unset NEWPASS
sleep "$RATE_DELAY"
fi
done < "$INPUT"
;;
*)
echo "unknown op: $OP"; exit 1 ;;
esac
log "Run $RUN_ID complete. Log: $RUN_LOG"
Usage pattern — always dry-run first:
# Step 1 — dry run, inspect the planned operations
WHM_TOKEN=$(vault kv get -field=value secret/whm/bulk-ops/2026-05) \
DRY_RUN=1 /usr/local/bin/whm-bulk-ops changepackage /tmp/upgrade-list.csv
# Step 2 — apply with rate limiting
WHM_TOKEN=$(vault kv get -field=value secret/whm/bulk-ops/2026-05) \
DRY_RUN=0 RATE_DELAY=2 /usr/local/bin/whm-bulk-ops changepackage /tmp/upgrade-list.csv
# Step 3 — verify post-state
while IFS=, read -r user expected; do
actual=$(curl -sH "Authorization: whm root:$TOKEN" \
"https://whm.example.com:2087/json-api/accountsummary?api.version=1&user=$user" | \
jq -r '.data.acct[0].plan')
if [[ "$actual" != "$expected" ]]; then
echo "MISMATCH $user actual=$actual expected=$expected"
fi
done < /tmp/upgrade-list.csv
A note on parallelism: do not run more than one whm-bulk-ops against the same WHM at the same time. The WHM control plane serializes account mutations internally; running parallel scripts just wastes the rate-limit budget and produces racy results in account_actions. If you need throughput, split the input list across servers, not across processes on the same server.
A rollback strategy for changepackage is straightforward: keep a snapshot of the pre-change state and feed it back into the same script. Before applying:
# Snapshot current state
while IFS=, read -r user newpkg; do
cur=$(curl -sH "Authorization: whm root:$TOKEN" \
"https://whm.example.com:2087/json-api/accountsummary?api.version=1&user=$user" | \
jq -r '.data.acct[0].plan')
echo "$user,$cur"
done < /tmp/upgrade-list.csv > /tmp/upgrade-list.snapshot.csv
To roll back the whole batch: re-run the script with /tmp/upgrade-list.snapshot.csv as input. The idempotency check means already-rolled-back users are skipped without error.
For modifyacct with quota changes, the rollback is the same — snapshot, restore. For password resets, there is no rollback; the original password is gone the moment WHM accepts the new one. That’s why password rotation campaigns need a customer-facing communication step, not just an API call.
Fleet-wide WHM operations — package migrations, quota campaigns, mass password resets, suspension waves for non-paying accounts — are exactly the work we automate inside Deployment Management with audit trails and rate-limit safeguards. Talk to us about a fleet review if you operate more than a handful of WHM servers.