<?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>Question Re: Calling PATCH API method returns 400 error? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/12639692#M4741544</link>
    <description>&lt;P&gt;Hi, Simone,&lt;/P&gt;&lt;P&gt;Do you have any solution? I have the same problem.&lt;/P&gt;&lt;P&gt;Thank you so much&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Marisa&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2023 12:43:43 GMT</pubDate>
    <dc:creator>Marisa3</dc:creator>
    <dc:date>2023-10-26T12:43:43Z</dc:date>
    <item>
      <title>Calling PATCH API method returns 400 error?</title>
      <link>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaq-p/12639691</link>
      <description>&lt;P&gt;I'm trying to call a SAP ARIBA API using the PATCH method within a S4 HANA ABAP system, but I always get the 400 code with an error message stating :"contentTypeIncorrect".&lt;BR /&gt;The SAP ARIBA API documentation gives a very clear example in ABAP, where it is clear that it should work.&lt;/P&gt;
  &lt;P&gt;******&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;DATA: lo_http_client TYPE REF TO if_http_client.
DATA: response TYPE string.

"create HTTP client by url
"API endpoint for API sandbox 
CALL METHOD cl_http_client=&amp;gt;create_by_url
  EXPORTING
    url                = 'https://sandbox.api.sap.com/ariba/api/approval/v2/sandbox/{approvableType}/{approvableId}'

  IMPORTING
    client             = lo_http_client
  EXCEPTIONS
    argument_not_found = 1
    plugin_not_active  = 2
    internal_error     = 3
    OTHERS             = 4.

IF sy-subrc &amp;lt;&amp;gt; 0.
  "error handling
ENDIF.

"setting request method
lo_http_client-&amp;gt;request-&amp;gt;set_method('PATCH').

"adding headers
"API Key for API Sandbox
lo_http_client-&amp;gt;request-&amp;gt;set_header_field( name = 'APIKey' value = 'jZROiOY0vaQrVnAAUGiA6vhGC6SyPPhh' ).
lo_http_client-&amp;gt;request-&amp;gt;set_header_field( name = 'DataServiceVersion' value = '2.0' ).
lo_http_client-&amp;gt;request-&amp;gt;set_header_field( name = 'Accept' value = 'application/json' ).
lo_http_client-&amp;gt;request-&amp;gt;set_header_field( name = 'Content-Type' value = 'application/json' ).


CALL METHOD lo_http_client-&amp;gt;request-&amp;gt;set_cdata
  EXPORTING
    data = '{\n   "state": "approve",\n   "comment": {\n      "text": "string",\n      "visibleToSupplier": true\n   }\n}'.

CALL METHOD lo_http_client-&amp;gt;send
  EXCEPTIONS
    http_communication_failure = 1
    http_invalid_state         = 2
    http_processing_failed     = 3
    http_invalid_timeout       = 4
    OTHERS                     = 5.

IF sy-subrc = 0.
  CALL METHOD lo_http_client-&amp;gt;receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3
      OTHERS                     = 5.
ENDIF.

IF sy-subrc &amp;lt;&amp;gt; 0.
  "error handling
ENDIF.

response = lo_http_client-&amp;gt;response-&amp;gt;get_cdata( ).

WRITE: 'response: ', response.

&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;{ "error": { "code": "contentTypeIncorrect", "message": "Content-Type supported is 'application/json'" } }I tried to use Postam to test the service and I don't get the same error &lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;Have you faced the problem or do you have any suggestions?&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;Simone&lt;/P&gt;
  &lt;P&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;BR /&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 15:58:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaq-p/12639691</guid>
      <dc:creator>simone_decato216</dc:creator>
      <dc:date>2022-11-18T15:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PATCH API method returns 400 error?</title>
      <link>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/12639692#M4741544</link>
      <description>&lt;P&gt;Hi, Simone,&lt;/P&gt;&lt;P&gt;Do you have any solution? I have the same problem.&lt;/P&gt;&lt;P&gt;Thank you so much&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Marisa&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2023 12:43:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/12639692#M4741544</guid>
      <dc:creator>Marisa3</dc:creator>
      <dc:date>2023-10-26T12:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PATCH API method returns 400 error?</title>
      <link>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/12639693#M4741545</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;Do you have any solution now? I have the same problem.&lt;/P&gt;&lt;P&gt;Thank you much&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Bernhard&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 18:16:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/12639693#M4741545</guid>
      <dc:creator>bsonntag1968</dc:creator>
      <dc:date>2023-12-12T18:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PATCH API method returns 400 error?</title>
      <link>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/14030347#M4905248</link>
      <description>Hi, Have you got any solution for this ?</description>
      <pubDate>Fri, 28 Feb 2025 09:45:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/14030347#M4905248</guid>
      <dc:creator>Nilesh_Pandey</dc:creator>
      <dc:date>2025-02-28T09:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PATCH API method returns 400 error?</title>
      <link>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/14096770#M4913348</link>
      <description>yes,</description>
      <pubDate>Thu, 08 May 2025 23:47:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/14096770#M4913348</guid>
      <dc:creator>giovanniklein1</dc:creator>
      <dc:date>2025-05-08T23:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PATCH API method returns 400 error?</title>
      <link>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/14096771#M4913349</link>
      <description>&lt;P&gt;Yes, it is necessary to change the abap code call to a lower level:&lt;/P&gt;&lt;P&gt;l_http_client=&amp;gt;create_by_url(&lt;BR /&gt;EXPORTING url = lv_url&lt;BR /&gt;IMPORTING client = lo_http&lt;BR /&gt;).&lt;/P&gt;&lt;P&gt;lo_http-&amp;gt;request-&amp;gt;set_method( 'PATCH' ).&lt;BR /&gt;lo_http-&amp;gt;request-&amp;gt;set_header_field( name = '~request_method' value = 'PATCH' ).&lt;BR /&gt;lo_http-&amp;gt;request-&amp;gt;set_header_field( name = 'Content-Type' value = 'application/json' ).&lt;BR /&gt;lo_http-&amp;gt;request-&amp;gt;set_header_field( name = 'APIKey' value = gc_api_key_attach ).&lt;BR /&gt;lo_http-&amp;gt;request-&amp;gt;set_header_field( name = 'Authorization' value = |Bearer { lv_token }| ).&lt;/P&gt;&lt;P&gt;DATA: lv_body_xstr TYPE xstring.&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'SCMS_STRING_TO_XSTRING'&lt;BR /&gt;EXPORTING&lt;BR /&gt;text = lv_body&lt;BR /&gt;mimetype = 'application/json'&lt;BR /&gt;IMPORTING&lt;BR /&gt;buffer = lv_body_xstr.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;" Insert payload directly&lt;BR /&gt;CALL METHOD lo_http-&amp;gt;request-&amp;gt;set_data&lt;BR /&gt;EXPORTING&lt;BR /&gt;data = lv_body_xstr&lt;BR /&gt;offset = 0&lt;BR /&gt;length = xstrlen( lv_body_xstr ).&lt;/P&gt;&lt;P&gt;"Send the request&lt;BR /&gt;CALL METHOD lo_http-&amp;gt;send.&lt;BR /&gt;CALL METHOD lo_http-&amp;gt;receive.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;CALL METHOD lo_http-&amp;gt;response-&amp;gt;get_status&lt;BR /&gt;IMPORTING&lt;BR /&gt;code = lv_status.&lt;BR /&gt;lv_error_text = lo_http-&amp;gt;response-&amp;gt;get_cdata( ).&lt;/P&gt;&lt;P&gt;IF lv_status = 200.&lt;BR /&gt;ls_log-ariba_status = lv_sap_stat.&lt;BR /&gt;ELSE.&lt;BR /&gt;ls_log-log_msg = |HTTP { lv_status }: { lv_error_text }|.&lt;BR /&gt;ENDIF.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 23:49:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/14096771#M4913349</guid>
      <dc:creator>giovanniklein1</dc:creator>
      <dc:date>2025-05-08T23:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calling PATCH API method returns 400 error?</title>
      <link>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/14096772#M4913350</link>
      <description>yes, it is necessary to change the abap code call to a lower level: l_http_client=&amp;gt;create_by_url( EXPORTING url = lv_url IMPORTING client = lo_http ). lo_http-&amp;gt;request-&amp;gt;set_method( 'PATCH' ). lo_http-&amp;gt;request-&amp;gt;set_header_field( name = '~request_method' value = 'PATCH' ). lo_http-&amp;gt;request-&amp;gt;set_header_field( name = 'Content-Type' value = 'application/json' ). lo_http-&amp;gt;request-&amp;gt;set_header_field( name = 'APIKey' value = gc_api_key_attach ). lo_http-&amp;gt;request-&amp;gt;set_header_field( name = 'Authorization' value = |Bearer { lv_token }| ). DATA: lv_body_xstr TYPE xstring. CALL FUNCTION 'SCMS_STRING_TO_XSTRING' EXPORTING text = lv_body mimetype = 'application/json' IMPORTING buffer = lv_body_xstr. " Insert payload directly CALL METHOD lo_http-&amp;gt;request-&amp;gt;set_data EXPORTING data = lv_body_xstr offset = 0 length = xstrlen( lv_body_xstr ). "Send the request CALL METHOD lo_http-&amp;gt;send. CALL METHOD lo_http-&amp;gt;receive. CALL METHOD lo_http-&amp;gt;response-&amp;gt;get_status IMPORTING code = lv_status. lv_error_text = lo_http-&amp;gt;response-&amp;gt;get_cdata( ). IF lv_status = 200. ls_log-ariba_status = lv_sap_stat. ELSE. ls_log-log_msg = |HTTP { lv_status }: { lv_error_text }|. ENDIF. ENDIF.</description>
      <pubDate>Thu, 08 May 2025 23:49:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/calling-patch-api-method-returns-400-error/qaa-p/14096772#M4913350</guid>
      <dc:creator>giovanniklein1</dc:creator>
      <dc:date>2025-05-08T23:49:59Z</dc:date>
    </item>
  </channel>
</rss>

