on 09-12-2016 3:16 PM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
Yes!!!
With "https://<host>/sap/hana/xs/dt/base/file/services/test.xsjs" I was able to download the XSJS.
Thanks, Michael.
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
To be more concrete:
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
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
Well those command aren't really done via SQL, that is mostly XS logic. But it is exposed via a REST API.
You could call the REST API from the command line with CURL.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.