cancel
Showing results for 
Search instead for 
Did you mean: 

CPI - HTTP Receiver Adapter for REST API - json payload error

laurentdoyen
Discoverer

Hi community experts,

Looking for advice to resolve an issue while executing a POST to an external REST API. The payload is simple and is in JSON format.

I am using the HTTP receiver adapter and have tried several configurations, for example with POST method and Dynamic method (with Send Body flag ticked). All attempts result in a HTTP 403 error. I can see in the monitor that the payload appears to be passed correctly to the Receiver adapter. For example an extract of the payload looks like this:

{"interview":{"title":"Test1","due_date":"2019-12-06T10:10:10Z", ...... }}

However the receiving 3rd party system indicates their logs shows the following type of payload with escape characters:

{"{\n \interview\": {\n \"title\": \"Test1\",\n \"due_date\": \"2019-12-06T10:10:10Z\",\n ..... }}

However when testing the same source JSON payload in a test tool such as Postman (POST to 3rd party API URL) the result is a success response (200 OK).

It appears the CPI HTTP receiver adapter seems to transform the payload by adding escape characters. How can I avoid that behaviour and how can I track what is happening? The CPI message monitor (with Trace enabled) does not provide enough details. It shows the payload before the error but no detail on what the adapter sends to the API.

It is also worth noting that GET requests from CPI to the same external REST API (different endpoint but same host) is successful. Obviously the difference is that GET does not include a payload body.

Any input would be appreciated.

Thanks.

Laurent

Accepted Solutions (0)

Answers (4)

Answers (4)

0 Kudos

Hi Laurent,

if your issue still not solved, read this Blog: https://blogs.sap.com/?p=896320

I believe you might have a similar Issue where CPI adds Linux line endings, while Postman adds Windows line endings.

Regards

Saraj

ankit12
Active Participant
0 Kudos

Hi Laurent,

I hope you already solved the issue till now... if not then you can follow the below approch to track request:

1. make sure you are using chrome then in developer tools(by pressing F12) you can check the request payload to ensure JSON request is as server expected.

2.in same developer tools window go to the network tabs.. and you will find all the request and response header details regarding the request and response from the server. by using this, you will have clear visibility about request and response header.

3. while making the request payload you can also use console.log() function to print your request to the console of developer tools.(if you are using Web IDE)

Hope this helps.

Regards,

Ankit Gupta

laurentdoyen
Discoverer
0 Kudos

Thanks Bala.

Yes using the exact same userid in Postman and CPI. And also using the same sample test json payload as input.

The receiving 3rd party has advised me that there is no authentication/authorisation issue on their end. What they notice in their logs however is that they receive a badly formatted message as my exemple shows in my first message. JSON message with escaped line breaks (\n) and escaped double quotes (\").

As I said I see in the CPI message monitoring that the JSON Body is well formatted just before the HTTP receiver adapter. I cannot see what is sent by the adapter but the receiver system receives an escaped message.

No idea how to troubleshoot that and the issue may be.

Regards,

Laurent

bhalchandraswcg
Contributor
0 Kudos

Hi laurentdoyen,

CPI posts the payload as it is without escaping it.

HTTP Code 403 suggests that target server is not authorizing the request. Is the user used in Postman same as that used in CPI?

Hope this helps,

Bala