Application Development and Automation 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: 
Read only

Update external service using POST method

ashok2021
Explorer
0 Likes
2,141

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

1 ACCEPTED SOLUTION
Read only

ashok2021
Explorer
0 Likes
1,998

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.

4 REPLIES 4
Read only

1,998

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>
Read only

0 Likes
1,998

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

Read only

KatiNonhebel
Advisor
Advisor
0 Likes
1,998

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

Read only

ashok2021
Explorer
0 Likes
1,999

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.