We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Scripted REST API POST how to retrieve the response?

LucaP5957190930
Mega Sage

Goodmorning,

I've created a scripted REST API with a post function to let a third party create a kind of incident, I whould like to log messages (inbound and outbound) into a custom table so I need to retrieve the response that we send to the third party. I can get my request's body because of I create it with the StreamWriter, but I whould like to get even the header created with the response.setStatus() and response.setContentType() : ex.

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 04 Aug 2015 15:20:44 GMT
Server: ServiceNow
Connection: close
Set-Cookie: BIGipServerpool_<Instance>=880838154.47166.0000; path=/

{"result":{"id":1234,"id1":5678,"name":"user0","name1":"user1"}}

Is there any way to do that?

Best regards

Luca

5 REPLIES 5

Hi Luca,



Instead of using getStreamWriter(). YOu can pass the ris(the output you have set in your code) to the response using response.setBody(ris);


find_real_file.png



and the resultd response will be:


find_real_file.png