ServiceNow CLI User Guide
ServiceNow CLI User Guide
User Guide
Table of Contents
What is the ServiceNow CLI? .................................................................................................................... 3
Installing the CLI ......................................................................................................................................... 3
MacOS ..................................................................................................................................................... 3
Windows................................................................................................................................................... 4
Linux .......................................................................................................................................................... 4
Configuring the CLI .................................................................................................................................... 5
Initial Configuration ................................................................................................................................ 5
Configuration File.................................................................................................................................... 6
Named Profiles ........................................................................................................................................ 6
Command Line Options......................................................................................................................... 8
Using the CLI ............................................................................................................................................... 8
Getting Help ............................................................................................................................................ 8
Command Structure............................................................................................................................. 10
Specifying Parameter Values .............................................................................................................. 11
Controlling Command Output............................................................................................................ 11
Extensions .................................................................................................................................................. 13
Find Extensions....................................................................................................................................... 13
Install Extensions .................................................................................................................................... 13
Update Extensions ................................................................................................................................ 14
Uninstall Extensions ................................................................................................................................ 14
UI-Component Extension ........................................................................................................................ 14
Prerequisites ........................................................................................................................................... 14
Installing the extension ......................................................................................................................... 14
Creating a component project .......................................................................................................... 14
Running a project locally ..................................................................................................................... 15
Deploying a component to an instance ........................................................................................... 16
Development Configuration ............................................................................................................... 16
Reference ................................................................................................................................................. 18
snc configure ........................................................................................................................................ 18
snc extension ......................................................................................................................................... 19
snc record.............................................................................................................................................. 19
snc version ............................................................................................................................................. 21
2
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
What is the ServiceNow CLI?
The ServiceNow Command Line Interface (CLI) is an extensible framework that enables users to
communicate with an instance from any client machine using the command line.
MacOS
Install the ServiceNow CLI on MacOS.
Prerequisites
• The ServiceNow CLI supports Apple-supported versions of 64-bit macOS.
5. To verify that the ServiceNow CLI is installed and the shell can find and run
the snc command in your $PATH, use the following commands.
$ which snc
/usr/local/bin/snc
$ snc version
3
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
{
"extensions": {},
"snc": "1.0.0"
}
Windows
Install the ServiceNow CLI on Windows.
Prerequisites
Before you can install the ServiceNow CLI on Windows, be sure you have the following:
• A 64-bit version of Windows 10 or later
• Admin rights to install software
If Windows is unable to find the program, you might need to close and reopen the
command prompt window to refresh the path.
Linux
Install the ServiceNow CLI on Linux.
Prerequisites
• You must be able to extract or "unzip" the downloaded package. If your operating
system doesn't have the built-in unzip command, use an equivalent.
• The ServiceNow CLI supports 64-bit versions of recent distributions of CentOS and Ubuntu.
4
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
Install the ServiceNow CLI on Linux using the installer
1. In your browser, download the installer bundle from the innovation lab.
• https://store.servicenow.com/sn_appstore_store.do#!/store/innovationlab
2. Unzip the downloaded bundle file to extract the OS-specific installers.
3. Locate and run the file snc-1.0.0-linux-x64-installer.run.
4. Follow the on-screen instructions.
• When prompted, ensure the ‘Add to PATH’ option is selected (requires sudo).
• If you do not have sudo access, you will have to manually create a symlink file in
your $PATH that points to the snc program by using the following commands at
the command prompt. If your $PATH includes a folder you can write to, you can
run the following command without sudo if you specify that folder as the target's
path. If you don't have a writable folder in your $PATH, you must use sudo in the
command to get permissions to write to the specified target folder. The default
location for a symlink is /usr/local/bin/.
5. To verify that the ServiceNow CLI is installed and the shell can find and run
the snc command in your $PATH, use the following commands.
$ which snc
~/ServiceNow CLI/bin/snc
$ snc version
{
"extensions": {},
"snc": "1.0.0"
}
Initial configuration
In order to enable the ServiceNow CLI to communicate with an instance, set up a default
profile using the configure profile set command. The CLI prompts you for the following pieces
of information:
Host
The host name of the ServiceNow instance to connect to. Supports both the full URL
(https://myinstance.service-now.com) or just the hostname (myinstance).
Login method
5
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
The login method to use to connect to the instance. Supports basic, OAuth, and OAuth +
MFA.
Username
The username to use to connect to the instance.
Password
The password to use to connect to the instance.
Client id
When login method is OAuth or OAuth+MFA, this is the client ID to use to connect to the
instance.
Client secret
When login method is OAuth or OAuth+MFA, this is the client secret to use to connect to the
instance.
Authentication code
When login method is OAuth+MFA, this is the authentication code to use to connect to the
instance.
Default output format
Specifies how the command results are formatted. Options are JSON, YAML, text, and table.
The ServiceNow CLI stores the credentials in the host system’s keychain while the non-sensitive
information is stored as a profile named default in the CLI’s configuration file. By default, the
information in this profile is used when you run a ServiceNow CLI command that does not
explicitly specify a profile to use.
The following example shows sample values. Replace them with your own.
Configuration file
The ServiceNow CLI stores profile information in a config.json file which, by default, is located in
the user’s home directory (~/.snc/config.json). The file is formatted as JSON with each profile
having its own node. By default, the ServiceNow CLI uses the settings found in the profile named
default. To use alternate settings, you can create and reference additional profiles. For more
information, see Named profiles.
Named profiles
A named profile is a collection of settings and credentials that you can apply to a ServiceNow
CLI command. When you specify a profile to run a command, the settings and credentials are
6
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
used to run that command. You can specify one profile that is the default and is used when no
profile is explicitly referenced. Other profiles have names that you can specify as a parameter
on the command line for individual commands.
The ServiceNow CLI supports using any number of multiple named profiles that are stored in
the config file and the host system’s keychain. You can configure additional profiles by using the
snc configure profile set command with the --profile option.
The following example shows a config file with two profiles. The first, default, is used when you
run a CLI command with no profile. The second is used when you run a CLI command with the -
-profile user1 parameter. Each profile can use different credentials and even specify different
hosts and output formats.
~/.snc/config.json (Linux & Mac) or %USERPROFILE%\.snc\config.json (Windows)
{
"profiles":{
"default":{
"host":"https://myinstance.service-now.com",
"loginmethod":"basic",
"username":"admin",
"output":"json",
"hostversion":"Paris",
"appversion":"1.0"
},
"user1":{
"host":"https://otherinstance.service-now.com",
"loginmethod":"basic",
"username":"user1",
"output":"yaml",
"hostversion":"Paris",
"appversion":"1.0"
}
}
}
To use a named profile, add the --profile profile-name option to your command.
7
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
"hostversion":"Paris",
"appversion":"1.0"
}
}
--debug
A boolean that provides debug logging output when executing a command. In addition
to the debug option, the ServiceNow CLI logs all command executions to a log file
located in ~/.snc/.logs (Linux & Mac) or %USERPROFILE%\.snc\.logs (Windows).
--profile
Specifies the named profile to use for this command. To set up additional named profiles,
you can use the snc configure profile set command with the --profile option.
--output
Specifies the output format to use for this command. The ServiceNow CLI supports the
following output formats.
• json: The output is formatted as JSON.
• yaml: The output is formatted as YAML.
• text: The output is formatted as multiple lines of tab-separated string values.
• table: The output is formatted as a table which presents the information in a
human-friendly format.
Name
set
Description
The description of what the command does and its return values.
Description
Configure connection profiles. This command is interactive and will prompt you for
each configuration value.
Synopsis
The basic syntax for using the command and its options.
Synopsis
snc configure profile set [arguments]
Available commands
The commands available under the current command group.
Available Commands
list : Lists the configured connection profiles.
refresh : Updates the available commands from the instance for the given profile.
remove : Removes the specified connection profile.
set : Configures connection profiles in order to communicate with an instance.
Command groups
The command groups available under the current command group.
9
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
Command Groups
profile : Set, view, and remove connection profiles.
Arguments
A description of each of the arguments the command accepts.
Arguments
-p, --profile string : Use a specific connection profile when executing a command.
Global arguments
The global arguments that the command accepts.
Global Arguments
-d, --debug Print logs to console.
-h, --help Display detailed help information.
-o, --output string Set the format for printing command output.
Examples
Examples showing the usage of the command and its options.
Examples
Create a new profile to save as the default:
$ snc configure profile set
Host:
Login method:
Username:
Password:
Client id:
Client secret:
Command structure
The ServiceNow CLI uses a hierarchical structure on the command line that must be specified in
this order:
1. The base call to the snc program.
2. The top-level command group followed by any nested command group(s).
3. The subcommand that specifies which operation to perform.
4. General CLI arguments required by the operation. You can specify these in any order as
long as they follow the first three parts.
10
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
$ snc <command-group> <subcommand> [arguments]
Arguments can take various types of input values, such as numbers, strings, and JSON structures.
What is supported is dependent upon the command and subcommand you specify.
You can surround strings that do not contain any space characters with quotation marks or not.
However, you must use quotation marks around strings that include one or more space
characters.
{
"profiles":{
"default":{
"output":"text"
}
}
• Using the --output argument on the command line: The following example sets the
output of only this one command to json. Using this option on the command overrides
any currently set value in the config file.
11
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
JSON output format
JSON is the default output format of the ServiceNow CLI. Most programming languages can
easily decode JSON strings using built-in functions or with publicly available libraries.
The following is an example of JSON output.
12
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
The text format organizes the ServiceNow CLI output into tab-delimited lines. It works well with
traditional Unix text tools such as grep, sed, and awk, and the text processing performed by
PowerShell.
The following is an example of text output. Each field is tab separated from the others, with an
extra tab where there is an empty field.
Extensions
The ServiceNow CLI offers the capability to load extensions. Extensions provide additional
functionality that is not shipped as part of the CLI but run as CLI commands.
Find extensions
To see the available extensions provided by ServiceNow, use the snc extension list-
available command.
Install extensions
Once you have found an extension to install, use the snc extension add command.
13
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
$ snc extension add --name <extension-name>
Update extensions
Update an extension using the snc extension update command.
Uninstall extensions
If an extension is no longer needed, remove it using the snc extension remove command.
UI-Component extension
The ui-component extension provides the capability to build and deploy Now Experience
components.
Prerequisites
• The ui-component extension is compatible with Windows 10 and MacOS (Yosemite and
later).
• Node version 12.16.1 or greater. For instructions on how to install node, please visit here.
• npm version 6.13.14 or greater. For instructions on how to install npm, please visit here.
Verify the installation by running the extension with the --help argument.
14
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
The first step in creating a component is to scaffold a component project. This will create all the
necessary files to start developing a component. Note: The project command can only be run
within an empty directory.
$ snc ui-component project --name @myorg/movie-quotes --description 'A web component that
prints movie quotes.'
Parameters
• name (required): The project name. This should be a valid and unique npm package
name.
• description: The project description to be available in the npm registry and the Plugins list.
• scope: Suggested scope name to be assigned to this project and its components.
o Scope must be unique.
o If provided, scope might be validated against the current host.
o Scope is limited to 18 characters.
o Scope must be "snake_cased".
o If the offline option (below) is specified, then scope is mandatory.
o Must follow the form x_customerprefix_componentname, where:
§ customerprefix is the value in the glide.appcreator.company.code system
property on your instance.
§ componentname is the value provided in the component's name
parameter when you created the project.
o if scope is not provided, the Now CLI defaults the scope name
to x_{vendor_prefix}_{package_name}.
• offline: Does not connect to the current host during the scaffolding process, skipping
validation of the given scope name. Defaults to false.
Parameters
• entry: Path to the test module. Defaults to example/index.js.
15
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
• open: Opens the default browser and navigates to the test page. Defaults to false.
• port: Port where the development server should listen for incoming connections. Defaults
to 8081.
• host: Host address to use if you want your local dev-server to be accessible externally by
others. This is typically set to 0.0.0.0.
Parameters
• open: Opens the default browser and navigates to the connected instance. Defaults
to false.
• force: Deploys component changes and overwrites existing component records. Defaults
to false.
Development configuration
Component authors have the ability to override default configurations and customize their build,
test, and development processes. Be careful with these configuration changes as they can
greatly alter the ui-component’s behavior.
Make configuration changes using the now-cli.json file, found at the root of each component
project.
Here is a brief description of each property found in the now-cli.json configuration file.
{
"development":{
"proxy":{
"origin":"https://yourinstance.com",
"port":3000,
"proxies":[
"/api"
]
}
}
}
Parameters:
• development.proxy.headers: Headers to append to your proxied request.
16
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
• development.proxy.origin: Host to open a proxy with (your instance host address).
• development.proxy.port: The port the proxy will run on.
• development.proxy.proxies: URL glob patterns to pass-through to the proxy server.
17
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
Reference
snc configure
The configure command group lets you set, view, and remove properties used by the CLI.
Commands
snc configure profile
Set, view, and remove connection profiles. A default profile must first exist in order to
communicate with a ServiceNow instance.
18
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
Removes the specified connection profile. You cannot remove the default connection profile
using this command. To remove the default connection profile, edit the configuration file
manually.
snc extension
Manage and update extensions which provide additional functionality as CLI commands.
snc record
Perform create, read, update, and delete (CRUD) operations on existing tables. Note, these
commands are only available when connected to an instance with the CLI Metadata app
installed.
snc record create
Inserts one record in a specified table. You cannot insert multiple records using this
command.
19
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
$ snc record create [--table table, --data data]
Arguments
• table: Name of the table in which to save the record.
• data: Field name and the associated value for each field to define in the specified
record (JSON format).
Arguments
• table: Name of the table in which to delete the record.
• sysid: Sys ID of the record to delete.
Arguments
• table: Name of the table from which to retrieve the record.
• sysid: Unique identifier of the record to retrieve.
Arguments
• table: Name of the table in which to query the records.
• query: Encoded query used to filter the result set. Syntax: --query
‘<col_name><operator><value>’.
20
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.
• fields: Comma-separated list of field names to return from the database.
• limit: Maximum number of records to return.
• offset: Starting record index for which to begin retrieving records. Use this value to
paginate record retrieval.
• displayValue: For reference and choice fields, determines whether to retrieve the
display value or actual value from the database.
Arguments
• table: Name of the table in which to save the record.
• sysid: Sys ID of the record to update.
• data: Field name and the associated value for each field to define in the specified
record (JSON format).
snc version
Show the version of the snc CLI client and any installed extensions.
$ snc version
21
© 2021 ServiceNow, Inc. All rights reserved. ServiceNow, the ServiceNow logo, Now, Now Platform, and other ServiceNow marks are trademarks and/or registered
trademarks of ServiceNow, Inc. in the United States and/or other countries. Other company and product names may be trademarks of the respective
companies with which they are associated.