<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Import URL data (http://requestb.in) into SAP using HTTP connection in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/import-url-data-http-requestb-in-into-sap-using-http-connection/m-p/348276#M6688</link>
    <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;I have requirement to get the response from External Gatewayapi which is built in PHP and JSON(http://requestb.in,which is like webhook).&lt;/P&gt;&lt;P&gt;Have created test webhook which stores the response from the Gateway at RAW BODY(see picture) &lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/19312-requestbin.png" /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Now we have to import data into SAP. Have written sample code which gets data. Find the code and the data received.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;call method cl_http_client=&amp;gt;create_by_url
 EXPORTING
 url = gV_URL
 IMPORTING
 client = http_client
 EXCEPTIONS
 others = 1.*system will use this Header Field to submit a Request to 3rd party’s API server
*after which we’ll receive the Response transmitted back to our Application Server.call method http_client-&amp;gt;request-&amp;gt;set_header_field
 EXPORTING
 name = '~request_method'
 value = 'GET'.*Structure of HTTP Connection and Dispatch of Data
call method http_client-&amp;gt;send
 EXCEPTIONS
 http_communication_failure = 1
 http_invalid_state = 2.
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 DISPLAY LIKE SY-MSGTY.
 exit.
ENDIF.
* 5 - Get the result back
*get the Response back from the API servercall method http_client-&amp;gt;receive
 EXCEPTIONS
 http_communication_failure = 1
 http_invalid_state = 2
 http_processing_failed = 3.
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 DISPLAY LIKE SY-MSGTY.
 exit.
ENDIF.
Data :lv_code type i,
 xml_string TYPE Xstring.
data:lv_reason type string.
data: xml_table type xml_line_structure occurs 0 with header line.
data: xreturn type bapiret2_t with header line.
*
http_client-&amp;gt;response-&amp;gt;get_status( IMPORTING code = lv_code reason = lv_reason ).
*
xml_string = http_client-&amp;gt;response-&amp;gt;get_data( ).
CALL FUNCTION 'SMUM_XML_PARSE'
 EXPORTING
 XML_INPUT = xml_string
 TABLES
 XML_TABLE = xml_table
 RETURN = xreturn

page_content = http_client-&amp;gt;response-&amp;gt;get_data( ).
CALL FUNCTION 'LXE_COMMON_XSTRING_TO_TABLE'
  EXPORTING
    IN_XSTRING = page_content
  IMPORTING
    PSTATUS    = lv_status
  TABLES
    EX_TAB     = LT_EX_TAB&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Data Received in internal table &lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/19314-data.png" /&gt;&lt;/P&gt;&lt;P&gt;After converting data from AScii to Char&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/19319-charformat.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;!DOCTYPE html&amp;gt;#&amp;lt;html&amp;gt;#  &amp;lt;head&amp;gt;#    &amp;lt;title&amp;gt;RequestBin - ym1r3cym&amp;lt;/title&amp;gt;#    &amp;lt;link rel="shortcut icon" href="data:image/gif;base64,R0lGODlhEAAQAIAAAKC0yAAAACH5BAQAAAAALAAAAAAQABAAAAIOhI+py+0Po5y02ouzPgUAOw==" /&amp;gt;#    &amp;lt;link href="https://answers.sap.com/static/css/bootstrap.css"&lt;/P&gt;&lt;P&gt;Not sure what data is it.Need inputs to proceed further at earliest.&lt;/P&gt;&lt;P&gt;Any code snippets,approach or suggestion would be helpful. &lt;/P&gt;</description>
    <pubDate>Wed, 08 Feb 2017 10:04:23 GMT</pubDate>
    <dc:creator>former_member361845</dc:creator>
    <dc:date>2017-02-08T10:04:23Z</dc:date>
    <item>
      <title>Import URL data (http://requestb.in) into SAP using HTTP connection</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/import-url-data-http-requestb-in-into-sap-using-http-connection/m-p/348276#M6688</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;I have requirement to get the response from External Gatewayapi which is built in PHP and JSON(http://requestb.in,which is like webhook).&lt;/P&gt;&lt;P&gt;Have created test webhook which stores the response from the Gateway at RAW BODY(see picture) &lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/19312-requestbin.png" /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Now we have to import data into SAP. Have written sample code which gets data. Find the code and the data received.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE&gt;call method cl_http_client=&amp;gt;create_by_url
 EXPORTING
 url = gV_URL
 IMPORTING
 client = http_client
 EXCEPTIONS
 others = 1.*system will use this Header Field to submit a Request to 3rd party’s API server
*after which we’ll receive the Response transmitted back to our Application Server.call method http_client-&amp;gt;request-&amp;gt;set_header_field
 EXPORTING
 name = '~request_method'
 value = 'GET'.*Structure of HTTP Connection and Dispatch of Data
call method http_client-&amp;gt;send
 EXCEPTIONS
 http_communication_failure = 1
 http_invalid_state = 2.
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 DISPLAY LIKE SY-MSGTY.
 exit.
ENDIF.
* 5 - Get the result back
*get the Response back from the API servercall method http_client-&amp;gt;receive
 EXCEPTIONS
 http_communication_failure = 1
 http_invalid_state = 2
 http_processing_failed = 3.
IF SY-SUBRC &amp;lt;&amp;gt; 0.
 MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 DISPLAY LIKE SY-MSGTY.
 exit.
ENDIF.
Data :lv_code type i,
 xml_string TYPE Xstring.
data:lv_reason type string.
data: xml_table type xml_line_structure occurs 0 with header line.
data: xreturn type bapiret2_t with header line.
*
http_client-&amp;gt;response-&amp;gt;get_status( IMPORTING code = lv_code reason = lv_reason ).
*
xml_string = http_client-&amp;gt;response-&amp;gt;get_data( ).
CALL FUNCTION 'SMUM_XML_PARSE'
 EXPORTING
 XML_INPUT = xml_string
 TABLES
 XML_TABLE = xml_table
 RETURN = xreturn

page_content = http_client-&amp;gt;response-&amp;gt;get_data( ).
CALL FUNCTION 'LXE_COMMON_XSTRING_TO_TABLE'
  EXPORTING
    IN_XSTRING = page_content
  IMPORTING
    PSTATUS    = lv_status
  TABLES
    EX_TAB     = LT_EX_TAB&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Data Received in internal table &lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/19314-data.png" /&gt;&lt;/P&gt;&lt;P&gt;After converting data from AScii to Char&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/19319-charformat.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;!DOCTYPE html&amp;gt;#&amp;lt;html&amp;gt;#  &amp;lt;head&amp;gt;#    &amp;lt;title&amp;gt;RequestBin - ym1r3cym&amp;lt;/title&amp;gt;#    &amp;lt;link rel="shortcut icon" href="data:image/gif;base64,R0lGODlhEAAQAIAAAKC0yAAAACH5BAQAAAAALAAAAAAQABAAAAIOhI+py+0Po5y02ouzPgUAOw==" /&amp;gt;#    &amp;lt;link href="https://answers.sap.com/static/css/bootstrap.css"&lt;/P&gt;&lt;P&gt;Not sure what data is it.Need inputs to proceed further at earliest.&lt;/P&gt;&lt;P&gt;Any code snippets,approach or suggestion would be helpful. &lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 10:04:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/import-url-data-http-requestb-in-into-sap-using-http-connection/m-p/348276#M6688</guid>
      <dc:creator>former_member361845</dc:creator>
      <dc:date>2017-02-08T10:04:23Z</dc:date>
    </item>
  </channel>
</rss>

