I recently needed to collect data from external websites in json format using SAP HANA. There were some very useful blogs on scn to help me find my way. I however did notice that most of them were prior to SP09 and I therefore had one or two challenges trying to complete this as the user interface has changed slightly on HANA on the admin side. This blog will provide a more up to date reference but also share what blogs assisted me along the way.
Simple http request
So to create a simple app to communicate with the web I looked at SAP Help and found the following SAP HANA Cloud Platform
I found this helpful as it had simple code and worked with json.
Below is an example of taking the code from the example, you need to create a xshttpdest file as shown below.
Then create a xsjs file with the following code. Note that httpdest and xsjs file must be in the same directory.
You can now run the program, it will connect to google maps api. The example requests a distance calculation from Cologne in Germany to Frankfurt in Germany.
The output is in json format and in my screen it has come out in a neat structure, that is because I have app in my google chrome that does this for me. Depending on the browser the output can vary.
More Complex http request
So some sites when connecting it will be a secure website and uses https instead of http. In these instances in order to interact with the websites you will need a certificate to allow secure communication.
I found some very good blogs on this on scn by Kai-Christoph Mueller , they are
This was an excellent starting point for me, I however did have the following challenges
- The script in part 1 of Kai-Christoph blogs after executing gave me some errors where my web app server for xsjs wouldn’t start up. This was due to some of the standard settings in HANA webdispatcher.ini config were overwritten. I therefore reverted back to the standard settings and then by reading the script added the settings manually in SAP HANA Studio. The script was still executed to copy the files to the correct locations and register files. Below you can see the settings in hana studio
- In part 2 of Kai-Christoph blogs the screens for trust manager have changed in SP09. So navigate to http://hana:8001/sap/hana/xs/admin , follow the numbers as shown in the below screen shot. As you can see I have done this for twitter.
- Once you have done part 1 and part 2 you can connect to more secure sites using https. You however need to create the code in a similar manner as we showed in previous example connecting to google map api. Once the httpdest is done you will need to link httpdest to the certificate you imported. For completeness here is the code to connect to Twitter
I have intentionally smeared my bearer credentials. This is the authentication with twitter for my twitter account.
- In part 3 of Kai-Christoph blogs the screens for trust manager have changed in SP09. Here you want to link the xshttpdest file with the certificate we imported. Remember I have imported Twitter certificate, the httpdest is also for twitter. So below is the steps to navigate to http dest file and link with certificate we imported.
If you now run the application it will connect to twitter and search for SAP HANA tweets, will return search results in JSON as shown below.
The https can be more complex as linking the code to certificate is done in separate section. But once you know where to go and how to do it, it is then relatively simple.
I hope the above helps anyone trying to connect to HTTP from HANA.
Thanks. Good luck 🙂