Get rid of the "result" node from Rest API Response

BP6
Tera Contributor

I have the same question as this one https://community.servicenow.com/community?id=community_question&sys_id=058e4b21dbdcdbc01dcaf3231f96...

It's been 6 years since that was posted and I wanted to know if there's an easier way to remove the "result" wrapper from responses now than for me to build out response objects for each and every type of request I send to a third party service.

 

1 REPLY 1

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi BP,

Try following script.

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    response.setHeader('Content-Type', 'application/json');
    var resultObj = {
        "text": "Hello world!"
    };

    writer = response.getStreamWriter();
    writer.writeString(JSON.stringify(resultObj));
})(request, response);

Result

find_real_file.png