You can use the pm.cookies methods to access and manipulate cookies for the domain in the request URL. You can also use the pm.cookies.jar() methods to access and manipulate cookies for any specified domain.
You can learn about using cookies and cookie lists in the Postman Collection SDK.
Use the pm.cookies methods in your scripts to access and manipulate cookies for the requested domain.
Checks if there is a cookie with the specified name for the requested domain.
Returns one of the following:
true - The cookie exists for the requested domain.false - The cookie doesn’t exist for the requested domain.Gets the value of the specified cookie for the requested domain.
Returns the value of the cookie.
You can append a string to the value of a cookie using the
+operator before or after the method.
Gets all cookies and their values for the requested domain.
Returns all cookies and their values as an object.
Use the pm.cookies.jar() methods to specify a domain and access and manipulate its cookies. To enable access to the methods from your scripts, you must first add a domain to the allowlist.
Function calls run asynchronously. Use a callback function to ensure functions run in sequence.
Sets a cookie with the specified name and value to a domain.
Example:
pm.cookies.jar().set("example.com", "session-id", "abc123", (error, cookie) => {
if (error) {
console.error(`An error occurred: ${error}`);
} else {
console.log(`Cookie saved: ${cookie}`);
}
});
Sets a cookie using a Cookie object.
Example:
var Cookie = require('postman-collection').Cookie,
myCookie = new Cookie({
name: 'session-id',
value: 'abc123e',
httpOnly: true
});
pm.cookies.jar().set("example.com", myCookie, (error, cookie) => {
if (error) {
console.error(`An error occurred: ${error}`);
} else {
console.log(`Cookie saved: ${cookie}`);
}
});
Gets the value of a cookie at the specified domain, which is available in the callback function.
Returns the value of the cookie.
Gets all cookies for a specified domains, which are available in the callback function.
Returns the name and value of all cookies.
Removes a specified cookie from the domain.
Clears all cookies from the specified domain.
The following example clears all cookies and then sets a cookie for a specified domain, in sequence:
pm.cookies.jar().clear("example.com", (error) => {
pm.cookies.jar().set("example.com", "session-id", "jkl456p", (error, cookie) => {
if (error) {
console.error(`An error occurred: ${error}`);
} else {
console.log(`Cookie saved: ${cookie}`);
}
})
});
Last modified: 2025/11/04