Artificial Intelligence Forum
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

HTTP 415 error while calling classify records

achowdhury
Explorer
0 Likes
1,122

Tutorials: https://developers.sap.com/tutorials/cp-aibus-dar-model.html
--------------------------
I am trying to programmatically call the POST method in "Classify Records" > 001. Send inference request. However, I am always getting the http 415 error even when I set the header fields as 'Content-Type' as 'application/json'

Within POSTMAN the content-type is 'application/json' then why is the same not accepted programmatically ?

Code:

  DATA: lo_rest_client TYPE REF TO cl_rest_http_client,<br>
          lo_request     TYPE REF TO if_http_entity.<br>
<br>
    CREATE OBJECT lo_rest_client<br>
      EXPORTING<br>
        io_http_client = lo_host_client. 

   lo_host_client->request->set_method( if_http_request=>co_request_method_post ). 

    lo_request = lo_host_client->request->if_http_entity~add_multipart( ).<br>
<br>
<br>
    lo_request->set_header_field(<br>
      name  = 'Content-Type'<br>
      value = if_rest_media_type=>gc_appl_json ).<br>
<br>
<br>
    lo_request->set_cdata(<br>
    EXPORTING:<br>
          data = lv_json_query_structure ).<br>
<br>
    CALL METHOD lo_host_client->send( ).<br>
<br>  <br>
    CALL METHOD lo_host_client->receive( ).<br><br>
    CALL METHOD lo_host_client->response->get_status<br>
      IMPORTING<br>
        code = DATA(lv_status_code_host).
SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}.L0S31 {
font-style: italic;
color: #808080;
}.L0S33 {
color: #4DA619;
}.L0S52 {
color: #0000FF;
}.L0S55 {
color: #800080;
}.L0S70 {
color: #808080;
}

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; }.L0S55 { color: #800080; }.L0S70 { color: #808080; }

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }

Error message:

{"status": 415, "message": "The server does not support the media type transmitted in the request.", "X-Correlation-ID": "7f4ee61c-363e-4a66-7437-cfa77a4759d6"}

1 REPLY 1
Read only

achowdhury
Explorer
0 Likes
971

This turned out to be a header issue, used the content-type = 'application/json' and the api call worked fine.