Using pm Object and JavaScript in Scripts
What Is the pm Object?
The pm object is Postman's built-in JavaScript API, available in both pre-request scripts and tests. It gives scripts access to the current request, response, variables, and environment.
Common pm Methods
| Method | Purpose |
|---|---|
| pm.environment.set() | Set an environment variable |
| pm.environment.get() | Read an environment variable |
| pm.request | Access or modify the outgoing request |
| pm.response | Access the response data |
| pm.test() | Define a named test assertion |
Writing Basic JavaScript
Since scripts run in a standard JavaScript sandbox, ordinary JavaScript - loops, conditionals, functions - works alongside the pm object, giving full control over request setup and response handling.
Ready to master Postman API Testing Course?
Join Uncodemy's hands-on training and build real-world API testing skills with expert mentors.