Files
openclaw-bms/scripts/bms-locations.sh
2026-04-07 19:08:52 +00:00

31 lines
731 B
Bash
Executable File

#!/usr/bin/env bash
# Get token from bms-auth.sh
if ! token=$(bash "${SCRIPT_DIR}/bms-auth.sh" get-token 2>/dev/null); then
echo "Error: Failed to retrieve BMS token" >&2
exit 1
fi
case "${1}" in
--account|--account=*)
account_id="${1#*=}" || account_id="${2}"
shift $(($# > 1 ? 2 : 1))
;;
*)
echo "Usage: $0 --account <id>" >&2
exit 1
;;
esac
curl --silent --show-error --fail \
-H "Authorization: Bearer $token" \
"https://api.bms.kaseya.com/v2/crm/accounts/${account_id}/locations/lookup" | \
jq -r '.result[]? // .[]' | \
while IFS= read -r line; do
id=$(echo "$line" | jq -r '.Id')
name=$(echo "$line" | jq -r '.Name')
printf "%-10s %-40s\n" "$id" "$name"
done
exit 0