how can i get user session id outside of the servicenow instance using rest api.

sakthivel639
Kilo Contributor

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}

9 REPLIES 9

Bryan Tay3
Mega Guru

hi Sakthival,



Have u try using rest api querying table v_user_session?


this table should give u your loggon session id.



Hope this helps.


Hi Bryan,


I tried to getting session from v_user_session table that's ok. But i want to get session id from my custom application to make continues rest request.


And i already using this v_user_session table to get user session. For is there any custom script file is available in servicenow instance.



Thanks


sakthivel


hi Sakthival,



in your custom application, once you initiate your first connection to the server via rest api call, your session had been stored at v_user_session table.


if u need the session_id, query the v_user_session table to retrieve it as the first rest call and then store the session id for the subsequent call.



i use poweshell as an example:


find_real_file.png


Hope this helps.


Hi Bryan Tay,



Thanks for your reply. Its very helpful for me.
Is there any possible to get session id without using username and password. When user log on to servicenow instance. We have only developer instance login url and rest api url only that time how can we retrieve user session id without using credentials for make subsequent rest/soap request.




Thanks for advance.


Sakthivel.