Skip to Content
Technical Articles
Author's profile photo Jascha Kanngiesser

FAQ & Troubleshooting Guide for @sap/datasphere-cli

This blog post is part of a series of blogs I published about @sap/datasphere-cli. Find all blog posts related to this topic in my overview blog post here.

The Node.js-based Command-Line Interface (CLI) for SAP Datasphere, @sap/datasphere-cli hosted on npmjs.com, allows you to interact with your SAP Datasphere tenant from the terminal or command line. 

Introduction

Using the Command-line Interface (CLI) for SAP Datasphere is much fun and certainly increases productivity! 🥳 But there’s always another dark side, too – when things don’t work as expected and you don’t know how to solve it. This blog aims at gathering all the well-known issues around using the CLI, and is your go-to blog to ask questions about using the CLI and troubleshooting problems you face along the way.

Troubleshooting

If something goes wrong and a command fails, you typically get a single error message “Failed to …”, for example, “Failed to initialize the local CLI cache”. To get more information, you can always append the –verbose option to any command. Adding the –verbose option tells the CLI to output more information such as the request sent to the server, the response status code and message, and a correlation ID if available in the response.

The blog provides help with the following problems when using @sap/datasphere-cli:

  • Error message “self-signed certificate in certificate chain”
  • Error message “Failed to initialize the local CLI cache”
  • “401 Unauthorized” when running commands
  • datasphere login command does no action

Error message “self-signed certificate in certificate chain”

$ datasphere login --secrets-file /path/to/secrets/file.json --verbose
POST https://your-datasphere-tenant.authentication.eu10.hana.ondemand.com/oauth/token
Request failed with message "self-signed certificate in certificate chain"
Failed to log in to your account using interactive OAuth authentication

Code Sample 1 – Failed command due to self-signed certificates

This error can occur if you are behind a proxy using self-signed certificates. You can try the following solutions to overcome this issue.

1. Switching to HTTP

Entering all URLs using the HTTP instead of HTTPS protocol can help to overcome this issue. Run the command again and replace https:// with http:// in any URL you are using.

2. NODE_TLS_REJECT_UNAUTHORIZED=0

Set environment variable NODE_TLS_REJECT_UNAUTHORIZED=0. This tells the Node.js runtime to not verify self-signed certificates. You want to use this option with care, as it might introduce security leaks in your application.

See also levelup.gitconnected.com/how-to-resolve-certificate-errors-in-nodejs-app-involving-ssl-calls for more information.

3. Including custom certificates in the certificate chain

The following sources provide insights into how you can include custom-generated or self-signed certificates into your machine’s certificate chain. Check out for example stackoverflow.com/how-to-add-custom-certificate-authority-ca-to-nodejs for more information.

Error message “Failed to initialize the local CLI cache”

$ datasphere cache init --verbose
GET https://your-datasphere-tenant.eu10.hcs.cloud.sap/dwaas-core/api/v1/discovery
Failed to initialize the local CLI cache

Code Sample 2 – The CLI failed to initialize the local CLI cache

This error can occur when the CLI can successfully retrieve the document from the server but fails to store it locally on the machine’s hard drive. This issue is typically caused by the executing user missing write privileges to the .cache folder of the CLI installation. Current versions of the CLI store the document in the executing user’s home directory at ~/.@sap/datasphere-cli/.cache.

This error happened typically in earlier versions of the CLI, where the document wasn’t stored in the user’s home directory, but in the CLI installation directory, typically located outside the user’s home directory.

To solve this issue, make sure that the executing user/process has write access to the .cache folder. Either grant the user the required privileges or run the command in admin mode, for example using sudo on Mac.

$ sudo datasphere cache init
Password: ************

Code Sample 3 – Using sudo to run the command

“401 Unauthorized” when running commands

Are you using the datasphere host set command, logging in using OAuth clients, and dealing with multiple tenants as well? This combination of different factors can cause 401 Unauthorized responses in case the configured host does not match the target server of the OAuth client.

You can tell whether the comand fails by adding the –verbose option to the command.

$ datasphere config cache init --verbose
GET https://some.tenant.eu10.hcs.cloud.sap/dwaas-core/api/v1/discovery
Request failed with 401 Unauthorized
Correlation ID 6ae2b9b1-664d-4c56-4779-55aa8cf44018
POST https://some.different.tenant.authentication.eu10.hana.ondemand.com/oauth/token
200 OK
Correlation ID dbe84b0f-6675-4e51-56ba-88f147c94802
GET https://some.tenant.eu10.hcs.cloud.sap/dwaas-core/api/v1/discovery
Request failed with 401 Unauthorized
Correlation ID f83062ce-5595-4857-4943-0c59b5976b6f
Failed to initialize the local CLI cache

Code Sample 4 – Requests sent to two different hosts

In Code Sample 4 you can see that the initial request is sent to tenant some.tenant, but because the login information point to a different tenant some.different.tenant than the tenant some.tenant configured globally, the returned access token is rejected by some.tenant.

To solve this issue, check the maintained host and stored secrets to authenticate and compare the URLs. They both should point to the same SAP Datasphere tenant.

$ datasphere host show
https://your-datasphere-tenant.eu10.hcs.cloud.sap/

Code Sample 5 – Configured host

$ datasphere secrets show
{
  "client_id": "sb-...",
  "client_secret": "9d27f40a-...",
  "authorization_url": "https://your-datasphere-tenant.authentication.eu10.hana.ondemand.com/oauth/authorize",
  "token_url": "https://your-datasphere-tenant.authentication.eu10.hana.ondemand.com/oauth/token",
  "access_token": "ey...",
  "token_type": "bearer",
  "id_token": "ey...",
  "refresh_token": "ba...",
  "expires_in": 3599,
  "scope": "open...",
  "jti": "4d...",
  "expires_after": 1688147408
}

Code Sample 6 – Locally stored login information

Make sure that the locally configured host URL matches the authorization and token URL. Otherwise, you receive a 401 Unauthorized response because the access token generated for tenant A cannot be used for tenant B.

datasphere login command does no action

When you run datasphere login, the CLi completes the command immediately and does not ask for client ID or client secret. When you provide a secrets file using the –secrets-file option, the CLI does not open the browser window.

$ datasphere login

Code Sample 7 – The datasphere login command does no action

You are already logged in. Run the datasphere logout command first, then run the datasphere login command again.

$ datasphere logout
$ datasphere login
✔ Please enter your client ID: … abc...
✔ Please enter your client secret: … ********************************************
✔ Please enter your authorization URL: … https://...
✔ Please enter your token URL: … https://...

Code Sample 8 – Log out first, then log in

Conclusion

Facing any troubles or issues when using @sap/datasphere-cli? Let me know in the comments and we can figure it out together! Any questions you have around @sap/datasphere-cli which are not yet covered by the official documentation on help.sap.com or in the package README? Let me know in the comments, too! 

I’d be happy to hear your thoughts, ideas, and comments on this tool and what you think would be a nice-to-have enhancement to the CLI, making your life and work with SAP Datasphere easier. Let me know in the comments!

Further Reading

Command-Line Interface for SAP Datasphere on npmjs.com

Command-Line Interface for SAP Datasphere on SAP Help

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Tobias Meyer
      Tobias Meyer

      Hi Jascha,

      thanks for the CLI. Some Ideas from my side are:

       

      • Enable Sharing of Objects ot other Spaces
      • Create Time Tables
      • upload from csv files for training pupose

      More Information about what options each element has, like possible data types to create tables etc. directly from scratch

       

      best regards

      tobias

      Author's profile photo Sebastian Esch
      Sebastian Esch

      Hi Jascha Kanngiesser,

      is the Datasphere CLI supported to run on SAP Business Application Studio? I can install the NPM module without any issues. After installation I can run datasphere -v and get the version number, but when I run datasphere cache init nothing happens - no prompts, no error messages, the process does not exit.

      Kind regards,

      Sebastian

      Author's profile photo Gebhard Roos
      Gebhard Roos

      Hello Sebastian,

       

      before you use the cache init, you have to logon to a system with the datasphere logon command.

       

      BR Gebhard