Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZJSON examples in ABAP #20

Closed
bryansippel opened this issue Feb 10, 2016 · 2 comments
Closed

ZJSON examples in ABAP #20

bryansippel opened this issue Feb 10, 2016 · 2 comments

Comments

@bryansippel
Copy link

I have to thank you so very much for providing the plugins you have created. I am really hoping they can help me create an ABAP program interface to connect to an external RESTful web service using JSON, but so far, I have been searching everywhere I can think of but I'm not finding any clear examples of how to use this stuff.

Unfortunately, I am a long time ABAP developer and never really got into the web side of things. I understand some concepts regarding HTML and HTTP communication, but REST and JSON are very new to me. Can you please point me to a step-by-step example in ABAP (via SAPGui, not Eclipse and we are not on 7.4 yet) showing exactly how I need to call a REST service?

So far, I am using the CL_HTTP_CLIENT class CREATE_BY_DESTINATION method to open a connection to the external service using Basic Authentication. The base URL is secure.smartwaregroup.com and our path is /Bigfoot/PABCO with various method subpaths depending upon the specific function we need to call.

My trouble spot has been trying to call their /api/login method where I need to pass the LoginName, Password, CultureCode ('en-US'), and Expires (120 minutes) parameters but I'm having trouble with the HTTP / REST / JSON syntax using the ABAP CL_HTTP_CLIENT class.

I have called CL_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD to set the values: '~server_protocol' = 'HTTP/1.1', 'Accept' = 'application/json', and 'Content-Type' = 'application/json; charset=utf-8'.

I have also called CL_HTTP_CLIENT->REQUEST->SET_METHOD to set the method to POST and CL_HTTP_UTILITY=>SET_REQUEST_URI to the full method path /Bigfoot/PABCO/api/login.

I have tried setting the login parameters as form fields, but I think they need it in JSON format, so I then just hardcoded what they expect and called CL_HTTP_CLIENT->REQUEST->SET_CDATA but their server returns a login screen as if my request was rejected. It should instead return a session ID.

Am I on the right track?? Does the SET_CDATA (or SET_DATA) method place the specified content into the "payload" or should I be doing something else?

Thank you so much for any assistance you can provide.

Bryan

@gregorwolf
Copy link
Contributor

Dear Bryan,

I hope you know SCN. I think you should try searching it via https://cse.google.com/cse/home?cx=013447253335410278659:k8ob9ipscwg for "abap rest client". http://scn.sap.com/community/abap/blog/2011/03/11/an-abap-rest-client looks like a good starting point for me. Test using the REST API using one of the tools mentioned there. In my project https://sap.assembla.com/spaces/zgeocode/subversion/source you find an ABAP Example for an REST client.

Best regards
Gregor

@bryansippel
Copy link
Author

I was not familiar with SCN. Thanks. I have however seen many of those posts via SDN and just Google, but I will finish looking through the ones I have not already seen.

Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants