Need to get/set cookie parameters in REST message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2018 02:40 PM
Hi All,
I am getting the session id within the cookies when I tested the REST API in postman tool. I have configured the REST messages in ServiceNow and calling them from a scheduled script. I need to pass the session id from one request to the subsequent requests. Can anyone please let me know how this can be done using the script.
Thanks in Advance.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2018 03:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2018 06:33 PM
Hi Mike,
I tried that, but not getting any response.
See my code below.
var cookies = responseBody.getCookies();
var i;
for(i=0;i<cookies.size();i++) {
gs.print(‘cookie: ‘ + cookies.get(i));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2019 07:16 AM
Hi Neha,
You find Cookie outside response.
try:
var cookies = response.getCookies();
for( var i=0; i < cookies.size(); i++ ){
gs.log('cookie: ' + cookies.get(i));
}
(Use all response instead of only responseBody).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2019 01:51 PM
Hi Neha
Did it work? I am trying to get the Cookie token from SOAP-WSDL and pass it to REST call for authentication. It is a 2 step process too, hence wondering how it worked for you.
Thanks!