Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP call from SAP ECC6 to REST API service on Kepware

johnm16
Participant
0 Kudos

Hi Folks,

there are already several helpful postings on SAP Answers re. calling an external REST API using HTTP. I've read this one:

https://blogs.sap.com/2014/11/09/calling-an-external-restful-service-from-abap-http-method-get/

I'm struggling to implement it, because it isn't calling a Kepware instance. If anyone has successfully managed a call from ABAP to Kepware, I'd be very grateful for a code sample. If not, any help with the following questions will be gratefully received.

When I test the Kepware API using Postman, I use this URL for the GET command: http:\\127.0.0.1:57412/config/v1/project/channels - and it works.

1. If I create an RFC destination (type G) in SM59, how does this URL map on to the target host, service number and path prefix? (In the example above by Amaresh Pani, the Path Prefix in his RFC destination entry looks to me like a suffix, not a prefix).

2. In Postman, I have to enter the user name and password for Kepware: would this be the SAP equivalent of basic authentication?

3. The SAP instance and the Kepware server are running on the same Windows server, so all connectivity is local. Given that, should I be getting NIEHOST_UNKNOWN when I test the RFC destination?

Thanks for reading,

John

5 REPLIES 5

Sandra_Rossi
Active Contributor
0 Kudos

Did you try the existing RFC destinations SAPHTTP (if Kepware can be accessed from your laptop) or SAPHTTPA (if Kepware can be accessed from the system where SAP is installed)?

johnm16
Participant
0 Kudos

Hi Sandra,

thanks for the suggestion. Yes, Kepware is effectively on my laptop, albeit I'm 'remoting in' to a Windows server, and running both the SAP client and Kepware on it.

Looking at the ICM monitor report, I can see that when the first 'create_by_destination' method is called, it triggers an error: NiStrToAddrMask: invalid character in 'http:\\127.0.0.1' . This address works in Postman (where I pass the string http:\\127.0.0.1:57412/config/v1/project/channels ). Do you think this may be because SAP is happier with a server name rather than an IP address?

If I'm using a TCP/IP connection (saphttp) instead of a type 'G' connection, presumably I'd need to use cl_http_client=>create_by_url instead of ...create_by_destination?

Cheers

John

johnm16
Participant

Hi Sandra,

I've answered my own question, but added this as a comment so you'll see it.

My theory that the IP address might be causing the problem seems to be true: I substituted the local server name and my REST client is now responding.

Also, I realise (having woken up and smelled the coffee) that using create_by_url would give me no way to specify the saphttpa destination... but I'll remember your advice for future projects - I wasn't even aware of those two RFC destinations.

Many thanks,

John

Sandra_Rossi
Active Contributor
0 Kudos

http://127.0.0.1 would maybe work better than http:\\127.0.0.1 (slash instead of backslash)

It's up to you concerning create_by_url versus create_by_destination. RFC destinations are HIGHLY recommended if you use https because you can register the password and PSE name for storing the certificates, but are optional for the rest.

If you want to use the SAPHTTP destination, you must use create_by_destination (create_by_url can't work to use SM59 destinations).

About your solution, could you post it as an ANSWER please, so that future visitors can see directly your tips? Please indicate what you exactly used instead of http://127.0.0.1.

johnm16
Participant
0 Kudos

Hi Folks,

in SM59, I replaced http://127.0.0.1 with servername.company.local in the Target Host field. Substitute your own local server name: this only works if the SAP instance and the Kepware instance are running on the same server.

Anyway, I can now instantiate a REST client in ABAP, and I need to learn a whole lot more about Kepware.

Cheers

John