34 lines
809 B
Bash
Executable File
34 lines
809 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# 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
|