VoidZero
VoidZero

Reputation: 550

How to set a session id in Postman

I need to hit a post request to an API service which requires a session id along with other parameters in its post request field in order to get the required information.

I am using Postman to test this API.

I would like to know how to send a 'session id' in a post request when using Postman?

I am aware of pre-request script in Postman, but I am unaware of how to use the variable in post request.

Upvotes: 31

Views: 99030

Answers (6)

user2858738
user2858738

Reputation: 550

In Postman native app:

  1. Turn on the Interceptor
  2. Go to Headers
  3. Fill-in a header entry with
    1. Key: Cookie
    2. Value: sessionid=omuxrmt33mnetsfirxi2sdsfh4j1c2kv

Upvotes: 23

Ujash Patel
Ujash Patel

Reputation: 19

SessionId can be set as a global variable. Select "Tests" Tab, then use the code below.

if (postman.getResponseHeader("authorization") !== null) {
    postman.setGlobalVariable("token","Bearer " + postman.getResponseHeader("authorization") );
}

Upvotes: 0

valdefreaks
valdefreaks

Reputation: 81

On your browser:

  • Open the developer tools (right click and Inspect).
  • Go to Application Tab > Storage > Cookies.
  • Open your site Cookie and copy the Name and Value.

In Postman 8+:

  • In your Request tab, go to Headers.
  • Click in the eye icon to see the hidden headers.
  • Click in the "Cookie" link that is in the top right corner.
  • In the "Manage Cookies" popup, select your domain, click on "+Add" button, or edit the existent cookie.
  • Paste the values that you copy from the browser. The complete value will look like PHPSESSID=f20nbdor26v9r1k5hdfj6tji0p; Path=/;
  • Click on "Save", and close the popup.

enter image description here

Upvotes: 5

James Ikubi
James Ikubi

Reputation: 2948

Hit inspect on the site you are working on, when logged in

  1. On your Chrome/browser, go to application - cookies.
  2. Copy your PHPSESSID.
  3. On postman headers Key: Cookie
  4. Value: PHPSESSID=dsdjshvbjvsdh (your key)

Upvotes: 8

makkasi
makkasi

Reputation: 7318

For standalone Postman app

You can use global variables in postman. First in the Tests tab of the first request set the session as global variable:

var a = pm.cookies.get('session');
pm.globals.set("session", a);

It might be 'session_id' as well (check in the headers of your first request) instead of session. To check if this variable is set, after you do your first request, go to the gear icon and click on globals. Then go to your second request -> Headers and for key add 'Cookie' while for value add 'session={{session}}'

Side note: be careful not to save keys that are used by your framework or they might be deleted for some reason.

Upvotes: 4

user1368695
user1368695

Reputation: 154

This post is bit old but I want to still answer incase someone else is looking for an answer.

First, you need to see if intercepter is enabled in the toolbar, it is present one step away from sign-in

If does not not get enabled when you click on it, you can install extension. I think there is one for Chrome. Go ahead and add the extension.

After that you can go back to Postman and enable intercepter

You will be able to see cookies in postman and at this point you can add _session_id

I hope this will help.

Thanks,

Upvotes: 13

Related Questions