We are having an integration with an external REST API which we are invoking from a SSJS script hosted on a cloudpage. We have tried couple of ways to invoke the API Call - Script.Util.HttpRequest & Platform.Function.HTTPPost. In both cases when the external system returns a HTTP 200 code then the script is able to extract the JSON response data and process it. But when the external system returns any of these HTTP codes - 400, 403, 409, 410, then an exception gets raised and the control is transferred to catch section of the script. Inside the catch section we are unable to retrieve the response JSON data and the http code etc. All that we get is the SFMC internal exception that gets raised.
We were able to confirm this via invoking the same API via SOAP UI and here we are clearly able to see the different HTTP codes and the corresponding response JSON data.
As an example, below is the response received in SOAP UI for a particular data we send to the external system:
HTTP/1.1 409 Conflict Content-Type: application/json Content-Length: 73 Connection: keep-alive Date: Thu, 22 Aug 2019 06:00:05 GMT Cache-Control: no-store, no-cache X-Content-Type-Options: nosniff Strict-Transport-Security: max-age=15768000 X-Download-Options: noopen X-XSS-Protection: 1; mode=block X-FRAME-OPTIONS: DENY X-Cache: Error from cloudfront Via: 1.1 2ca402c5412abcdc27e682e2b326bdbb.cloudfront.net (CloudFront) X-Amz-Cf-Pop: CDG3 X-Amz-Cf-Id: qB5AQNvHh7dqpe8HQbA6x0xc2kFOq5Tbj79IJvPOfFUEZQbpYM9hpg==
{"errorCode":"409.1","message":"You have already claimed this game code"}
Whereas the same data sent via the SSJS call returns this generic error message:
{"message":"An error occurred when attempting to evaluate a Util.HttpRequest call. See inner exception for details.\r\n URL: https://XXXXXXXXXXXXXXX/ext/v1/okta/prize/award\r\n Method: POST\r\n ClientID: 6235576\r\n JobID: 0\r\n ListID: 0\r\n BatchID: 0\r\n SubscriberID: 0\r\n","description":"ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a Util.HttpRequest call. See inner exception for details.\r\n URL: https://XXXXXXXXXXXXXXX/ext/v1/okta/prize/award\r\n Method: POST\r\n ClientID: 6235576\r\n JobID: 0\r\n ListID: 0\r\n BatchID: 0\r\n SubscriberID: 0\r\n Error Code: OMM_FUNC_EXEC_ERROR\r\n - from Jint --> \r\n\r\n --- inner exception 1---\r\n\r\nSystem.Net.WebException: The remote server returned an error: (409) Conflict. - from System\r\n\r\n\r\n\r\n"}
Can you please advise how we can retrieve the HTTP code and the JSON response data that is received, inside the SSJS script ?
Any inputs or suggestions would be highly appreciated.
TIA.
Keddy