LoginSignup
1
0

More than 1 year has passed since last update.

ServiceNow CLIを試してみる

Last updated at Posted at 2021-05-22

version: Paris(Quebec?)

※ (2021-05)インストールは成功しましたがコマンドの実行には失敗しています…

SeviceNowをクライアントマシンから操作出来るServiceNow CLIというものがあると知ったのでWindows 10 Home 64bitマシンで試します以下はドキュメントの翻訳です
https://docs.servicenow.com/bundle/quebec-application-development/page/build/servicenow-cli/concept/servicenow-cli.html#
image.png

ServiceNow CLIのダウンロード

ServiceNow Storeでクライアント用のアプリケーションを落としてインストールする必要がありそうです(ドキュメントはQuebecしか見当たりませんでしたがStoreの互換性バージョンを確認するとQuebec, Paris, Orlandoとなってます)
image.png
Downloadをクリックすると認証ダイアログが表示されます
image.png
ServiceNow IDを持っている(HIに登録されている?)場合"Login via sign-on(SSO)"をクリックしてメールアドレス, パスワードで認証後にメールで送られる6桁の数字を入力, 登録していない場合は"Are you customer who doesn't have ServiceNow ID?"をクリックでメールアドレスとメールで送られてくる32桁の英数字とインスタンス名を入力してダウンロードします(因みに"Are you a federal(連邦政府) customer?"はこの記事を読んでる人で該当する人がいるとも思えないのでパスします)

ServiceNow CLIのインストール

zipファイルがダウンロードされたので解答したところMacOS, Linux, Windows用のインストーラーが見受けられました
image.png
snc-1.1.0-windows-x64-installer.exeをダブルクリックして実行してWindows Defender?に警告を出されつつ進めるとSet Upダイアログが表示されました
image.png
[Next]して
image.png
acceptしてNextして
image.png
インストール先はそのままで[Next]して
image.png
PATHに追加のまま[Next]して
image.png
準備が出来たらしいので[Next]して
image.png
終わったらしいので[Finish]して
win + rで"cmd"と入力して[OK]でdos窓を立ち上げてsncコマンドを実行したところ以下のusageが表示されました

C:\*********>snc

Name
  snc

Description
  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.

Synopsis
  snc <command-group> <command> [arguments]

  To see a list of additional commands, first configure a default profile and then run "snc --help"

Available Commands
  help        : Help about any command
  version     : Show the version of the snc CLI client

  For additional help information on a specific command, run "snc <command> --help"

Command Groups
  configure   : The configure command group lets you set, view, and remove properties used by the CLI.
  extension   : Manage and update CLI extensions.

  To see a list of additional commands, run "snc <command-group> --help"

Arguments
  -d, --debug            Print logs to console
  -h, --help             Display detailed help information
      --no-interactive   Disable all interactive prompts when running commands
      --no-verbose       Disable printing user facing messages in console
  -o, --output string    Set the format for printing command output. The supported formats are json (default), yaml, table, text and none.
  -p, --profile string   Use a specific connection profile when executing a command. If you do not provide this argument, the CLI uses the default profile.

ServiceNow CLIの構成ファイル

構成ファイルが以下のパスにあるようなので
image.png
見てみたら無いので(.snc以下のディレクトリはsncコマンドを1回実行すると出来るようです)

C:\Users\********\.snc>dir
2021/05/22  09:29    <DIR>          .
2021/05/22  09:29    <DIR>          ..
2021/05/22  09:29    <DIR>          .extensions
2021/05/22  09:29    <DIR>          .logs

ドキュメントを参考に作ってみて

C:\Users\********\.snc>snc configure profile set
> Host: dev********
> Login method: Basic
> Username: admin
> Password: ********
> Default output format: JSON
Connection to https://dev********.service-now.com successful.
This instance does not support dynamic commands. Functionality will be limited.
Profile default has been saved

instanceがParisだったからかこのinstanceはdynamic commandをsupportしてない機能は限定されていると言われながら何んとか出来たようです

C:\Users\********\.snc>dir
2021/05/22  10:02    <DIR>          .
2021/05/22  10:02    <DIR>          ..
2021/05/22  10:02                77 .checksum.txt
2021/05/22  09:29    <DIR>          .extensions
2021/05/22  09:29    <DIR>          .logs
2021/05/22  10:02               201 config.json

コマンド実行

record createを試してみるもエラーになってしまいました(これがdynamic commandというやつなのか…?)

C:\Users\********\.snc>snc record create --table incident --data "{short_description: 'New Incident'}"
Error: unknown flag: --table

Quebecのinstanceを用意して試してみたいところですが…暫くは使えるinstanceが無さそうなので…ここまでで一旦止めておきます

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0