cancel
Showing results for 
Search instead for 
Did you mean: 

Consuming Rest web service in ABAP

Hello Friends, I am new to web service topic and read many articles before finally coming here to post my question.

My requirement is to consume a webservice provided by our partner as URL.

I have tested the scenario first in POSTMAN app, by passing some header and Body fields. It worked fine.

Now same thing I am trying to replicate in SAP ABAP, for this I have used cl_http_client=>create_by_url

Header Fields I am populating using http_client->request->set_header_field.

My query is how I can populate or which method I have to use in ABAP to populate the fields similar to what I am setting in BODY of postman app. I am putting screenshot of POSTMAN app, same I am looking to map in ABAP. Header is populated correctly now want to populate BODY.

This may be very basic question, but I am not able to yet figure out the solution.

Thanks,

Brij

Sandra_Rossi
Active Contributor
0 Kudos

Methods like set_data...

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Hi Thomas,

I tried this code, but still getting error,

lo_http_client->request->set_form_field( EXPORTING name = 'fileName'
value = 'abc.pdf' ).

Error:

{"error":{"code":500,"message":"An unexpected error occurred. Please contact the service."}}


0 Kudos

Sequence I am following is:

1) cl_http_client=>create_by_url

2) lo_http_client->request->set_method( 'POST' ).

3) lo_http_client->request->set_header_field

4) lo_http_client->request->set_form_field

Tomas_Buryanek
Active Contributor
0 Kudos

It is HTTP 500, which indicates error on server side...

Also try response->get_status( ) to get more info about what happened. But it will probably will be the same code "500" + reason "unexpected".

0 Kudos

Hi Thomas,

Yes we get same response if we use

response->get_status( ).. is there any way we can monitor restapi ?

Tomas_Buryanek
Active Contributor

brijsoni

  • Your request in POSTMAN works OK ( = HTTP 20x response) ?
  • If yes, then do you have everything exactly the same in ABAP like in POSTMAN request?
  • You can try check transaction SMICM and check communication log, if there is any problem (usually for example SSL certificate missing...)...
  • If nothing helps you will probably need to contat API provider and coordinate with them (debug/read log on their side), why they return you HTTP 500 error....
Tomas_Buryanek
Active Contributor
0 Kudos

Hello,

for HTTP "Form fields" you can use:

request->set_form_field  "for one field+value
request->set_form_fields "for multiple at once
"Example:
lo_http_client->request->set_form_field( EXPORTING name  = ''
                                                   value = '' ).

Hi Tomas

  • It is working correctly in POSTMAN.
  • There are multiple services, the simplest one where I do not pass anything in BODY(POSTMAN) works fine in POSTMAN and ABAP, but for other service where I need to pass body also do not work in ABAP. So I think no certificate related issue. Also SMICM do not shows any error.
  • One thing I observed is, if I pass fields using set_form_field, it is not visible in SMICM trace, all other fields that I send using set_header_data are visible in SMICM trace.
  • You are correct, I think I need to check with service provider and see what they are getting from my side to find exact cause.

Sequence I am calling is,

  1. CALL METHOD lo_http_client->request->set_method( 'POST' ).
  2. CALL METHOD lo_http_client->request->set_header_field
  3. CALL METHOD lo_http_client->request->set_form_field