Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Invalid request body error when sending json string as data to an external api using CL_HTTP_CLIENT.

rahulpippalla
Participant
0 Likes
7,304

Hi Every one,

We are facing an issue while sending json data to an external api using CL_HTTP_CLIENT.
The JSON data is produced using '/ui2/cl_json=>serialize( data = ls_body compress = abap_true pretty_name = /ui2/cl_json=>pretty_mode-camel_case )' .

when sending this JSON as data the the external api returns status 400 with response as
{ "errorCode": "INVALID_REQUEST_BODY", "message": "The request body is missing or improperly formatted. Unexpected character encountered while parsing value: \u001f. Path '', line 0, position 0." } .

we also stringyfied this JSON Data in backend as it might be due to parsing error but it didnt work.
The same stringyfied data tried to send through browser console using ajax and it did worked without any issue.

could any any one tell us how to handle this json object and send this to external api using CL_HTTP_CLIENT.
Note : JSON STRING is deeply nested .

Thanks in advance..

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
4,833

Solved here by the OP: "The issue was with the unicodes in the string. these were not accepted by the external api so removed from the string and sent to api and it did worked."

Solved here by the OP: "The issue was with the unicodes in the string. these were not accepted by the external api so removed from the string and sent to api and it did worked."

8 REPLIES 8
Read only

MateuszAdamus
Active Contributor
4,833

Hello rahulpippalla

I think it might be of help if you provide the code you're using to send the JSON.

Kind regards,
Mateusz
Read only

Sandra_Rossi
Active Contributor
4,833

Why do you send the character \u001f (U+001F) in the body? Use ICM trace (SMICM) to get the exact message sent.

Read only

rahulpippalla
Participant
0 Likes
4,833

Hello @mateuszadamusIts just a json data which was created from internal table thats all.
one thing is that it contains base64 content as well in it.

thanks and regards,
Rahul

Read only

rahulpippalla
Participant
0 Likes
4,833

Hello @sandra.rossi ,

we didnt add ani unicodes to it. The same data which was sent from abap was downloaded and sent from the postman and it did worked.
we did checked in smicm and were unable to trace. could you please tell what can we do there..?

Thanks and regards,

Rahul.

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
4,833
Few ideas:
  • What exactly are you doing with the string after serialization?
  • Go into debugger and right after serialization open the JSON string, download it to file and check the file for this strange character \u001f in some better text editor. If it is there then check where exactly. It might be from some user input values (often users just copy&paste data from various sources like web, Word docs. etc. with "strange" and "invisible" characters and input these data into SAP, then the problem happens when you try to pass these data to different systems).
  • You can also try some "JSON validators" on-line (but these might not find that unicode characters as invalid).
  • Check if you do not have some very old version of /ui2/cl_json (Documentation + versions and SAP notes are here https://wiki.scn.sap.com/wiki/display/Snippets/One+more+ABAP+to+JSON+Serializer+and+Deserializer )
-- Tomas --
Read only

Sandra_Rossi
Active Contributor
0 Likes
4,833

You "didn't add any Unicode" but anyway the fact is that there's one (or the log is buggy). Sorry about the ICM trace, it's in fact the ICF client recorder in transaction code SICF, see there: https://blogs.sap.com/2006/04/05/icf-recording-a-possibility-for-analysing/

Read only

Sandra_Rossi
Active Contributor
4,834

Solved here by the OP: "The issue was with the unicodes in the string. these were not accepted by the external api so removed from the string and sent to api and it did worked."

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
4,833

That is what I thought 🙂 Thanks for updating

-- Tomas --