I am calling third party API via HTTPPOST2 using ampscript, and need response body for response codes like 4xx or 5xx. For success scenario, I am getting the response body in response parameter of HTTPPOST2 request. Please find below my code for the same:
Below is the output for the same-
code: 400 response : ï¿½ï¿½ï¿½Tï¿½ï¿½ï¿½ F_ï¿½Ü¹1ï¿½ï¿½0ï¿½1R0ï¿½ï¿½[Cï¿½ï¿½Sntjï¿½î¢›ï¿½9ï¿½ï¿½fï¿½Q@ï¿½ï¿½ï¿½Qï¿½^ï¿½ï¿½ï¿½Eoï¿½ï¿½sï¿½ï¿½ï¿½ï¿½7Fï¿½ï¿½;M1ï¿½ï¿½|ï¿½2ï¿½ï¿½/Sï¿½nï¿½0%Jï¿½g4ï¿½Wï¿½ï¿½ï¿½2ï¿½jï¿½ï¿½gï¿½ï¿½Nï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Z(&ï¿½5ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½kï¿½ responseRows: System.Data.DataRow responseRowCount: 7
I am not sure why the response is corrupted in case of 4xx or 5xx response while trying with HTTPPOST2 using amp script where as for success scenario it worked perfectly fine.
Also, have tried with HTTP.POST method via SSJS as well but it seems we cannot read status code and response in case of HTTP.POST. Salesforce just throw back a generic message in case of 400:bad request and unable to read response body as well.
Below is the error we got in case of 400: bad request and reponse body is coming null. description: "
ExactTarget.OMM.FunctionExecutionException: An error occurred when attempting to evaluate a HTTPPost function call. See inner exception for details.
↵ Error Code: OMM_FUNC_EXEC_ERROR ↵ - from Jint --> ↵ ↵ --- inner exception 1--- ↵ ↵System.Net.WebException: The remote server returned an error: (400) Bad Request. - from System ↵ ↵ ↵ ↵"
Looking forward for help on this issue.