How to see the response headers in REST message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 11:33 AM
I'm currently creating REST Messages using in ServiceNow to make API calls an outside server using their API resource. I'm having issues retrieving and storing a non standard header generated by the server's API. Using the RESTLet client chrome extension, I'm able to see the token necessary in the response header. I'm unsure how to do the same in ServiceNow.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 02:03 PM
Have you tried using restmessagev2's getRequestHeaders() method or are you doing it another way?
RESTMessageV2 - Scoped, Global
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 05:11 AM
Originally no I didn't use the restmessagev2's getRequestHeaders() method. I was trying to pass the token in the HTTP Header under the HTTP requests under the get method. Even when using the restmessagev2's getRequestHeaders() method no success. I'm very new to serviceNow and have only been developing on the platform for almost two weeks. I'm using these REST messages I create to run from a workflow for new a catalog service item. Like i said using the RESTlet client from the chrome store I'm able to see exactly what I need and how to pass the token. Just unsure of how to do it in ServiceNow.
This is making the first call to generate the response header necessary.
The needed token is the X-RestSvcSessionId.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2021 11:50 AM
Hi,
This is an old post but hope my reply could be helpful.
In order to get the Response headers in ServiceNow you can use the function - getAllHeaders()
Sample syntax:
var r = new sn_ws.RESTMessageV2('RESTMESSAGE NAME', 'get');
var response = r.execute();
var headers = res.getAllHeaders(); // returns all headers present in the response
for(var i in headers)
{
gs.log(headers[i].name + ': ' + headers[i].value);
}
To get specific header use - getHeader(String name)
Example
var sm = new sn_ws.RESTMessageV2("RESTMESSAGE NAME","get");
var response = sm.execute();
var headerVal = response.getHeader("Content-Type");