Using the Interceptor to read and write cookies
With the new version of Postman (1.0.2), and the Postman Interceptor (0.2.7), it is now possible to read and write cookies!
With the interceptor on, you can retrieve cookies set on a particular domain (Jetpacks only), and include cookies while sending requests.
Retrieving cookies:
1. Make sure the interceptor is enabled in Postman – Check that the traffic light icon in the top-right corner is green.
2. In the tests section (Jetpacks must be enabled for this), you can use the “responseCookies” object. This will return an array of cookie objects. To retrieve a particular name, use “postman.getResponseCookie(cookieName)”. This will return a single cookie object. Each cookie object will contain the following properties:
domain, hostOnly, httpOnly, name, path, secure, session, storeId, value
Setting Cookies
1. Make sure the interceptor is enabled.
2. Include the “Cookie” header in the headers section
eg. Cookie: name=value; name2=value2
3. Send the request. The cookies you set will be sent by Chrome along with your request.
I really like and appreciate your blog post. Cool.
I have a post which has a response of cookies and a json object. I am able to extract the “id” from the response body, but I can’t get cookie values. I purchase Jetpacks and have interceptor enabled. Here is what is in my test editor:
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable(“id”, data.entity.id);
postman.setEnvironmentVariable(“test”,responseCookies);
The quick look shows the value of the id correct. In the response I also see 4 cookie values.
But the value of test = [object,Object],[object,Object],[object,Object],[object,Object]
Can anyone help?
I am also having a similar issue
I resolved with the following:
var myslCheck = postman.getResponseCookie(“slCheck”);
postman.setGlobalVariable(“slCheck”,myslCheck.value);
Use postman.getResponseCookie(“slCheck”).value
In ubuntu, postman not detects interceptor have installed… any tip?
Is there a way to set cookie attributes other than the name and value (e.g. path, domain, etc.)?
Aw, this was a really nice post. Finding the time and actual effort to make a good article… but
what can I say… I put things off a lot and don’t seem to get nearly anything done.
Abhijit, this is an Informative Article to write Cookies. Surely i will implement it on my site