‎2021 Mar 04 7:25 PM
Hi,
I have a requirement where I need to post some data using an external RESTful service from ABAP with values. I have been provided the service name PLANNING_DATA_API_SRV which I have to call from a SAP SE38 program and pass some fixed values. Please let me know how to go about it as I have never done this before.
Thanks
‎2021 Jun 01 5:05 PM
The problem was solved. I had to get the Cookie values and the x-csrf-token using the GET method. Then use these along with the Transaction ID to post the data. I got a HTTP 201 message successfully.
‎2021 Mar 05 7:14 AM
Hii Ashok,
Create a Report program and call the Below Class and Method, if the RFC connection is built in SM59 for the API then use CL_HTTP_CLIENT=>CREATE_BY_DESTINATION
Get the Url for PLANNING_DATA_API_SRV
DATA: lo_http_client TYPE REF TO if_http_client.Use CL_HTTP_CLIENT to consume the OData service using the method "create_by_url"
cl_http_client=>create_by_url(
EXPORTING
url = lv_service
IMPORTING
client = lo_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4 ).
**** Send the request
lo_http_client->send(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2 ).
*** Receive the respose
lo_http_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3 ).
*** Read the result
CLEAR lv_result .
lv_result = lo_http_client->response->get_cdata( ).
write: lv_result.<br>
‎2021 Mar 05 2:47 PM
Hi Saif,
Thanks for the reply. I created a program. I used the GET and the POST methods for my program. In the GET part I had to get the CSRF token and the Transaction ID using cl_http_client=>create_by_destination and passing the RFC name. Next when using the POST method I used cl_http_client=>create_by_url, created the JSON file and passed the transaction ID and the CSRF token from the previous step. I get a HTTP 200 message but when I go to the destination system the data is not updated. Please assist.
Thanks,
Ashok
‎2021 Mar 05 7:16 AM
Thank you for visiting SAP Community to get answers to your questions. I recommend that you familiarize yourself with: https://community.sap.com/resources/questions-and-answers, as it provides tips for preparing questions that draw responses from our members.
For example, you can:
- outline what steps you took to find answers (and why they weren't helpful)
- share screenshots of what you've seen/done
- make sure you've applied the appropriate tags
- use a more descriptive subject line
The more details you provide, the more likely it is that members will be able to respond. Feel free to also take our Q&A tutorial at: https://developers.sap.com/tutorials/community-qa.html
Should you wish, you can revise your question by selecting Actions, then Edit.
By adding a picture to your profile you encourage readers to respond:https://www.youtube.com/watch?v=46bt1juWUUM
Keep in mind, when you receive an answer that was helpful to you, accept it as best answer.
Good Luck
Kati - SAP Community Moderator
‎2021 Jun 01 5:05 PM
The problem was solved. I had to get the Cookie values and the x-csrf-token using the GET method. Then use these along with the Transaction ID to post the data. I got a HTTP 201 message successfully.