Reputation: 550
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
Reputation: 550
In Postman native app:
Cookie
sessionid=omuxrmt33mnetsfirxi2sdsfh4j1c2kv
Upvotes: 23
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
Reputation: 81
On your browser:
In Postman 8+:
PHPSESSID=f20nbdor26v9r1k5hdfj6tji0p; Path=/;
Upvotes: 5
Reputation: 2948
Hit inspect on the site you are working on, when logged in
Upvotes: 8
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
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