Skip to Content
avatar image
Former Member

how to call http get api in abap

Dear All.

As I make new program interfacing with http API, 500 error code is occurring.

Calling API via IE is just like this

It's working well :

https://api.mgage.solutions/servxml/XML_parse_API.php?data=%3CMESSAGE%20VER=%221.2%22%3E%3CUSER%20USERNAME=%22USERID%22%20PASSWORD=%22PASSWORD%22%20DLR=%220%22/%3E%3CSMS%20TEXT=%22This%20is%20first%20sms%22%20ID=%221%22%20CUST_MID=%22customer-reference-uniqueid-20011234567890%22%20MTAG=%22unique_message_tag_1%22%3E%3CADDRESS%20FROM=%22MGAGE%22%20TO=%22+9188269466%22%20SEQ=%221%22/%3E%3C/SMS%3E%3CSMS%20TEXT=%22This%20is%20second%20sms%22%20ID=%222%22%20CUST_MID=%22customer-reference-uniqueid-20011234567891%22%20MTAG=%22unique_message_tag_2%22%3E%3CADDRESS%20FROM=%22MGAGE%22%20TO=%22+9188269466%22%20SEQ=%221%22/%3E%3C/SMS%3E%3C/MESSAGE%3E

But in abap program, I got 500 error,

Would you please what's problem in my source ??

source code 1)

CALL METHOD cl_http_client=>create_by_destination
  EXPORTING
    destination           = 'MGAGE_BULK'
  IMPORTING
    client                = lo_client
  EXCEPTIONS
    destination_not_found = 1
    internal_error        = 2.


request = lo_client->request.


CALL METHOD lo_client->request->set_method(
  if_http_request=>co_request_method_post ).


CONCATENATE
'<MESSAGE VER="1.2">'
'<USER USERNAME="*****"' 'PASSWORD="*****" DLR="0"/>'
'<SMS TEXT="This is first sms" ID="1" CUST_MID="customer-reference-uniqueid-20011234567890" MTAG="unique_message_tag_1">'
'<ADDRESS FROM="MGAGE" TO="+918826466" SEQ="1"/>'
'</SMS>'
'<SMS TEXT="This is second sms" ID="2" CUST_MID="customer-reference-uniqueid-20011234567891" MTAG="unique_message_tag_2">'
'<ADDRESS FROM="MGAGE" TO="+91882466" SEQ="1"/>'
'</SMS>'
'</MESSAGE>'
INTO lv_bodystr.


name = 'data'.
value = lv_bodystr.
CALL METHOD request->set_form_field
  EXPORTING
    name  = name
    value = value.


CALL METHOD lo_client->send
  EXCEPTIONS
    http_communication_failure = 1
    OTHERS                     = 4.


IF sy-subrc EQ 0.
  lo_client->receive(
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4 ).


  lo_client->response->get_status( IMPORTING  code = lv_http_code
                                      reason = lv_reason ).


  lv_cdata = lo_client->response->get_cdata( ).

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Dec 27, 2017 at 10:19 AM

    Hi Kyoungmi,

    As you are attempting to consume an HTTPS service, you will first need to configure the security certificate in tcode STRUST (under SSL-client Anonymous). You can see and download the certificate by clicking on the lock icon next to the URL in Internet Explorer. Simply download and import it in your SAP system. Assuming that everything else is configured correctly, this should solved the issue.

    Additionally, check for a more detailed message in tcode SMICM.


    BR,

    Tudor

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi, Tudor

      We already set up certificate for this URL.

      What I want to know is whether calling API via abap is correct or not.

      It not, what's problem on it.

      Thanks in advance.

      BR.KM

  • Dec 27, 2017 at 09:43 PM

    Isn't the HTTP error code 500 an "application error" (i.e. which occurs in the called system), so don't you get another message in the variable lv_cdata?

    As said by Tudor, use SMICM to trace the request sent + errors (eventually increase the trace level too).

    Maybe, you should call the following method, because you use special characters < and > which should be passed with values %3C and %3E (AKA "URL encoding"):

    request->SET_FORMFIELD_ENCODING( request->CO_FORMFIELD_ENCODING_ENCODED ).
    
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 28, 2017 at 03:17 AM

    In sm59 test..here's result.

    This page can’t be displayed

    • Make sure the web address saphtmlp://htmlviewer.sap.com is correct.
    • Look for the page with your search engine.
    • Refresh the page in a few minutes.
    Add comment
    10|10000 characters needed characters exceeded

    • So, in fact your question is all about the configuration of SM59 RFC destination. Unfortunately you don't give any information about your config. You may also get some information in SMICM (Internet Communication Manager) HTTP trace, as we already said.