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?
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.
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.
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:
Tests
tab of the request that will return cookies you want to save, writepm.globals.set('<your key>', pm.cookies.get('<cookie name>'));
cookie
and corresponding value as <your cookie name>={{<global variable name>}};
.I found documentation for this at the Postman sandbox API reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With