cancel
Showing results for 
Search instead for 
Did you mean: 

Execute export/import of JS packages via command line

Former Member
0 Kudos

Hi all,

I have seen the nice export/import in the HANA WebIDE:

Is there a way to execute this function via command line (e.g. via SAP HANA HDBSQL), too?

Thanks for your help.

Best regards

Dan

Accepted Solutions (1)

Accepted Solutions (1)

Bruhn
Explorer
0 Kudos

Hi Dan,

Using Curl it would look something along the lines

curl -X "GET" "http://<host>:8000/sap/hana/xs/dt/base/file/getTickTimes/getProjectList.xsjs" \

    -H "Cookie: xsIdD59B93298881005C493F9DF22AD9D2EF=AF51E49B012810439E3220738BE19680; sapxslb=AAAB05E214F22144B30A8D41458B6CCA" \

    -H "Authorization: Basic <Encoded user/pwd>"

So initially you use the host and port of your hana xs engine next you use the /sap/hana/xs/dt/base/file api and last you specify the file you want in my example the /getTickTimes is the package followed by /getProjectList.xsjs which is the file name - above I have removed the basic auth part which is an encoded and in my case fairly simple to decode 😉 so you will have to fill in the details there.

I execute this from my terminal (on a mac) directly

curl -X "GET" "http://<host>:8000/sap/hana/xs/dt/base/file/getTickTimes/getProjectList.xsjs" \

    -H "Cookie: xsIdD59B93298881005C493F9DF22AD9D2EF=AF51E49B012810439E3220738BE19680; sapxslb=AAAB05E214F22144B30A8D41458B6CCA" \

    -H "Authorization: Basic <Encoded user/pwd>"


and get the following as a response


/**

* getProjectList.xsjs

*

* Reads the available projects

* and updates the forecast entries table in HANA

*

* Created by mbruhn on 02/08/16.

*/

/* Import library with functions for tickspot*/

$.import("getTickTimes", "tickSpotFunctions");

var gTickSpot = $.getTickTimes.tickSpotFunctions;

/* PROCESSING */

var hot = true; // update db(true) or not(false)

var userAgentInfo = "ourHanaIntegrationJob (johntryout@maildrop.cc)";

var tokens = gTickSpot.getTickSpotToken("getTickTimes", "tickspot", userAgentInfo);

var registeredProjects = gTickSpot.getProjectList("getTickTimes", "tickspotToken", userAgentInfo, tokens);

// sending back simple text information

$.response.setBody(gTickSpot.saveProjectList(registeredProjects, hot));

I hope this helps - You should consider using a 3rd party tool for putting the curl request together - I am a long time user of a mac tool called PAW (paw.cloud) another option is www.getpostman.com which works online and I know there are several clients for windows also.

Best regards

/MiB

Former Member
0 Kudos

Thanks, Michael.

This was very helpful. I will try your examples.

Best regards

Dan

Former Member
0 Kudos

Hi Michael,

now I tried this simple curl command (according to https://curl.haxx.se/docs/manpage.html😞


curl -k -o "downloads/test.xsjs" --user "<myUser:myPW>" --get "https://<host>/services/test.xsjs" --cookie "xsSecureId<...>=<cookie_content>"

This gives me the JSON-result of my XS service in my downloaded file. This is nice, but what I need instead is the source code of my XS service.

Do I have to deal with -x and -h parameters?

Thanks.

Best regards

Dan

Bruhn
Explorer
0 Kudos

Hi Again,

Well you are getting closer 😉 - what you are doing is as you say simply executing the service itself where you want to use an api which will read the file content. So instead of just "https://<host>/services/test.xsjs" try


"https://<host>/sap/hana/xs/dt/base/file/services/test.xsjs"

Hope it helps

/MiB

Former Member
0 Kudos

Yes!!!

With "https://<host>/sap/hana/xs/dt/base/file/services/test.xsjs" I was able to download the XSJS.

Thanks, Michael.

Former Member
0 Kudos

Now I am trying the other way around:

I have a file on my computer which I want to add to HANA XS.

I tried this curl command:


curl -k --user "USER:PW" -t "C:\Software\curl\uploads\test.txt" https://<host>/sap/hana/xs/dt/base/file/test --cookie "xsSecureId1...=...."

But it did not work out.

Michael, do you have curl example statements using PUT?

Thanks in advance.

Best regards

Dan

Former Member
0 Kudos

To be more concrete:

  1. I want to export the the content of a directory on HANA instance A.

  2. Afterwards I want to import and unzip the archive to HANA instance B - as it is possible via WebIDE (Import > Archive)

Step 1 is easy via CURL and File API statement:


curl -k -o "downloads/test.zip" 
--user "<USER>:<PASSWORD>"
--get "https://<HOST>/sap/hana/xs/dt/base/xfer/export/test.zip"
--cookie "xsSecure...=..."

But at step 2 I am stuck. Hope you can help.

Thanks.

Best regards

Dan

Bruhn
Explorer
0 Kudos

Hi again,

Sounds interesting 😉

I think that you need to do this in 3 steps:

a) get a token (X-CSRF-Token) inorder to do the post and put later on - I call the service for directory metadata and include the "fetch" in the header

curl -X "GET" "http://<HOST>:<PORT>/sap/hana/xs/dt/base/file/getTickTimes/" \

    -H "Cookie: ..." \

    -H "Authorization: ..." \

    -H "X-CSRF-Token: Fetch"

This returns a x-csrf-token field in the response header - you need to use this for the following two steps.

b) create an empty file POST

curl -X "POST" "http://<HOST><PORT>/sap/hana/xs/dt/base/file/getTickTimes/" \

    -H "Slug: myfile.txt" \

    -H "Authorization: ..." \

    -H "X-CSRF-Token: <what ever your received in the get Token call above>" \

    -H "Cookie: ..."

- the name of the new file is in the header field Slug

c) fill contents into the empty file PUT note this time the filename is embedded into the url

curl -X "PUT" "http://<HOST><PORT>/sap/hana/xs/dt/base/file/getTickTimes/myfile.txt" \

    -H "X-CSRF-Token: <what ever your received in the get Token call above>" \

    -H "Cookie: ..." \

    -H "Authorization: ..." \

    -H "Content-Type: text/plain; charset=utf-8" \

    -d $'This is the new contents

All of the content is send as the body - as text.

I hope this helps..

/MiB

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Well those command aren't really done via SQL, that is mostly XS logic.  But it is exposed via a REST API.

JSDoc: Tutorial: 2. File API

You could call the REST API from the command line with CURL.

Former Member
0 Kudos

Thanks, Thomas.

This looks pretty much what I need. Now I have to get familiar with CURL 😉

Former Member
0 Kudos

As I am very new to CURL:

Do you have any example statements to e.g. create a file or folder with CURL and the HANA File API?

By the way: Does the HANA File API also work with HTTPS?

Thanks for your help.

Best regards

Dan

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

CURL is a linux OS level tool, so you won't find any documentation from SAP on it. I'd suggest just searching Google for that information or ask a Linux system admin. In my experience its the kind of thing they do regularly. 

File API work with HTTPS - yes of course if your XSEngine is configured for HTTPS.  HTTPS support comes centrally, not at the individual service level.