on 2022 Nov 18 3:58 PM
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".
The SAP ARIBA API documentation gives a very clear example in ABAP, where it is clear that it should work.
******
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=>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 <> 0.
"error handling
ENDIF.
"setting request method
lo_http_client->request->set_method('PATCH').
"adding headers
"API Key for API Sandbox
lo_http_client->request->set_header_field( name = 'APIKey' value = 'jZROiOY0vaQrVnAAUGiA6vhGC6SyPPhh' ).
lo_http_client->request->set_header_field( name = 'DataServiceVersion' value = '2.0' ).
lo_http_client->request->set_header_field( name = 'Accept' value = 'application/json' ).
lo_http_client->request->set_header_field( name = 'Content-Type' value = 'application/json' ).
CALL METHOD lo_http_client->request->set_cdata
EXPORTING
data = '{\n "state": "approve",\n "comment": {\n "text": "string",\n "visibleToSupplier": true\n }\n}'.
CALL METHOD lo_http_client->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->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 5.
ENDIF.
IF sy-subrc <> 0.
"error handling
ENDIF.
response = lo_http_client->response->get_cdata( ).
WRITE: 'response: ', response.
{ "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
Have you faced the problem or do you have any suggestions?
Thank you
Simone
Request clarification before answering.
Hi, Simone,
Do you have any solution? I have the same problem.
Thank you so much
Regards,
Marisa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
69 | |
21 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.