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.
- Click on the Whitelist Domains button and add a domain name. This will allow the domain’s cookies to be accessed in the scripts.
- 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
- 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.