Authenticate to a ServiceNow instance using basic authentication with the ServiceNow SDK

  • Freigeben Version: Australia
  • Aktualisiert 12. März 2026
  • 1 Minute Lesedauer
  • Use basic authentication to connect to a ServiceNow instance with the ServiceNow SDK.

    Vorbereitungen

    Role required: admin

    Warum und wann dieser Vorgang ausgeführt wird

    This procedure uses the ServiceNow SDK command-line interface (CLI). From a command-line tool, enter now-sdk --help to get information about the available commands and global options. To get additional information about a command and its parameters, enter the command and --help or -h. For example, now-sdk auth --help. For more information about the CLI, see ServiceNow SDK CLI.

    Prozedur

    1. Open a command-line tool on your system.
    2. Create a local directory for your application.
    3. In Visual Studio Code, open the directory.
    4. From the application directory, open an integrated Terminal window.
    5. Specify the instance to authenticate to with the auth command.Specify an alias and the authentication method to use with the auth save command.
      npx @servicenow/sdk auth --add <instance>
      now-sdk auth save <alias> --type basic

      To set this alias as the default alias, add the --default or -d parameter to your command.

      For example:
      npx @servicenow/sdk auth --add https://myinstance.service-now.com
      now-sdk auth save devuser1 --type basic --default true
      Hinweis:
      Using the npx command installs the ServiceNow SDK in your application directory instead of globally.
    6. Respond to the following series of prompts.
      Prompt Response
      Type of authentication to use Select basic.
      Alias for these credentials Enter an alias for your credentials and the instance.

      The alias can be used for authentication with the init, transform, dependencies, and install commands.

      The username to authenticate with the instance Enter your username for the instance.

      You must be assigned the admin role.

      The password to authenticate with the instance Enter your password.
    7. At the prompt, enter the target instance URL.
    8. At the prompt, enter your ServiceNow user name.

      You must be assigned the admin role.

    9. Enter your password.

    Ergebnisse

    The alias and credentials are stored in the device keychain or credential manager on your system and are set as the default credentials.

    Nächste Maßnahme

    Add an application to your local system with the ServiceNow SDK. For more information, see Adding applications with the ServiceNow SDK.