Postman Sandbox API reference

Note: The functionality described here is exclusive to Postman's native apps for Mac, Windows, and Linux.

Global functions (pm.*)


require(moduleName:String):function → *

The require function allows you to use the sandbox built-in library modules. The list of available libraries are listed below. The list links to their corresponding documentation.

A number of NodeJS modules are also available to use in the sandbox:

In order to use a library, simply call the require function and pass the module name as a parameter and assign the return of the function to a variable.

var atob = require('atob'),
    _ = require('lodash'),
arrayOfStrings = ['string1', 'string2'];
base64Strings =, atob);



The pm object encloses all information pertaining to the script being executed and allows one to access a copy of the request being sent or the response received. It also allows one to get and set environment and global variables.

The object contains information pertaining to the script being executed. Useful information such as the request name, request Id, and iteration count are stored inside of this object.


    Contains information whether the script being executed is a "prerequest" or a "test" script.


    Is the value of the current iteration being run.


    Is the total number of iterations that are scheduled to run.


    The saved name of the individual request being run.


    The unique guid that identifies the request being run.



The pm.sendRequest function allows sending HTTP/HTTPS requests asynchronously. Simply put, with asynchronous scripts, you can execute logic in the background if you have a heavy computational task or are sending multiple requests. Instead of waiting for a call to complete and blocking any next requests, you can designate a callback function and be notified when an underlying operation has finished.

Some things to know about pm.sendRequest():

  • The method accepts a collection SDK compliant request and a callback. The callback receives two arguments, an error (if any) and an SDK-compliant response. Refer to Collection SDK Documentation to view more information.
  • It can be used in the pre-request or the test script.
// example with a plain string URL
pm.sendRequest('', function (err, res) {
    if (err) {
    } else {
        pm.environment.set("variable_key", "new_value");

// Example with a full fledged SDK Request
const echoPostRequest = {
  url: '',
  method: 'POST',
  header: 'headername1:value1',
  body: {
    mode: 'raw',
    raw: JSON.stringify({ key: 'this is json' })
pm.sendRequest(echoPostRequest, function (err, res) {
  console.log(err ? err : res.json());

// example containing a test ** under the Tests tab only
pm.sendRequest('', function (err, res) {
  if (err) { console.log(err); }
  pm.test('response should be okay to process', function () {
    pm.expect(res)'code', 200);
    pm.expect(res)'status', 'OK');

Extended Reference:


pm.variables: Read more about VariableScope

In Postman, all variables conform to a specific hierarchy. All variables defined in the current iteration take precedence over the variables defined in the current environment, which overrides ones defined in the global scope, i.e. Iteration Data < Environment < Global.

  • pm.variables.has(variableName:String):function → Boolean
  • pm.variables.get(variableName:String):function → *
  • pm.variables.toObject():function → Object

The variables defined in the individual scopes may also be accessed via pm.environment for the environment scope and pm.globals for the global scope.


pm.environment: Read more about VariableScope

  • pm.environment.has(variableName:String):function → Boolean
  • pm.environment.get(variableName:String):function → *
  • pm.environment.set(variableName:String, variableValue:String):function
  • pm.environment.unset(variableName:String):function
  • pm.environment.clear():function
  • pm.environment.toObject():function → Object


pm.globals: Read more about VariableScope

  • pm.globals.has(variableName:String):function → Boolean
  • pm.globals.get(variableName:String):function → *
  • pm.globals.set(variableName:String, variableValue:String):function
  • pm.globals.unset(variableName:String):function
  • pm.globals.clear():function
  • pm.globals.toObject():function → Object


pm.request: Read more about VariableScope

The request object inside pm is a representation of the request for which this script is being run. For a pre-request script, this is the request that is about to be sent and when in a test script, this is the representation of the request that was sent.

request contains information stored in the following structure:

  • pm.request.url:Url
  • pm.request.headers:HeaderList
  • pm.request.headers.add(headerName:String):function
  • pm.request.headers.delete(headerName:String):function
  • pm.request.headers.upsert({ key: headerName:String, value: headerValue:String}):function)

The following items are ONLY available in the test scripts.


pm.response: Read more about Response

Inside the test scripts, the pm.response object contains all information pertaining to the response that was received.

The response details are stored in the following format:

  • pm.response.code:Number
  • pm.response.reason():Function → String
  • pm.response.headers:HeaderList
  • pm.response.responseTime:Number
  • pm.response.text():Function → String
  • pm.response.json():Function → Object


pm.iterationData: Read more about VariableScope

The iterationData object contains data from the data file provided during a collection run.

  • pm.iterationData.get(variableName:String):function → *
  • pm.iterationData.toObject():function → Object


pm.cookies: Read more about CookieList

The cookies object contains a list of cookies that are associated with the domain to which the request was made.

  • pm.cookies.has(cookieName:String):Function → Boolean

    Check whether a particular cookie (addressed by its name) exists for the requested domain.

  • pm.cookies.get(cookieName:String):Function → String

    Get the value of a particular cookie.

  • pm.cookies.toObject:Function → Object

    Get a copy of all cookies and their values in the form of an object. The cookies returned are the ones defined for the requested domain and path.


pm.test(testName:String, specFunction:Function):Function

You can use this function to write test specifications inside either the Pre-request Script or Tests sandbox. Writing tests inside this function allows you to name the test accurately and this function also ensures the rest of the script is not blocked even if there are errors inside the function.

In the following sample test, we are checking that everything about a response is valid for us to proceed.

  pm.test("response should be okay to process", function () {;'');'error');

An optional done callback can be added to pm.test, to test asynchronous functions.

  pm.test('async test', function (done) {
    setTimeout(() => {
    }, 1500);
  • pm.test.index():Function → Number

    Get the total number tests from a specific location.


pm.expect(assertion:*):Function → Assertion

pm.expect is a generic assertion function. Underlying this is the ChaiJS expect BDD library. Using this library, it is easy to write tests where the syntax becomes readable.

This function is useful to deal with assertions of data from a response or variables.

  pm.test("response value check", function () {
      var jsonData = pm.response.json();
  pm.test('environment to be production', function () {

Response Assertion API available in the test scripts

  •, optionalValue:String)
  •, optionalValue:*)
  •, ajvOptions:Object)*

The properties inside the object allows you to easily assert a set of pre-defined rules.


    Checks 1XX status code


    Checks 2XX status code


    Checks 3XX status code


    Checks 4XX status code


    Checks 5XX


    Checks 4XX or 5XX


    Status code must be 200


    Status code must be 202


    Status code must be 400


    Status code must be 401


    Status code 403


    Status code of response is checked to be 404


    Checks whether response status code is 429