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
  • Use scripts to access cookies
  • Use scripts with requests and responses
  • Use scripts with collections
  • Script variables
  • Use scripts to define mock responses
  • Use scripts with datasets
  • Use scripts to manage persistent state
  • Use scripts to visualize data
  • Manage Postman Vault with scripts
  • Test assertions with scripts
  • Import packages into your scripts
Tests and scriptsWrite scriptsPostman sandbox reference

Postman Sandbox API reference

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

Use dynamic variables to return randomly generated data

Next

Reference variables in Postman scripts

Built with

Postman provides JavaScript APIs with the pm object, enabling you to test and access request and response data in your test scripts run in the Postman Sandbox. You can use the pm object to access request and response details, write assertions, and access and use variables. You can also use the pm object to send HTTP requests and other meta information in the Postman Sandbox.

Use scripts to access cookies

Use the pm.cookies methods in scripts to access and manipulate cookies. To learn more, see Access cookies in Postman scripts.

Use scripts with requests and responses

Reference requests and responses with the pm.request and pm.response objects in scripts. Streaming protocols also return a pm.message object. The pm.info object contains meta info related to the request and script Use the pm.sendRequest method in your scripts to send requests in Postman. To learn more, see Reference Postman requests in scripts, Use scripts to send requests in Postman, Reference request metadata in scripts and Reference message data in scripts.

Use scripts with collections

The pm.execution object provides information and context about requests and their responses during a collection run, such as sending requests or which request is running, its position in a collection, and run-related metadata. To learn more, see Use scripts in collection runs.

Script variables

Access and manipulate different variable types and scopes in your scripts. To learn more, see Reference variables in Postman scripts.

Use scripts to define mock responses

The pm.mock object provides structured functions for matching requests and sending responses. You can use it to serve responses from your saved Postman examples instead of hard-coding them in your mock server implementation file. To learn more, see Reference requests and examples in local mock servers.

Use scripts with datasets

The pm.datasets function enables you to access and query dataset data in scripts. You can use it to run SQL queries or predefined views to retrieve data when your script runs. This enables your tests and mock server logic to use dynamic, data-driven values instead of hard-coded data. To learn more, see Manage and use datasets in scripts.

Use scripts to manage persistent state

The pm.state object provides a persistent store for managing data across script executions. You can use it to read, write, and update data. This enables stateful behavior instead of relying on static responses in your mock server implementation file. To learn more, see Persist state across requests in local mock servers.

Use scripts to visualize data

The pm.visualizer object enables you to visually represent your API’s request responses with the Postman Visualizer. To learn more, see Script Postman visualizations.

Manage Postman Vault with scripts

Access and manipulate vault secrets in your scripts with the pm.vault methods. To learn more, see Reference vault secrets in Postman scripts.

Test assertions with scripts

Use the pm.test and pm.expect methods in your scripts to add test specifications and assertions. To learn more, see Writing tests and assertions in scripts.

Import packages into your scripts

The pm.require method enables you to import packages from your team’s Package Library or external package registries inside scripts in HTTP, gRPC, and GraphQL requests. To learn more, see Import packages into your scripts.

Postman Community.

Ask questions, share knowledge, and connect with developers

Join the Community