npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@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)
  • --json flag for clean stdout output (ideal for AI agents)
  • --dry-run flag 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 globally

Quick 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 --json

Auth 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:

  1. Open Chrome → your ServiceNow instance → DevTools → Application → Cookies
  2. Copy the full cookie string (all cookies for the domain)
  3. Set it:
sn config init
# Choose: cookie
# Paste the cookie string when prompted

Or pass it inline:

sn incident list \
  --instance https://yourcompany.service-now.com \
  --cookie "glide_user=abc; glide_session_store=xyz; ..." \
  --json

The 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-apikey

Or inline:

sn incident list --instance https://dev12345.service-now.com --api-key your-key-here

Basic auth

sn config init
# Choose: basic
# Enter username + password

Environment 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=pass

Commands

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 only

change

sn change list
sn change list --state scheduled --type normal
sn change get CHG0010001

table (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-run

aggregate

sn aggregate incident --group-by assignment_group
sn aggregate incident --query "active=true" --group-by priority --json

attachment

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_server

import

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 --json for structured output (clean stdout, no decorations)
  • Use --dry-run before 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-run

Development

bun test           # run tests
bun run src/index.ts --help  # dev run

License

MIT License — Copyright © 2026 Khoa Pham