For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Postman
PricingEnterprise
Contact SalesSign InSign Up for Free
HomeDocs
HomeDocs
      • Overview
        • Overview
        • Write pre-request scripts
        • Write tests
        • Script examples
        • Dynamic variables
          • Overview
          • pm variables methods
          • pm.vault
          • pm.cookies
          • pm.request
          • pm.response
          • pm.sendrequest
          • pm.visualizer
          • pm.test and pm.expect
          • pm.require
          • pm.execution
          • pm.message
          • pm.info
          • pm.mock
          • pm.datasets
          • pm.state
        • Troubleshoot test errors
Postman API Platform

Product

  • Postman Overview
  • Enterprise
  • Spec Hub
  • Flows
  • Agent Mode
  • API Catalog
  • Fern
  • Postman CLI
  • Integrations
  • Workspaces
  • Plans and pricing

API Network

  • App Security
  • Artificial Intelligence
  • Communication
  • Data Analytics
  • Database
  • Developer Productivity
  • DevOps
  • Ecommerce
  • eSignature
  • Financial Services
  • Payments
  • Travel

Resources

  • Postman Docs
  • Academy
  • Community
  • Templates
  • Intergalactic
  • Videos
  • MCP Servers

Legal and Security

  • Legal Terms Hub
  • Terms of Service
  • Postman Product Terms
  • Security
  • Website Terms of Use

Company

  • About
  • Careers and culture
  • Contact us
  • Partner program
  • Customer stories
  • Student programs
  • Press and media
Twitter iconLinkedIn iconGithub iconYouTube iconInstagram iconDiscord icon
Download Postman
Privacy Policy

© 2026 Postman, Inc.

On this page
  • pm.cookies methods
  • pm.cookies.jar methods
Tests and scriptsWrite scriptsPostman sandbox reference

Access cookies in Postman scripts

||View as Markdown|
Was this page helpful?
Previous

Reference vault secrets in Postman scripts

Next

Reference Postman requests in scripts

Built with

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.

pm.cookies methods

Use the pm.cookies methods in your scripts to access and manipulate cookies for the requested domain.

pm.cookies.has(cookieName:String)

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.

pm.cookies.get(cookieName:String)

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.

pm.cookies.toObject()

Gets all cookies and their values for the requested domain.

Returns all cookies and their values as an object.

pm.cookies.jar methods

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.

pm.cookies.jar().set(URL:String, cookieName:String, cookieValue:String, callback(error, cookie))

Sets a cookie with the specified name and value to a domain.

Example:

1pm.cookies.jar().set("example.com", "session-id", "abc123", (error, cookie) => {
2 if (error) {
3 console.error(`An error occurred: ${error}`);
4 } else {
5 console.log(`Cookie saved: ${cookie}`);
6 }
7});

pm.cookies.jar().set(URL:String, { name:String, value:String, httpOnly:Bool }, callback(error, cookie))

Sets a cookie using a Cookie object.

Example:

1var Cookie = require('postman-collection').Cookie,
2 myCookie = new Cookie({
3 name: 'session-id',
4 value: 'abc123e',
5 httpOnly: true
6 });
7
8pm.cookies.jar().set("example.com", myCookie, (error, cookie) => {
9 if (error) {
10 console.error(`An error occurred: ${error}`);
11 } else {
12 console.log(`Cookie saved: ${cookie}`);
13 }
14});

pm.cookies.jar().get(URL:String, cookieName:String, callback(error, value))

Gets the value of a cookie at the specified domain, which is available in the callback function.

Returns the value of the cookie.

pm.cookies.jar().getAll(URL:String, callback(error, cookies))

Gets all cookies for a specified domains, which are available in the callback function.

Returns the name and value of all cookies.

pm.cookies.jar().unset(URL:String, cookieName:String, callback(error))

Removes a specified cookie from the domain.

pm.cookies.jar().clear(URL:String, callback(error))

Clears all cookies from the specified domain.

The following example clears all cookies and then sets a cookie for a specified domain, in sequence:

1pm.cookies.jar().clear("example.com", (error) => {
2 pm.cookies.jar().set("example.com", "session-id", "jkl456p", (error, cookie) => {
3 if (error) {
4 console.error(`An error occurred: ${error}`);
5 } else {
6 console.log(`Cookie saved: ${cookie}`);
7 }
8 })
9});