<?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: API post with body in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639906#M2014154</link>
    <description>&lt;P&gt;Sandra, it's the first time I work with APIs, sorry if I use the words correctly. &lt;/P&gt;</description>
    <pubDate>Wed, 18 May 2022 11:58:35 GMT</pubDate>
    <dc:creator>maria_merino</dc:creator>
    <dc:date>2022-05-18T11:58:35Z</dc:date>
    <item>
      <title>API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639898#M2014146</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;
  &lt;P&gt;I'm new working with APIs. I've been asked to use an API for pay by link.&lt;/P&gt;
  &lt;P&gt;This is how it looks the API on postman:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2048885-adyen.png" /&gt;&lt;/P&gt;
  &lt;P&gt;And this is how my report looks:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;REPORT  zzmaria.

TYPES: BEGIN OF ty_json_req,
         reference        TYPE string,
         value            TYPE string,
         currency         TYPE string,
         countrycode      TYPE string,
         merchantaccount  TYPE string,
         shopperreference TYPE string,
         shopperemail     TYPE string,
         shopperlocale    TYPE string,
         key              TYPE string,
       END OF ty_json_req.

DATA: l_datos TYPE ty_json_req,
      t_datos TYPE STANDARD TABLE OF ty_json_req.
DATA gs_json TYPE string.
*HTTP Client Abstraction
DATA: lo_client    TYPE REF TO if_http_client.


DATA : lo_http_client TYPE REF TO if_http_client,
       lv_response    TYPE string,
       lv_sap_res     TYPE string.
DATA : l_str_length     TYPE i.
DATA : mime      TYPE w3mimetabtype.
DATA : lo_http_request TYPE REF TO if_http_entity.

START-OF-SELECTION.


*Data variables for storing response in xstring and string
  DATA  : lv_xstring   TYPE xstring,
          lv_string    TYPE string,
          lv_body    TYPE string,
          lv_node_name TYPE string.

  CLEAR : lv_xstring, lv_string, lv_node_name.

  DATA  : lv_cdata     TYPE string.
  DATA  : lv_content_length_value TYPE i.

  CLEAR : lv_cdata, lv_content_length_value, gs_json.

*Pass the URL to get Data
  lv_string = 'https://XXXXXXXXXXXXXX/paymentLinks'.


*Creation of New IF_lo_http_client Object
  cl_http_client=&amp;gt;create_by_url(
  EXPORTING
    url                = lv_string
  IMPORTING
    client             = lo_http_client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    ).

  IF sy-subrc IS NOT INITIAL.
* Handle errors
  ENDIF.

*lv_body = '{"reference": "FVM1", "amount": {"value": 125, "currency": "EUR"  }, "countryCode": "ES", "merchantAccount": "XXXXXX", "shopperReference": "1234567890", "shopperEmail": "xxxxxx@xxxx.com",' &amp;amp;&amp;amp;
*          '"shopperLocale": "es-ES", "metadata": {"key": "R0C060"}}'.
  l_datos-reference = 'FVM1'.
  l_datos-value = '125'.
  l_datos-currency = 'EUR'.
  l_datos-countrycode = 'ES'.
  l_datos-merchantaccount = 'xxxxxxxx'.
  l_datos-shopperreference = '1234567890'.
  l_datos-shopperemail = 'xxxxx@xxxx.com'.
  l_datos-shopperlocale = 'es-ES'.
  l_datos-key = 'R0C060'.

  /ui2/cl_json=&amp;gt;serialize(
    EXPORTING
      data        =  l_datos   " Data to serialize
    RECEIVING
      r_json      =   gs_json  " JSON string
  ).

  PERFORM json_naming.

  lo_http_client-&amp;gt;propertytype_logon_popup = lo_http_client-&amp;gt;co_disabled.

*set http method POST

  CALL METHOD lo_http_client-&amp;gt;request-&amp;gt;set_method(
    if_http_request=&amp;gt;co_request_method_post ).

*set protocol version
  lo_http_client-&amp;gt;request-&amp;gt;set_version( if_http_request=&amp;gt;co_protocol_version_1_0 ).

  CALL METHOD lo_http_client-&amp;gt;request-&amp;gt;if_http_entity~set_formfield_encoding
    EXPORTING
      formfield_encoding = cl_http_request=&amp;gt;if_http_entity~co_encoding_raw.

*content type
  CALL METHOD lo_http_client-&amp;gt;request-&amp;gt;if_http_entity~set_content_type
    EXPORTING
      content_type = if_rest_media_type=&amp;gt;gc_appl_json.

  CALL METHOD lo_http_client-&amp;gt;request-&amp;gt;set_header_field
    EXPORTING
      name  = 'x-api-key:'
      value = 'FSSGDGdgdgdghd'.


*get data
  CLEAR : lv_sap_res, lv_response.
  lo_http_request = lo_http_client-&amp;gt;request.

**append data
*lo_http_client-&amp;gt;request-&amp;gt;set_cdata( EXPORTING data = lv_body ).

  lo_http_request-&amp;gt;append_cdata( data = gs_json ).

  CALL METHOD lo_http_client-&amp;gt;send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.

  CALL METHOD lo_http_client-&amp;gt;receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 4.


*response
  DATA(lo_res) = lo_http_client-&amp;gt;response.
  lv_response = lo_http_client-&amp;gt;response-&amp;gt;get_cdata( ).
  WRITE : lv_response.

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  JSON_NAMING
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --&amp;gt;  p1        text
*  &amp;lt;--  p2        text
*----------------------------------------------------------------------*
FORM json_naming .

  REPLACE ALL OCCURRENCES OF 'REFERENCE' IN gs_json WITH 'reference'.
  REPLACE ALL OCCURRENCES OF 'VALUE' IN gs_json WITH 'amount.value'.
  REPLACE ALL OCCURRENCES OF 'CURRENCY' IN gs_json WITH 'amount.currency'.
  REPLACE ALL OCCURRENCES OF 'COUNTRYCODE' IN gs_json WITH 'countryCode'.
  REPLACE ALL OCCURRENCES OF 'MERCHANTACCOUNT' IN gs_json WITH 'merchantAccount'.
  REPLACE ALL OCCURRENCES OF 'SHOPPERreference' IN gs_json WITH 'shopperReference'.
  REPLACE ALL OCCURRENCES OF 'SHOPPEREMAIL' IN gs_json WITH 'shopperEmail'.
  REPLACE ALL OCCURRENCES OF 'SHOPPERLOCALE' IN gs_json WITH 'shopperLocale'.
  REPLACE ALL OCCURRENCES OF 'KEY' IN gs_json WITH 'metadata.key'.

ENDFORM.
&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I get an error with the body. I don't know how to use it.&lt;/P&gt;
  &lt;P&gt;this is the error:&lt;/P&gt;
  &lt;P&gt;{"status":400,"errorCode":"702","message":"Structure of CreatePaymentLinkRequest contains the following unknown fields: [amount.currency, metadata.key, amount.value]","errorType":"validation"}&lt;/P&gt;
  &lt;P&gt;Thanks in advance.&lt;/P&gt;
  &lt;P&gt;Maria&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 08:27:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639898#M2014146</guid>
      <dc:creator>maria_merino</dc:creator>
      <dc:date>2022-05-18T08:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639899#M2014147</link>
      <description>&lt;P&gt;If you say there is an error, give information about the error, where it happens, what are the exact details of this error, etc.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 09:27:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639899#M2014147</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-05-18T09:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639900#M2014148</link>
      <description>&lt;P&gt;You're right Sandra, I've edited the question.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 10:25:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639900#M2014148</guid>
      <dc:creator>maria_merino</dc:creator>
      <dc:date>2022-05-18T10:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639901#M2014149</link>
      <description>&lt;P&gt;Given that your API call works in Postman, you have to use the proper nesting level in ABAP typing to be able to generate the proper JSON format:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES BEGIN OF ty_json_req.
...
TYPES BEGIN OF amount.
TYPES value TYPE string.
TYPES currency TYPE string.
TYPES END OF amount.
....
TYPES END OF ty_json_req.&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And you should use the following serialization parameter to get lower-case results, as it is much cleaner and safer then a post-correction:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;pretty_name  = /ui2/cl_json=&amp;gt;pretty_mode-camel_case&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If you name an ABAP component e.g. shopper_reference it should translate to shopperReference in JSON&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 11:01:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639901#M2014149</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2022-05-18T11:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639902#M2014150</link>
      <description>&lt;P&gt;Okay, at last line of code, LV_RESPONSE contains JSON data (that you have posted) which contains the error.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 11:12:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639902#M2014150</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-05-18T11:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639903#M2014151</link>
      <description>&lt;P&gt;Your question should be different.&lt;/P&gt;&lt;P&gt;Your issue is that you don't find a way to initialize GS_JSON same as in PostMan.&lt;/P&gt;&lt;P&gt;So, your question is about how to use /UI2/CL_JSON. It's not related to "API post with body".&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 11:14:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639903#M2014151</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-05-18T11:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639904#M2014152</link>
      <description>&lt;P&gt;Thanks Gábor, problem solved !!! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;How can I retrieve one of the fields from LV_RESPONSE?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;{"amount":{"currency":"EUR","value":125},"countryCode":"ES","expiresAt":"2022-05-19T11:41:15Z","merchantAccount":"XXXXX","metadata":{"key":"R0C060"},"reference":"FVM1","reusable":false,"shopperEmail":"XXXX@XXX.com","shopperLocale":"es-ES","shopperReference":"1234567890","id":"PL3E7Bsdfs025BBF3","status":"active","url":"https:\/\/test.adyen.linkRRRRR"}  &lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need the URL.&lt;/P&gt;&lt;P&gt;thanks !!&lt;/P&gt;&lt;P&gt;Maria&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 11:45:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639904#M2014152</guid>
      <dc:creator>maria_merino</dc:creator>
      <dc:date>2022-05-18T11:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639905#M2014153</link>
      <description>&lt;P&gt; &lt;SPAN class="mention-scrubbed"&gt;mariamerino&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;Its the same story in the opposite direction. &lt;/P&gt;&lt;P&gt;Create an ABAP structure with fields that corresponds to the structure of the response and use method DESERIALIZE. &lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 11:55:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639905#M2014153</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2022-05-18T11:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639906#M2014154</link>
      <description>&lt;P&gt;Sandra, it's the first time I work with APIs, sorry if I use the words correctly. &lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 11:58:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639906#M2014154</guid>
      <dc:creator>maria_merino</dc:creator>
      <dc:date>2022-05-18T11:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: API post with body</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639907#M2014155</link>
      <description>&lt;P&gt;I'll try it!! Thanks!!&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 11:58:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/api-post-with-body/m-p/12639907#M2014155</guid>
      <dc:creator>maria_merino</dc:creator>
      <dc:date>2022-05-18T11:58:53Z</dc:date>
    </item>
  </channel>
</rss>

