api

Use api when you want to call a ServiceNow endpoint directly instead of using a higher-level command.

snow-cli api <verb> [options]

All api subcommands also accept the global flags from the command overview.

Supported verbs

  • api get <path>
  • api post <path>
  • api put <path>
  • api delete <path>

<path> should be a ServiceNow-relative path such as:

/api/now/table/incident?sysparm_limit=1
/api/x_myapp/status

Common options

  • -H, --header 'Key: Value': add a custom header; repeat the flag to send multiple headers
  • --data <body>: request body for post and put

Examples:

snow-cli api get /api/now/table/incident?sysparm_limit=1
snow-cli api post /api/x_myapp/action --data '{"dry_run":true}'
snow-cli api put /api/x_myapp/config --data '{"enabled":true}'
snow-cli api delete /api/x_myapp/config/abc123
snow-cli api get /api/x_myapp/status -H 'X-Trace-Id: abc123'

api get <path>

Send a GET request.

snow-cli api get <path> [-H 'Key: Value']

Use this for read-only endpoints.

api post <path>

Send a POST request.

snow-cli api post <path> [--data '{"key":"value"}']

If --data is omitted and stdin is piped in, the CLI reads the request body from stdin.

Example:

echo '{"dry_run":true}' | snow-cli api post /api/x_myapp/action

api put <path>

Send a PUT request.

snow-cli api put <path> [--data '{"key":"value"}']

Like post, this can also read the body from stdin.

api delete <path>

Send a DELETE request.

snow-cli api delete <path>

Use -H if the endpoint needs additional headers.

Response handling

snow-cli prints the raw response body to stdout.

  • If the response is valid JSON and you use JSON-like output, the CLI pretty-prints it.
  • If the response is not valid JSON, the body is printed as-is.
  • --output csv prints the raw body unchanged.

This makes api the most flexible command when you need an endpoint that does not yet have a dedicated command.