@onmyway133/servicenow-cli
v1.0.1
Published
A TypeScript/Bun CLI for ServiceNow — AI-friendly, supports Table API, Incident, Change, CMDB, and more
Readme
servicenow-cli
A TypeScript/Bun CLI for ServiceNow — AI-friendly, comprehensive API coverage, supports any hosted instance.
Features
- Full Table API (query, get, create, update, delete)
- Incident & Change management with human-readable output
- Aggregate API for reporting
- Attachment management
- CMDB queries
- Import Set API
- Three auth modes: Basic, API key, or Cookie/token (for SSO instances)
--jsonflag for clean stdout output (ideal for AI agents)--dry-runflag for safe previewing of writes- Config stored in
~/.config/servicenow-cli/config.json
Install
git clone https://github.com/onmyway133/servicenow-cli
cd servicenow-cli
bun install
bun link # makes `sn` available globallyQuick Start
# Interactive setup
sn config init
# List open incidents
sn incident list --limit 10
# Get a specific incident
sn incident get INC0010001
# Output JSON (for AI/scripting)
sn incident list --jsonAuth Modes
Cookie mode (for SSO/hosted instances without API tokens)
Some ServiceNow instances use SSO (ADFS, SAML, etc.) and don't expose API keys. In this case, grab your session cookie from Chrome DevTools:
- Open Chrome → your ServiceNow instance → DevTools → Application → Cookies
- Copy the full cookie string (all cookies for the domain)
- Set it:
sn config init
# Choose: cookie
# Paste the cookie string when promptedOr pass it inline:
sn incident list \
--instance https://yourcompany.service-now.com \
--cookie "glide_user=abc; glide_session_store=xyz; ..." \
--jsonThe CLI auto-fetches X-UserToken from the response headers — no manual token needed.
API key mode
sn config init
# Choose: apikey
# Enter your x-sn-apikeyOr inline:
sn incident list --instance https://dev12345.service-now.com --api-key your-key-hereBasic auth
sn config init
# Choose: basic
# Enter username + passwordEnvironment variables
All auth can be provided via env:
export SN_INSTANCE=https://yourinstance.service-now.com
export SN_COOKIE="glide_user=..." # cookie mode
export SN_API_KEY=your-key # apikey mode
export SN_USERNAME=admin # basic mode
export SN_PASSWORD=passCommands
incident
sn incident list
sn incident list --state 1 # 1=New, 2=In Progress, 6=Resolved, 7=Closed
sn incident list --group "PM Payments" --limit 50
sn incident list --query "priority=1^state=1" --json
sn incident get INC0010001
sn incident update INC0010001 --group "New Team" --note "Routing reason"
sn incident update INC0010001 --group "New Team" --dry-run # preview onlychange
sn change list
sn change list --state scheduled --type normal
sn change get CHG0010001table (generic Table API)
sn table query sys_user --query "active=true" --fields "name,email,user_name"
sn table get incident <sys_id>
sn table create incident --data '{"short_description":"Test","category":"software"}'
sn table update incident <sys_id> --data '{"state":"2"}'
sn table delete incident <sys_id> --dry-runaggregate
sn aggregate incident --group-by assignment_group
sn aggregate incident --query "active=true" --group-by priority --jsonattachment
sn attachment list incident <incident_sys_id>
sn attachment get <attachment_sys_id>
sn attachment delete <attachment_sys_id>cmdb
sn cmdb list
sn cmdb list --class cmdb_ci_server --query "operational_status=1" --limit 50
sn cmdb get <sys_id> --class cmdb_ci_serverimport
sn import create u_my_staging_table --data '{"u_field":"value"}'config
sn config init # interactive setup
sn config show # view config (secrets masked)
sn config set instance https://newinstance.service-now.com
sn config set auth.cookie "new-cookie-string"AI Usage
This CLI is designed to be called by AI agents. Key patterns:
- Use
--jsonfor structured output (clean stdout, no decorations) - Use
--dry-runbefore any write operations - All errors go to stderr, data to stdout
- Exit codes: 0 = success, 1 = error
Example AI workflow:
# List incidents as JSON for the AI to parse
sn incident list --group "PM Payments" --limit 20 --json
# Get full incident detail
sn incident get INC0010001 --json
# Propose a reassignment (dry-run first)
sn incident update INC0010001 --group "T&S CCS I&I Identity Authentication" \
--note "Login failure — routing to identity team" --dry-runDevelopment
bun test # run tests
bun run src/index.ts --help # dev runLicense
MIT License — Copyright © 2026 Khoa Pham
