How to use cookies in scripts

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.

  1. Select a request > Cookies.
  2. Select the Whitelist Domains button and add a domain name. This will allow the domain’s cookies to be accessed in the scripts.
  3. Create a Cookie jar in your script.
const cookieJar = pm.cookies.jar();
cookieJar.getAll(URL, callback(error, cookies)); // *Optional* This line will retrieve all stored cookies

Note:

  • You can use the cookie jar to Get, Delete, Create, or Update cookies.
  • To learn more, you will find further operations you can perform on the cookie jar in the Learning Center.


Have more questions? Submit a request