I'm trying to write some postman tests that require me to set a cookie. My first request returns a token in a json payload. I've pulled this out and stored it in a variable but I cant seem to inject this into a cookie for further requests.
I get the value for the cookie like:
var json = pm.response.json();
pm.globals.set("my-cookie", json.Token);
I've tried this in the cookie dialog box:
my-cookie={{my-cookie}}; path=/; domain=.myhost.com; Expires=Tue, 19 Jan 2038 03:14:07 GMT;
However when it sends the cookie it sends the above without replacing the variable the, i.e. it has {{my-cookie}} rather than the value of the variable.
I cant see anything in the postman API that will enable me to set cookies on a request grammatically.
I did see this, but it only mentions adding them via the dialog
https://www.getpostman.com/docs/v6/postman/sending_api_requests/interceptor_extension
I also found this, but could find no mention of how to use it.
https://www.postmanlabs.com/postman-collection/Cookie.html
I'm assuming this is a common requirement and must be missing something obvious. Does anyone know how to do this?
Postman stores cookies inside a Cookie Manager and the stored cookies can be accessed when writing scripts in Postman. The access to cookies inside scripts is exposed thanks to a cookie jar, and you can use that cookie jar to work with cookies inside your scripts. Select a request > Cookies.
Try using the Headers feature with a key of Cookie
and a value of cookieName={{yourVariable}}
In case anyone stumbles upon this question, in current version there is a special section for setting request cookies on the righthand side of the request window.
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