<?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 Re: Calling REST API Get Method from SAP ABAP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-rest-api-get-method-from-sap-abap/m-p/834908#M43779</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It's possible that you have the following problems:&lt;/P&gt;&lt;P&gt;- Certificate error: You try to connect to https using ABAP client, it's possible that you need to create a destination with SM59 and then add ssl certificate transaction STRUST.&lt;/P&gt;&lt;P&gt;- API error: Could you call with browser and provide the error message?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Enric Castella&lt;/P&gt;</description>
    <pubDate>Fri, 18 Jan 2019 20:35:53 GMT</pubDate>
    <dc:creator>enric101</dc:creator>
    <dc:date>2019-01-18T20:35:53Z</dc:date>
    <item>
      <title>Calling REST API Get Method from SAP ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-rest-api-get-method-from-sap-abap/m-p/834907#M43778</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
  &lt;P&gt;I am trying to call a REST API Get method from a Function module in SAP to convert Lat Long to Zip codes but getting error as Failure to connect to Endpoint. Please look at the below code and response to provide your inputs.&lt;/P&gt;
  &lt;P&gt;G_SERVICE: &lt;A href="https://services-dev.XXXX.com/BingMapsREST/REST/v1/Locations/X,Y" target="test_blank"&gt;https://services-dev.XXXX.com/BingMapsREST/REST/v1/Locations/X,Y&lt;/A&gt;&lt;/P&gt;
  &lt;P&gt;where X &amp;amp; Y are Location Coordinates&lt;/P&gt;
  &lt;P&gt;Create HTTP intance using RFC destination created&lt;BR /&gt; * You can directly use the REST service URL as well&lt;BR /&gt; cl_http_client=&amp;gt;create_by_url(&lt;BR /&gt; EXPORTING&lt;BR /&gt; url = g_service&lt;BR /&gt; IMPORTING&lt;BR /&gt; client = g_ref_http_client&lt;BR /&gt; EXCEPTIONS&lt;BR /&gt; argument_not_found = 1&lt;BR /&gt; plugin_not_active = 2&lt;BR /&gt; internal_error = 3&lt;BR /&gt; OTHERS = 4 ).&lt;BR /&gt;&lt;BR /&gt; * If you are using cl_http_client=&amp;gt;create_by_url use this code to supress and pass your&lt;BR /&gt; * HTTP basic authenication&lt;BR /&gt; g_ref_http_client-&amp;gt;propertytype_logon_popup = g_ref_http_client-&amp;gt;co_disabled.&lt;BR /&gt; &lt;BR /&gt; * Create REST client instance&lt;BR /&gt; CREATE OBJECT g_ref_rest_client&lt;BR /&gt; EXPORTING&lt;BR /&gt; io_http_client = g_ref_http_client.&lt;BR /&gt; * Set HTTP version&lt;BR /&gt; g_ref_http_client-&amp;gt;request-&amp;gt;set_version( if_http_request=&amp;gt;co_protocol_version_1_0 ).&lt;BR /&gt; &lt;BR /&gt; IF g_ref_http_client IS BOUND AND g_ref_rest_client IS BOUND.&lt;BR /&gt; g_urltest = g_service.&lt;BR /&gt; * Set the URI if any&lt;BR /&gt; cl_http_utility=&amp;gt;set_request_uri(&lt;BR /&gt; EXPORTING&lt;BR /&gt; request = g_ref_http_client-&amp;gt;request " HTTP Framework (iHTTP) HTTP Request&lt;BR /&gt; uri = g_urltest ). " URI String (in the Form of /path?query-string)&lt;BR /&gt; ENDIF.&lt;BR /&gt; &lt;BR /&gt; * Set Payload or body ( JSON or XML)&lt;BR /&gt; g_ref_request = g_ref_rest_client-&amp;gt;if_rest_client~create_request_entity( ).&lt;BR /&gt; g_ref_request-&amp;gt;set_content_type( iv_media_type = if_rest_media_type=&amp;gt;gc_appl_json ).&lt;BR /&gt; * g_ref_request-&amp;gt;set_string_data( lv_body ).&lt;BR /&gt; &lt;BR /&gt; DATA: lt_fields TYPE tihttpnvp,&lt;BR /&gt; ls_fields TYPE ihttpnvp.&lt;BR /&gt; &lt;BR /&gt; ls_fields-name = if_http_header_fields_sap=&amp;gt;request_uri.&lt;BR /&gt; ls_fields-value = g_urltest.&lt;BR /&gt; APPEND ls_fields TO lt_fields.&lt;BR /&gt; &lt;BR /&gt; CALL METHOD g_ref_rest_client-&amp;gt;if_rest_client~set_request_headers&lt;BR /&gt; EXPORTING&lt;BR /&gt; it_header_fields = lt_fields.&lt;BR /&gt; &lt;BR /&gt; TRY.&lt;BR /&gt; * g_ref_rest_client-&amp;gt;if_rest_resource~options( ).&lt;BR /&gt; g_ref_rest_client-&amp;gt;if_rest_resource~get( ).&lt;BR /&gt; &lt;BR /&gt; CATCH cx_root INTO g_ref_exception.&lt;BR /&gt; wa_errtab-type = c_e.&lt;BR /&gt; wa_errtab-id = c_id. "ZPM_TNA&lt;BR /&gt; wa_errtab-message = g_ref_exception-&amp;gt;get_text( ).&lt;BR /&gt; ENDTRY.&lt;BR /&gt; &lt;/P&gt;
  &lt;P&gt;OPTION 1:&lt;BR /&gt; CLEAR g_response .&lt;BR /&gt; g_response = g_ref_http_client-&amp;gt;response-&amp;gt;get_cdata( ).&lt;BR /&gt; &lt;/P&gt;
  &lt;P&gt;OPTION 2:&lt;/P&gt;
  &lt;P&gt;g_ref_response = g_ref_rest_client-&amp;gt;if_rest_client~get_response_entity( ).&lt;BR /&gt;g_response = g_ref_response-&amp;gt;get_string_data( ).&lt;BR /&gt; &lt;BR /&gt; * "Close the call&lt;BR /&gt; CALL METHOD g_ref_http_client-&amp;gt;close&lt;BR /&gt; EXCEPTIONS&lt;BR /&gt; http_invalid_state = 1&lt;BR /&gt; OTHERS = 2.&lt;/P&gt;
  &lt;P&gt;Response:&lt;/P&gt;
  &lt;P&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt; -&amp;lt;env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"&amp;gt; &amp;lt;env:Header&amp;gt; &amp;lt;/env:Header&amp;gt; -&amp;lt;env:Body&amp;gt; -&amp;lt;env:Fault&amp;gt; -&amp;lt;env:Code&amp;gt; &amp;lt;env:Value&amp;gt;env:Receiver &amp;lt;/env:Value&amp;gt; -&amp;lt;env:Subcode&amp;gt; &amp;lt;env:Value xmlns:fault="http://tempuri.org/soapfaults"&amp;gt;fault:MessageBlocked &amp;lt;/env:Value&amp;gt; &amp;lt;/env:Subcode&amp;gt; &amp;lt;/env:Code&amp;gt; -&amp;lt;env:Reason&amp;gt; &amp;lt;env:Text xml:lang="en"&amp;gt;Failure connecting to endpoint: &lt;A href="http://dev.YYY.nethttps://services-dev.XXXX.com/REST/V1/Locations/39.0637395,-94.7483701?key=AAABBBCCCEEEEDDDD" target="test_blank"&gt;http://dev.YYY.nethttps://services-dev.XXXX.com/REST/V1/Locations/39.0637395,-94.7483701?key=AAABBBCCCEEEEDDDD&lt;/A&gt; &amp;lt;/env:Text&amp;gt; &amp;lt;/env:Reason&amp;gt; &amp;lt;env:Detail xmlns:fault="http://tempuri.org/soapfaults" fault:type="faultDetails"&amp;gt; &amp;lt;/env:Detail&amp;gt; &amp;lt;/env:Fault&amp;gt; &amp;lt;/env:Body&amp;gt; &amp;lt;/env:Envelope&amp;gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 20:03:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-rest-api-get-method-from-sap-abap/m-p/834907#M43778</guid>
      <dc:creator>lakshmanjk</dc:creator>
      <dc:date>2019-01-18T20:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calling REST API Get Method from SAP ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-rest-api-get-method-from-sap-abap/m-p/834908#M43779</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It's possible that you have the following problems:&lt;/P&gt;&lt;P&gt;- Certificate error: You try to connect to https using ABAP client, it's possible that you need to create a destination with SM59 and then add ssl certificate transaction STRUST.&lt;/P&gt;&lt;P&gt;- API error: Could you call with browser and provide the error message?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Enric Castella&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 20:35:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-rest-api-get-method-from-sap-abap/m-p/834908#M43779</guid>
      <dc:creator>enric101</dc:creator>
      <dc:date>2019-01-18T20:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calling REST API Get Method from SAP ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/calling-rest-api-get-method-from-sap-abap/m-p/834909#M43780</link>
      <description>&lt;P&gt;Hi Enric,&lt;/P&gt;&lt;P&gt;Thanks for your response. Actually with the browser, we are getting error 'Access Denied' as the service works only based on authentication approved by end system. I will try to create a new RFC destination with SM59 and make a call to see if it works. &lt;/P&gt;&lt;P&gt;I would like to know why the endpoint URL is being prefixed and the actual key is suffixed with the actual URL &lt;A href="https://services-dev.xxxx.com/BingMapsREST/REST/v1/Locations/X,Y"&gt;https://services-dev.XXXX.com/BingMapsREST/REST/v1/Locations/X,Y&lt;/A&gt; to give the error as 'Failure to connect to Endpoint'&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 21:47:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/calling-rest-api-get-method-from-sap-abap/m-p/834909#M43780</guid>
      <dc:creator>lakshmanjk</dc:creator>
      <dc:date>2019-01-18T21:47:07Z</dc:date>
    </item>
  </channel>
</rss>

