#!/usr/bin/env bash # bms.sh — Kaseya BMS CLI entrypoint # Usage: bms [subcommand] [options] set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" usage() { cat >&2 <<'EOF' bms — Kaseya BMS CLI Usage: bms auth [login|refresh|status] Authenticate / manage tokens bms tickets Manage tickets bms templates Browse ticket/note/timelog templates bms lookup Fetch lookup tables (IDs for statuses, etc.) Tickets subcommands: list List/search tickets get Get a single ticket create Create a new ticket (supports --template-id) update Update ticket fields note Add a note to a ticket assign Reassign a ticket resolve Resolve a ticket delete Delete ticket(s) Templates subcommands: tickets list List all ticket templates tickets get Show full details for a ticket template notes list List all note templates timelogs list List all timelog templates Lookup tables: statuses, priorities, queues, issue-types, sources, ticket-types, assignees, slas, work-types, note-types, all Examples: bms auth bms tickets list --status "Open" --assignee "Jane Doe" bms tickets list --from 2024-01-01 --to 2024-01-31 bms tickets get 12345 bms tickets create --title "Server down" --details "..." --account-id 1 \ --location-id 1 --status-id 1 --priority-id 2 --type-id 1 --source-id 1 bms tickets create --template-id 7 --title "Override title" --account-id 99 --location-id 5 bms tickets note 12345 --message "Called client" --internal bms tickets resolve 12345 --comment "Fixed by replacing NIC" bms templates tickets list bms templates tickets get 7 bms templates notes list bms templates timelogs list bms lookup statuses bms lookup priorities Environment variables (required): BMS_TENANT Your BMS tenant name BMS_USERNAME BMS username (or use BMS_CLIENT_ID) BMS_PASSWORD BMS password (or use BMS_CLIENT_SECRET) Optional: BMS_CLIENT_ID OAuth2 client ID BMS_CLIENT_SECRET OAuth2 client secret BMS_API_BASE Override API base URL (default: https://api.bms.kaseya.com) BMS_TOKEN_FILE Token cache path (default: ~/.bms_token.json) EOF exit 1 } cmd="${1:-}" [[ -n "$cmd" ]] || usage shift case "$cmd" in auth) exec bash "${SCRIPT_DIR}/bms-auth.sh" "$@" ;; tickets) exec bash "${SCRIPT_DIR}/bms-tickets.sh" "$@" ;; templates) exec bash "${SCRIPT_DIR}/bms-templates.sh" "$@" ;; lookup) exec bash "${SCRIPT_DIR}/bms-lookup.sh" "$@" ;; help|-h|--help) usage ;; *) echo "Unknown command: $cmd" >&2 usage ;; esac