how can i get user session id outside of the servicenow instance using rest api.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2018 04:41 AM
I have developed custom application using C# windows application. And i have using my servicenow developer instance rest api url to retrieve rest request and response from servicenow instance. And i actually using basic authentication to retrieve rest response in my custom application. How can i get session id from servicenow instance to my custom application.
For example: My Instance https://dev.service-now.com/ My Rest api url is: https://dev.service-now.com/api/now/table/{tableName}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 01:37 PM
hi Sakthival,
I am confused, i thought u are developing a custom C# windows application which using basic authentication to retrieve rest response in my custom application.
which i presume u already have access to ServiceNow rest api? are u trying to get your program own session id? or u are trying to get other user session id?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2018 11:06 PM
Hi Bryan Tay,
Sorry for this confusion.
I have get session id in my developer instance(istanbul version).
For example in script:
1.First i add script include sections in my developer instance:
i.e:
var GetSessionID = Class.create();
GetSessionID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
sessionID: function() {
var session=gs.getSessionID();
var token=gs.getSessionToken();
var userName=gs.getUserName();
return "The Server Says Hello " + this.getParameter('sysparm_user_name') + "!"+"\nSession Id= "+session+"\nSession Token= "+token+"\nUser Name= "+userName;
}
});
2. Second i have add this script method to my sys_user table onload():
i.e
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('GetSessionID');
ga.addParam('sysparm_name','sessionID');
ga.addParam('sysparm_user_name',"sakthivel");
ga.getXMLWait();
alert(ga.getAnswer());
}
Result is:
This script is working fine in my developer instance only. How can i get my custom application like c# windows application.
Like i have using Http listener url to send that session id to my custom applications. Is there possible way to get this session id.
Please tell me to can i add this script or any other script to my custom applications for get this value.
Thanks for advance.
Sakthivel.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2018 03:03 PM
hi Sakthival,
firstly, in your dev example, you already logon to the servicenow instance and when u navigate to the user form, it trigger onload client script which trigger the ajax server script. This works cause u already logon to the instance and your current session has a session id.
In your response,
1. "https listener url" is to receive request. Who trigger this https call? Is this a Servicenow listener u are talking about? or your custom C# program? or a physical user?
2. "send that session id to my custom applications", so in this instance ur cusom C# program is expecting a session id? who initiate the C# program call?
3. "Is there possible way to get this session id.", which session id? the one ur user is logging on? or initiator from point 1 and 2 above?
4. "Please tell me to can i add this script or any other script to my custom applications for get this value." I dont get what you want...
perhaps u can elaborate more on the whole picture,
e.g.
I have a custom C# application, when it runs, it trigger a REST API Call to Servicenow to get my connection session id. once response with my session id, the custom C# application continue to perform it operations...
OR
1. Whole initiate the entire process?
2. What C# application do?
3. What role/function is ServiceNow?
4. Expected output for the entire process?
Hope this help again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2019 04:28 AM
Hello all,
I have the session id and user id of the user. I want to create a scripted API which will take input as session id and user and it will check it in logged in user table if the session id or user exist in return it should give me the complete details of the user from user table.
I am struggling with the script, Request you all to help me out on this it is a critical requirement.
Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2019 07:29 PM
Again, this is a very old thread, I'd recommend opening a new thread to post this for better responses.