cancel
Showing results for 
Search instead for 
Did you mean: 

API-Post Method-Unsupported Media Type - SAP ABAP

former_member576008
Active Participant
0 Kudos

Hi

I am consuming an external API Post method to send PO information from our ECC system on release 731, SP14.

We are able to send Po data in Json format without any issues until we found an issue. Here content type is set to "application/problem+json; charset=utf-8".

Issue is, few material descriptions has special character (non breaking space) because of that receiver is not able to receive our data and their .NET system is rejecting that.

Even though I am able to fix it, we have other fields in the Po data where special characters can appear. Ex - Vendor name, address.

To over come that, we decided to send the data in Base64 encoded format and content type set to "text/plain".

But when I push the data, I am getting error 415 - Unsupported media type.

Initially when i was using "application/json" i faced the same issue but later after adding the addition it worked - "application/problem+json; charset=utf-8".

Similarly for "text/plain" also i am facing issue but not sure what is the addition i need to use. I have tried "text/plain; charset=utf-8" but its not working.

Any suggestions, please let me know.

Sandra_Rossi
Active Contributor
0 Kudos

It would be more simple if we discuss of just one problem at a time, so I propose to talk about the first one:

  • "content type is set to "application/problem+json; charset=utf-8". Issue is, few material descriptions has special character (non breaking space) because of that receiver is not able to receive our data and their .NET system is rejecting that."

Please indicate the error text, how you encode in UTF-8, etc.

former_member576008
Active Participant
0 Kudos

Thanks for your reply.

I haven't encoded anything in UTF-8. Fetched the material description to an internal table and converted that internal table to Json structure. I was not able to send until i set the content type to application/problem+json; charset=utf-8.

Because of the special character they want json data in base64 encoded format and expecting in text/plain format. From my side i changed the content type to text/plain from application/problem+json; charset=utf-8 but getting 415-unsupported media type and I am looking for solution/suggestion for this issue.

DATA: l_base64 TYPE string,
           v_or_request_acct        TYPE REF TO if_rest_entity,
           v_or_rest_client_acct   TYPE REF TO cl_rest_http_client.


        v_or_request_acct->set_content_type( iv_media_type = 'text/plain' ).        

***l_post_data is a string type and has json format data        
        l_base64 = cl_http_utility=>encode_base64( l_post_data ).
        v_or_client_acct->request->set_cdata( l_base64 ).
        l_con_len = v_or_request_acct->get_content_length( ).
        v_or_request_acct->set_header_field( iv_name = if_http_header_fields=>content_length
                                             iv_value = l_con_len ).

        CALL METHOD v_or_client_acct->send
          EXCEPTIONS
            http_communication_failure = 1
            http_invalid_state         = 2
            http_processing_failed     = 3
            http_invalid_timeout       = 4
            OTHERS                     = 5.

        CALL METHOD v_or_client_acct->receive
          EXCEPTIONS
            http_communication_failure = 1
            http_invalid_state         = 2
            http_processing_failed     = 3
            OTHERS                     = 4.

        CALL METHOD v_or_client_acct->response->get_status
          IMPORTING
            code   = v_httpcode
            reason = v_reason.
Sandra_Rossi
Active Contributor

You use set_cdata, so you don't need to bother with encoding, probably it's sent in UTF-8 implicitly. You don't need to set the Content-Length, it's set automatically by the kernel. I'm surprised that you need to indicate the "charset=utf-8" when you use "application/problem+json" as I think it's set by the kernel too because you used set_cdata.

The non-breaking space is a valid Unicode character, so there shouldn't be any problem, UTF-8 will encode it without any issue.

You may activate the ICF Client Recorder to make sure what is sent from your SAP system.

NB: you're using an old version (7.31), maybe there are some bugs somewhere, if possible check the SAP notes.

Sandra_Rossi
Active Contributor
0 Kudos

I'm not sure what you exactly ask. Are you still open to using UTF-8, or anyway you go for Base64 and the Content-Type. Also, I don't get what sends the error 415 unsupported media type, is it SAP or .NET, and how do you know?

former_member576008
Active Participant
0 Kudos
I have been waiting for some reply. Thanks for coming back.
"You use set_cdata, so you don't need to bother with encoding, probably it's sent in UTF-8 implicitly. You don't need to set the Content-Length, it's set automatically by the kernel."
  • Ok, I will remove the length related code.

" I'm surprised that you need to indicate the "charset=utf-8" when you use "application/problem+json" as I think it's set by the kernel too because you used set_cdata."

  • Yes, I was not able to send data using "application/json" after adding the "Problem+" addition I am able to send the Json data. Later this also failed because of special character and we decided to go with base64 encoding.

The issue I wan to fix is, I need to send the Json encoded in Base64 format, with content type text/plain but getting below 415-Unsupported media type. When I checked with the Vendor they said- they didnt write any code like this and its the .NET core sending the message.

  {"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13",
 "title":"Unsupported Media Type",
 "status":415,
 "traceId":"00-542de72a5aa174210ed }

So after analysis we found that material description - non breaking space is causing issue and we decided go with text/plain and base64 encoding. I am getting the 415-unsupported media type message from below method

        CALL METHOD v_or_client_acct->response->get_status
          IMPORTING
            code   = v_httpcode--------->415
            reason = v_reason.---------->Unsupported Media type

    v_response = v_or_client_acct->response->get_cdata( ).-------> Above pasted error message with type, titlt, status and trace id.

I don't have authorization to check the ICF recorder will take Basis help to check that.

Thank you !!

Sandra_Rossi
Active Contributor
0 Kudos

I'm not surprised that the .NET library rejects the request, I saw similar issues for security reason, but I'm surprised that text/plain is rejected as it's a classic content type.

I advise to test directly the Web service with software like Postman (there's a free version), to make sure what are the possible formats. It's possible to pass special characters like non-breaking space.

former_member576008
Active Participant
0 Kudos

Yes, I have tested the Post method from Postman and it works fine with content type text/plain.

Working with my Basis team to check the ICF Recorder, will let you know if there is any findings.

former_member576008
Active Participant
0 Kudos

Hi Sandra,

I reached out to my Basis to activate the ICF client recorder but they are asking me the path from SICF.

I am consuming an external api dont have SICF path. Any help or tips to guide them ?

Sandra_Rossi
Active Contributor

Good news for Postman. I guess you can solve the issue then, and you don't need the ICF Client Recorder.

You're right for SICF. Don't be confused by the two different ICF recorders: there are the ICF Client Recorder and the ICF Server Recorder. I guess the Basis team doesn't know how SICF works. The "client recorder" = outbound HTTP calls = means that you are recording HTTP calls made by ABAP programs to the Web, so you don't need to select a "path from SICF". The question they ask is probably to know the URL in the SAP system, this is needed only for the "server recorder" = inbound HTTP calls = calls from external programs which call Web Services defined in the SAP system.

xiswanto
Active Participant
0 Kudos

Hello,

I am having similar issue, but instead, I am consuming SAP API in external system. When i tried to test service in SICF on path /sap/bc/srt/wsdl or the service created from soamanager in SICF tcode, i get the error 415 - Unsupported media type.

When I used the ICF recorder, the response is

HTTP/1.1 415 Unsupported Media Type
Set-Cookie: sap-recorder_sid=%2cc%3dGDE%25-C0A8B708511C6405AA32159F00000000%25-%25-1%2co%3dgwdev_GDE_10%25-110%25-ABAP01; path=/; domain=glicowings.local
Content-Type: text/html
Content-Length: 0
the wsdl binding url for created webservice itself is no issue when opened in browser. I also tried the service definition from se80 and it works fine within SAP internally.Any suggestion would be welcomed
Sandra_Rossi
Active Contributor
0 Kudos

xiswanto It's a generic message which says that the media type (Content-Type) you are sending is simply not the right one. Obviously, the question is what content type does your Web service expects, and what content type do you send?

View Entire Topic
pedrohb
Active Participant
0 Kudos

The error 415 - Unsupported Media Type occurs when the server is unable to process the media type of the data sent by the client. In your case, it seems that the server is not able to process the "text/plain" content type that you are sending.

One possible reason for this error could be that the server is expecting a specific media type, such as "application/json" or "application/xml", and is not configured to handle "text/plain". You may need to check the API documentation or contact the API provider to confirm the supported media types.

Another possible reason could be that the content of the data being sent is not properly formatted for the selected media type. In your case, if you are sending Base64-encoded data in "text/plain" format, you may need to ensure that the data is properly encoded and formatted for the media type.

You could also try specifying the character set as part of the media type, such as "text/plain; charset=utf-8", to see if that resolves the issue. If that doesn't work, you may need to try a different media type that is supported by the server.

Lastly, it's worth noting that some APIs may have strict requirements for the format and encoding of data being sent, so you may need to ensure that your data conforms to those requirements.