How to Share Session ID across Different Requests in Postman?


We can share session id across different requests in Postman. We can send a cookie value obtained from a request to a different request. This can be done only if the website is similar.

A particular server can identify its own cookie. This makes a cookie highly secured. The cookies are passed to another request to store the information of the user preferences as it navigates through the webpages.

A session id is similar to an expiration of a token. As the session id gets expired, an user has to again authenticate his credentials. As a user logs in for the first time to a website with his valid details, a unique session id is created, shared with the client and stored in the browser.

For every following request, the browser passes this session id and the request for the user authentication. If the session id matches, the user is redirected to the webpage he is looking for. After logout, the session id is demolished from both the server and client sides.

Step1 − Enter the URL − https://www.amazon.com/ in the address bar and send a GET request.

Step2 − In the Response, click on Cookies and record the session-id value as marked in the below image.

Step3 − Store the session-id value in a variable and set it as a Global variable using the script below within the Tests tab.

var c = pm.cookies.get('session-id')

pm.globals.set('session ID', c)

Step4 − Global variable - session ID will be displayed on clicking the eye icon to the right upper corner.

Step5 − Input the other URL − https://www.amazon.in/your-account

Step6 − Incorporate the Global variable session ID with its value in form of a key-value pair within the Headers tab under the address bar. The key is Cookie and the value should be in the format {{session ID}}. If we do a mouseover on the {{session ID}}, it shall display the SCOPE as Global and the CURRENT value which is the same as the value obtained in Step4.

Updated on: 25-Jun-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements