Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store and reuse cookies in Postman?

I'm using Postman to test and play with an API.

For the login url, the API requires sending a POST request with username and password as fields. I do this, and I get a 200 response with the message that I am logged in.

I then try another request to get user data. However, I get a response that I am not logged in.

I realized this problem is most likely because the cookie that is sent to me when I log in is not included in the next Postman request.

So my question is, how do I save and include cookies for future requests?

like image 770
CodyBugstein Avatar asked Dec 01 '14 10:12

CodyBugstein


People also ask

How do you store cookies in The Postman?

In postman, we can update the cookies. Click on 'Cookies' to change an existing cookie and pick the domain from the domain list in the MANAGE COOKIES section, then click the cookie you want to update. We can change any property, and click Save to update.

How do you clean Postman cookies?

navigate to View: Show DevTools. navigate to the Application tab, then the Clear Storage view in the left menu. deselect all choices except Cache Storage, then click on 'Clear site data' restart Postman.


1 Answers

I tried using Ashutosh's answer but got an error. I'm guessing this is because Postman's scripting API changed?

At any rate, the following worked for me:

  1. In the Tests tab of the request that will return cookies you want to save, write
pm.globals.set('<your key>', pm.cookies.get('<cookie name>'));
  1. Then, as described in Ashutosh's answer, add the cookie to the headers by setting the key as cookie and corresponding value as <your cookie name>={{<global variable name>}};.

I found documentation for this at the Postman sandbox API reference.

like image 190
darksinge Avatar answered Sep 25 '22 11:09

darksinge